Work in progress

This commit is contained in:
Alex Yatskov 2015-05-14 14:24:52 +09:00
parent a96c0295b9
commit 920dc8c841
3 changed files with 24 additions and 14 deletions

12
dir.go
View File

@ -29,12 +29,20 @@ import (
) )
type versionedDir struct { type versionedDir struct {
dirs map[string]versionedDir dirs map[string]*versionedDir
files map[string]versionedFile files map[string]*versionedFile
node versionedNode node versionedNode
inode uint64 inode uint64
} }
func newVersionedDir(node versionedNode, inode uint64) *versionedDir {
return &versionedDir{
dirs: make(map[string]*versionedDir),
files: make(map[string]*versionedFile),
node: node,
inode: inode}
}
func (this versionedDir) Attr(attr *fuse.Attr) { func (this versionedDir) Attr(attr *fuse.Attr) {
attr.Mode = this.node.info.Mode() attr.Mode = this.node.info.Mode()
attr.Inode = this.inode attr.Inode = this.inode

View File

@ -32,6 +32,10 @@ type versionedFile struct {
inode uint64 inode uint64
} }
func newVersionedFile(node versionedNode, inode uint64) *versionedFile {
return &versionedFile{node: node, inode: inode}
}
func (this versionedFile) Attr(attr *fuse.Attr) { func (this versionedFile) Attr(attr *fuse.Attr) {
attr.Mode = this.node.info.Mode() attr.Mode = this.node.info.Mode()
attr.Inode = this.inode attr.Inode = this.inode

View File

@ -48,7 +48,7 @@ type version struct {
parent *version parent *version
timestamp time.Time timestamp time.Time
meta versionMetadata meta versionMetadata
root versionedDir root *versionedDir
inodeCnt uint64 inodeCnt uint64
} }
@ -107,9 +107,8 @@ func (this *version) scanDir(path string) (map[string]versionedNode, error) {
for _, node := range nodes { for _, node := range nodes {
name := node.Name() name := node.Name()
ownNodes[name] = versionedNode{ subPath := filepath.Join(fullPath, name)
info: node, ownNodes[name] = versionedNode{subPath, node}
path: filepath.Join(fullPath, name)}
} }
} }
@ -132,16 +131,15 @@ func (this *version) buildDir(path string, dir *versionedDir) error {
for name, node := range nodes { for name, node := range nodes {
if node.info.IsDir() { if node.info.IsDir() {
subDir := versionedDir{node: node, inode: this.allocInode()} subDir := newVersionedDir(node, this.allocInode())
subDirPath := filepath.Join(path, name) subDirPath := filepath.Join(path, name)
if err := this.buildDir(subDirPath, &subDir); err != nil { if err := this.buildDir(subDirPath, subDir); err != nil {
return err return err
} }
dir.dirs[name] = subDir dir.dirs[name] = subDir
} else { } else {
dir.files[name] = versionedFile{node: node, inode: this.allocInode()} dir.files[name] = newVersionedFile(node, this.allocInode())
} }
} }
@ -154,11 +152,11 @@ func (this *version) scanFs() error {
return err return err
} }
this.root = versionedDir{ this.root = newVersionedDir(
node: versionedNode{path: this.rootPath(), info: node}, versionedNode{path: this.rootPath(), info: node},
inode: this.allocInode()} this.allocInode())
return this.buildDir(this.rootPath(), &this.root) return this.buildDir(this.rootPath(), this.root)
} }
func (this *version) loadMetadata() error { func (this *version) loadMetadata() error {