This commit is contained in:
Alex Yatskov 2015-06-16 18:22:29 +09:00
parent 2278f5710b
commit facabaf563
2 changed files with 26 additions and 34 deletions

38
node.go
View File

@ -41,8 +41,6 @@ type versionedNode struct {
versioned bool versioned bool
} }
type versionedNodeMap map[string]*versionedNode
func newVersionedNode(path string, ver *version, parent *versionedNode) (*versionedNode, error) { func newVersionedNode(path string, ver *version, parent *versionedNode) (*versionedNode, error) {
info, err := os.Stat(ver.rebasePath(path)) info, err := os.Stat(ver.rebasePath(path))
if err != nil { if err != nil {
@ -56,21 +54,6 @@ func newVersionedNodeStat(path string, ver *version, parent *versionedNode, info
return &versionedNode{path, info, ver, parent, false} 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 { func (this *versionedNode) setAttr(req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error {
if req.Valid&fuse.SetattrMode != 0 { if req.Valid&fuse.SetattrMode != 0 {
if err := os.Chmod(this.rebasedPath(), req.Mode); err != nil { if err := os.Chmod(this.rebasedPath(), req.Mode); err != nil {
@ -124,6 +107,21 @@ func (this *versionedNode) sync() error {
return nil 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 { func (this *versionedNode) rebasedPath() string {
return this.ver.rebasePath(this.path) return this.ver.rebasePath(this.path)
} }
@ -156,3 +154,9 @@ func (this *versionedNode) attr(attr *fuse.Attr) {
attr.Gid, attr.Uid = this.owner() attr.Gid, attr.Uid = this.owner()
attr.Rdev = uint32(stat.Rdev) attr.Rdev = uint32(stat.Rdev)
} }
//
// versionedNodeMap
//
type versionedNodeMap map[string]*versionedNode

View File

@ -32,7 +32,6 @@ import (
"path/filepath" "path/filepath"
"regexp" "regexp"
"strconv" "strconv"
"strings"
"time" "time"
) )
@ -151,27 +150,12 @@ func (this *version) finalize() error {
return this.meta.save() 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) { func (this *version) Root() (fs.Node, error) {
return this.root, nil return this.root, nil
} }
// //
// version helpers // versionList
// //
type versionList []*version type versionList []*version
@ -188,6 +172,10 @@ func (this versionList) Less(i, j int) bool {
return this[i].timestamp.Unix() < this[j].timestamp.Unix() return this[i].timestamp.Unix() < this[j].timestamp.Unix()
} }
//
// version helpers
//
func buildNewVersion(base string) error { func buildNewVersion(base string) error {
name := buildVerName(time.Now()) name := buildVerName(time.Now())