Skip to content

Commit

Permalink
Object clone (#6)
Browse files Browse the repository at this point in the history
DanielSollis authored Oct 27, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent dd97110 commit 47b233d
Showing 2 changed files with 17 additions and 17 deletions.
11 changes: 11 additions & 0 deletions object/object.go
Original file line number Diff line number Diff line change
@@ -31,3 +31,14 @@ func (v *Version) IsLater(other *Version) bool {
// Either v.Version < other.Version or other.Pid > v.Pid
return false
}

//Copies the child's attributes before updating to the parent.
func (v *Version) Clone() *Version {
parent := &Version{
Pid: v.Pid,
Version: v.Version,
Region: v.Region,
Tombstone: v.Tombstone,
}
return parent
}
23 changes: 6 additions & 17 deletions versions.go
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ func (v VersionManager) Update(meta *pb.Object) error {

// Update the parent to the current version of the object.
if meta.Version != nil && !meta.Version.IsZero() {
meta.Version.Parent = create_version_parent(meta)
meta.Version.Parent = meta.Version.Clone()
} else {
// This is the first version of the object. Also set provenance on the object.
meta.Version = &pb.Version{}
@@ -64,7 +64,7 @@ func (v VersionManager) Update(meta *pb.Object) error {

// Update the version to the new version of the local version manager,
// Undelete the version if it was a Tombstone before
update_version(meta, v, false)
v.updateVersion(meta, false)
return nil
}

@@ -83,26 +83,15 @@ func (v VersionManager) Delete(meta *pb.Object) error {
if meta.Version.Tombstone {
return errors.New("cannot delete an already deleted object")
}
meta.Version.Parent = create_version_parent(meta)
meta.Version.Parent = meta.Version.Clone()

//Update Pid, Version, Region and Tombstone for the version.
update_version(meta, v, true)
v.updateVersion(meta, true)
return nil
}

//Copies the child's attributes before updating to the parent.
func create_version_parent(meta *pb.Object) *pb.Version {
parent := &pb.Version{
Pid: meta.Version.Pid,
Version: meta.Version.Version,
Region: meta.Version.Region,
Tombstone: meta.Version.Tombstone,
}
return parent
}

//Assigns the attributes of the passed vertionManager to the object.
func update_version(meta *pb.Object, v VersionManager, delete_version bool) {
//Assigns the attributes of the passed versionManager to the object.
func (v VersionManager) updateVersion(meta *pb.Object, delete_version bool) {
meta.Version.Pid = v.PID
meta.Version.Version++
meta.Version.Region = v.Region

0 comments on commit 47b233d

Please sign in to comment.