From ff9a014afc1c53f3cae0093a642c8f7c99271c12 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 17 Jun 2015 16:50:07 +0900 Subject: [PATCH] Improvements to metadata --- meta.go | 16 ++++++++++++++++ node.go | 2 +- version.go | 4 ---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/meta.go b/meta.go index 76a0fcb..24fbf42 100644 --- a/meta.go +++ b/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 diff --git a/node.go b/node.go index e77a15d..e2806fa 100644 --- a/node.go +++ b/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 } diff --git a/version.go b/version.go index b034e8a..35eb769 100644 --- a/version.go +++ b/version.go @@ -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() }