From facabaf563129b81ebbc1964af238a9b55531e63 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 16 Jun 2015 18:22:29 +0900 Subject: [PATCH] Cleanup --- node.go | 38 +++++++++++++++++++++----------------- version.go | 22 +++++----------------- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/node.go b/node.go index 4c9eb3b..9dc38c7 100644 --- a/node.go +++ b/node.go @@ -41,8 +41,6 @@ type versionedNode struct { versioned bool } -type versionedNodeMap map[string]*versionedNode - func newVersionedNode(path string, ver *version, parent *versionedNode) (*versionedNode, error) { info, err := os.Stat(ver.rebasePath(path)) if err != nil { @@ -56,21 +54,6 @@ func newVersionedNodeStat(path string, ver *version, parent *versionedNode, info return &versionedNode{path, info, ver, parent, false} } -func (this *versionedNode) remove() error { - ver := this.ver - - if this.versioned { - if err := os.Remove(this.rebasedPath()); err != nil { - return err - } - - ver = ver.parent - } - - ver.removePath(this.path) - return nil -} - func (this *versionedNode) setAttr(req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error { if req.Valid&fuse.SetattrMode != 0 { if err := os.Chmod(this.rebasedPath(), req.Mode); err != nil { @@ -124,6 +107,21 @@ func (this *versionedNode) sync() error { return nil } +func (this *versionedNode) remove() error { + ver := this.ver + + if this.versioned { + if err := os.Remove(this.rebasedPath()); err != nil { + return err + } + + ver = ver.parent + } + + ver.removePath(this.path) + return nil +} + func (this *versionedNode) rebasedPath() string { return this.ver.rebasePath(this.path) } @@ -156,3 +154,9 @@ func (this *versionedNode) attr(attr *fuse.Attr) { attr.Gid, attr.Uid = this.owner() attr.Rdev = uint32(stat.Rdev) } + +// +// versionedNodeMap +// + +type versionedNodeMap map[string]*versionedNode diff --git a/version.go b/version.go index 1c3d527..df4b6ef 100644 --- a/version.go +++ b/version.go @@ -32,7 +32,6 @@ import ( "path/filepath" "regexp" "strconv" - "strings" "time" ) @@ -151,27 +150,12 @@ func (this *version) finalize() error { return this.meta.save() } -func (this *version) dump(root *versionedDir, depth int) { - indent := strings.Repeat("\t", depth) - for name, dir := range root.dirs { - fmt.Printf("%s+ %s [%s@%x]\n", indent, name, dir.node.path, this.timestamp.Unix()) - this.dump(dir, depth+1) - } - for name, file := range root.files { - fmt.Printf("%s- %s [%s@%x]\n", indent, name, file.node.path, this.timestamp.Unix()) - } -} - -func (this *version) dumpRoot() { - this.dump(this.root, 0) -} - func (this *version) Root() (fs.Node, error) { return this.root, nil } // -// version helpers +// versionList // type versionList []*version @@ -188,6 +172,10 @@ func (this versionList) Less(i, j int) bool { return this[i].timestamp.Unix() < this[j].timestamp.Unix() } +// +// version helpers +// + func buildNewVersion(base string) error { name := buildVerName(time.Now())