Work in progress

This commit is contained in:
Alex Yatskov 2015-05-28 14:36:34 +09:00
parent dcec6402c4
commit 57fa972b78
3 changed files with 19 additions and 14 deletions

4
dir.go
View File

@ -54,7 +54,7 @@ func (this *versionedDir) createDir(name string) (*versionedDir, error) {
return nil, err return nil, err
} }
node, err := newVersionedNode(childPath, this.node.ver) node, err := newVersionedNode(childPath, this.node.parent, this.node.ver)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -73,7 +73,7 @@ func (this *versionedDir) createFile(name string, flags int) (*versionedFile, er
return nil, err return nil, err
} }
node, err := newVersionedNode(childPath, this.node.ver) node, err := newVersionedNode(childPath, this.node.parent, this.node.ver)
if err != nil { if err != nil {
return nil, err return nil, err
} }

15
node.go
View File

@ -33,25 +33,30 @@ import (
type versionedNode struct { type versionedNode struct {
path string path string
info os.FileInfo info os.FileInfo
ver *version parent *versionedNode
shadow *versionedNode shadow *versionedNode
ver *version
} }
type versionedNodeMap map[string]*versionedNode type versionedNodeMap map[string]*versionedNode
func newVersionedNode(path string, ver *version) (*versionedNode, error) { func newVersionedNode(path string, parent *versionedNode, ver *version) (*versionedNode, error) {
info, err := os.Stat(ver.rebasePath(path)) info, err := os.Stat(ver.rebasePath(path))
if err != nil { if err != nil {
return nil, err return nil, err
} }
return newVersionedNodeStat(path, ver, info), nil return newVersionedNodeStat(path, parent, ver, info), nil
} }
func newVersionedNodeStat(path string, ver *version, info os.FileInfo) *versionedNode { func newVersionedNodeStat(path string, parent *versionedNode, ver *version, info os.FileInfo) *versionedNode {
return &versionedNode{path, info, ver, nil} return &versionedNode{path, info, parent, nil, ver}
} }
// func (this *versionedNode) version() (*versionedNode, error) {
// return nil, 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 {

View File

@ -62,12 +62,12 @@ func newVersion(base string, timestamp time.Time, allocator InodeAllocator, pare
return ver, nil return ver, nil
} }
func (this *version) scanDir(path string) (versionedNodeMap, error) { func (this *version) scanNode(node *versionedNode) (versionedNodeMap, error) {
var baseNodes versionedNodeMap var baseNodes versionedNodeMap
if this.parent != nil { if this.parent != nil {
var err error var err error
baseNodes, err = this.parent.scanDir(path) baseNodes, err = this.parent.scanNode(node)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -77,7 +77,7 @@ func (this *version) scanDir(path string) (versionedNodeMap, error) {
ownNodes := make(versionedNodeMap) ownNodes := make(versionedNodeMap)
{ {
infos, err := ioutil.ReadDir(this.rebasePath(path)) infos, err := ioutil.ReadDir(this.rebasePath(node.path))
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
if err != nil { if err != nil {
return nil, err return nil, err
@ -85,8 +85,8 @@ func (this *version) scanDir(path string) (versionedNodeMap, error) {
for _, info := range infos { for _, info := range infos {
childName := info.Name() childName := info.Name()
childPath := filepath.Join(path, childName) childPath := filepath.Join(node.path, childName)
ownNodes[childName] = newVersionedNodeStat(childPath, this, info) ownNodes[childName] = newVersionedNodeStat(childPath, node, this, info)
} }
} }
@ -106,7 +106,7 @@ func (this *version) scanDir(path string) (versionedNodeMap, error) {
} }
func (this *version) buildVerDir(dir *versionedDir) error { func (this *version) buildVerDir(dir *versionedDir) error {
nodes, err := this.scanDir(dir.node.path) nodes, err := this.scanNode(dir.node)
if err != nil { if err != nil {
return err return err
} }
@ -128,7 +128,7 @@ func (this *version) buildVerDir(dir *versionedDir) error {
} }
func (this *version) resolve() error { func (this *version) resolve() error {
node, err := newVersionedNode("/", this) node, err := newVersionedNode("/", nil, this)
if err != nil { if err != nil {
return err return err
} }