Improvements to metadata
This commit is contained in:
parent
466ac8ec26
commit
ff9a014afc
16
meta.go
16
meta.go
@ -36,6 +36,7 @@ import (
|
||||
type versionMetadata struct {
|
||||
Deleted []string `json:"deleted"`
|
||||
path string
|
||||
dirty bool
|
||||
}
|
||||
|
||||
func newVersionMetadata(path string) (*versionMetadata, error) {
|
||||
@ -57,7 +58,18 @@ func (this *versionMetadata) filter(nodes versionedNodeMap) {
|
||||
}
|
||||
}
|
||||
|
||||
func (this *versionMetadata) destroyPath(path string) {
|
||||
this.Deleted = append(this.Deleted, path)
|
||||
this.dirty = true
|
||||
}
|
||||
|
||||
func (this *versionMetadata) createPath(path string) {
|
||||
this.dirty = true
|
||||
}
|
||||
|
||||
func (this *versionMetadata) load() error {
|
||||
this.dirty = false
|
||||
|
||||
if _, err := os.Stat(this.path); os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
@ -75,6 +87,10 @@ func (this *versionMetadata) load() error {
|
||||
}
|
||||
|
||||
func (this *versionMetadata) save() error {
|
||||
if !this.dirty {
|
||||
return nil
|
||||
}
|
||||
|
||||
js, err := json.Marshal(this)
|
||||
if err != nil {
|
||||
return err
|
||||
|
2
node.go
2
node.go
@ -102,7 +102,7 @@ func (this *versionedNode) remove() error {
|
||||
ver = ver.parent
|
||||
}
|
||||
|
||||
ver.removePath(this.path)
|
||||
ver.meta.destroyPath(this.path)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -145,10 +145,6 @@ func (this *version) rebasePath(paths ...string) string {
|
||||
return filepath.Join(combined...)
|
||||
}
|
||||
|
||||
func (this *version) removePath(path string) {
|
||||
this.meta.Deleted = append(this.meta.Deleted, path)
|
||||
}
|
||||
|
||||
func (this *version) finalize() error {
|
||||
return this.meta.save()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user