Improvements to metadata

This commit is contained in:
Alex Yatskov 2015-06-17 16:50:07 +09:00
parent 466ac8ec26
commit ff9a014afc
3 changed files with 17 additions and 5 deletions

16
meta.go
View File

@ -36,6 +36,7 @@ import (
type versionMetadata struct { type versionMetadata struct {
Deleted []string `json:"deleted"` Deleted []string `json:"deleted"`
path string path string
dirty bool
} }
func newVersionMetadata(path string) (*versionMetadata, error) { 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 { func (this *versionMetadata) load() error {
this.dirty = false
if _, err := os.Stat(this.path); os.IsNotExist(err) { if _, err := os.Stat(this.path); os.IsNotExist(err) {
return nil return nil
} }
@ -75,6 +87,10 @@ func (this *versionMetadata) load() error {
} }
func (this *versionMetadata) save() error { func (this *versionMetadata) save() error {
if !this.dirty {
return nil
}
js, err := json.Marshal(this) js, err := json.Marshal(this)
if err != nil { if err != nil {
return err return err

View File

@ -102,7 +102,7 @@ func (this *versionedNode) remove() error {
ver = ver.parent ver = ver.parent
} }
ver.removePath(this.path) ver.meta.destroyPath(this.path)
return nil return nil
} }

View File

@ -145,10 +145,6 @@ func (this *version) rebasePath(paths ...string) string {
return filepath.Join(combined...) return filepath.Join(combined...)
} }
func (this *version) removePath(path string) {
this.meta.Deleted = append(this.meta.Deleted, path)
}
func (this *version) finalize() error { func (this *version) finalize() error {
return this.meta.save() return this.meta.save()
} }