diff --git a/database.go b/database.go index f8f0559..6e8ae06 100644 --- a/database.go +++ b/database.go @@ -103,10 +103,6 @@ func (this *database) buildVersions(base string) ([]*version, error) { prev = ver } - for _, ver := range vers { - ver.last = vers[len(vers)-1] - } - return vers, nil } diff --git a/dir.go b/dir.go index 0bd4e1a..e343806 100644 --- a/dir.go +++ b/dir.go @@ -58,7 +58,7 @@ func (this *versionedDir) createDir(name string) (*versionedDir, error) { return nil, err } - node, err := newVersionedNode(childPath, this.node.ver) + node, err := newVersionedNode(childPath, this.node.ver, nil) if err != nil { return nil, err } @@ -77,7 +77,7 @@ func (this *versionedDir) createFile(name string, flags int) (*versionedFile, er return nil, err } - node, err := newVersionedNode(childPath, this.node.ver) + node, err := newVersionedNode(childPath, this.node.ver, nil) if err != nil { return nil, err } @@ -89,9 +89,10 @@ func (this *versionedDir) createFile(name string, flags int) (*versionedFile, er return file, nil } -func (this *versionedDir) Attr(attr *fuse.Attr) { +func (this *versionedDir) Attr(ctx context.Context, attr *fuse.Attr) error { this.node.attr(attr) attr.Inode = this.inode + return nil } func (this *versionedDir) Getattr(ctx context.Context, req *fuse.GetattrRequest, resp *fuse.GetattrResponse) error { @@ -99,7 +100,7 @@ func (this *versionedDir) Getattr(ctx context.Context, req *fuse.GetattrRequest, return err } - this.Attr(&resp.Attr) + this.Attr(ctx, &resp.Attr) return nil } diff --git a/file.go b/file.go index 82bc3eb..72ea563 100644 --- a/file.go +++ b/file.go @@ -62,9 +62,10 @@ func (this *versionedFile) Open(ctx context.Context, req *fuse.OpenRequest, resp return this, nil } -func (this *versionedFile) Attr(attr *fuse.Attr) { +func (this *versionedFile) Attr(ctx context.Context, attr *fuse.Attr) error { this.node.attr(attr) attr.Inode = this.inode + return nil } func (this *versionedFile) Getattr(ctx context.Context, req *fuse.GetattrRequest, resp *fuse.GetattrResponse) error { @@ -72,7 +73,7 @@ func (this *versionedFile) Getattr(ctx context.Context, req *fuse.GetattrRequest return err } - this.Attr(&resp.Attr) + this.Attr(ctx, &resp.Attr) return nil } diff --git a/node.go b/node.go index 6a9aea9..f4480e2 100644 --- a/node.go +++ b/node.go @@ -34,24 +34,25 @@ import ( // type versionedNode struct { - path string - info os.FileInfo - ver *version + path string + info os.FileInfo + ver *version + parent *versionedNode } type versionedNodeMap map[string]*versionedNode -func newVersionedNode(path string, ver *version) (*versionedNode, error) { +func newVersionedNode(path string, ver *version, parent *versionedNode) (*versionedNode, error) { info, err := os.Stat(ver.rebasePath(path)) if err != nil { return nil, err } - return newVersionedNodeStat(path, ver, info), nil + return newVersionedNodeStat(path, ver, parent, info), nil } -func newVersionedNodeStat(path string, ver *version, info os.FileInfo) *versionedNode { - return &versionedNode{path, info, ver} +func newVersionedNodeStat(path string, ver *version, parent *versionedNode, info os.FileInfo) *versionedNode { + return &versionedNode{path, info, ver, parent} } func (this *versionedNode) setAttr(req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error { @@ -111,14 +112,6 @@ func (this *versionedNode) rebasedPath() string { return this.ver.rebasePath(this.path) } -func (this *versionedNode) rebasedTermPath() string { - if this.ver.last == nil { - return this.rebasedPath() - } - - return this.ver.last.rebasePath(this.path) -} - func (this *versionedNode) owner() (gid, uid uint32) { stat := this.info.Sys().(*syscall.Stat_t) diff --git a/version.go b/version.go index 4360f7f..124a3ad 100644 --- a/version.go +++ b/version.go @@ -42,14 +42,13 @@ import ( type version struct { base string - prev *version - last *version + parent *version timestamp time.Time meta *versionMetadata root *versionedDir } -func newVersion(base string, timestamp time.Time, prev *version) (*version, error) { +func newVersion(base string, timestamp time.Time, parent *version) (*version, error) { meta, err := newVersionMetadata(filepath.Join(base, "meta.json")) if err != nil { return nil, err @@ -57,7 +56,7 @@ func newVersion(base string, timestamp time.Time, prev *version) (*version, erro ver := &version{ base: base, - prev: prev, + parent: parent, timestamp: timestamp, meta: meta} @@ -66,10 +65,10 @@ func newVersion(base string, timestamp time.Time, prev *version) (*version, erro func (this *version) scanNode(node *versionedNode) (versionedNodeMap, error) { var baseNodes versionedNodeMap - if this.prev != nil { + if this.parent != nil { var err error - baseNodes, err = this.prev.scanNode(node) + baseNodes, err = this.parent.scanNode(node) if err != nil { return nil, err } @@ -88,7 +87,7 @@ func (this *version) scanNode(node *versionedNode) (versionedNodeMap, error) { for _, info := range infos { childName := info.Name() childPath := filepath.Join(node.path, childName) - ownNodes[childName] = newVersionedNodeStat(childPath, this, info) + ownNodes[childName] = newVersionedNodeStat(childPath, this, nil, info) } } @@ -100,6 +99,7 @@ func (this *version) scanNode(node *versionedNode) (versionedNodeMap, error) { } for ownName, ownNode := range ownNodes { + ownNode.parent, _ = baseNodes[ownName] baseNodes[ownName] = ownNode } @@ -129,7 +129,7 @@ func (this *version) buildVerDir(dir *versionedDir) error { } func (this *version) resolve() error { - node, err := newVersionedNode("/", this) + node, err := newVersionedNode("/", this, nil) if err != nil { return err }