Adding ".." and "." directory handling

This commit is contained in:
Alex Yatskov 2015-05-18 10:23:53 +09:00
parent eed33efdc8
commit adb06273ab
3 changed files with 30 additions and 17 deletions

14
dir.go
View File

@ -34,14 +34,16 @@ type versionedDir struct {
files map[string]*versionedFile files map[string]*versionedFile
node *versionedNode node *versionedNode
inode uint64 inode uint64
parent *versionedDir
} }
func newVersionedDir(node *versionedNode, inode uint64) *versionedDir { func newVersionedDir(node *versionedNode, inode uint64, parent *versionedDir) *versionedDir {
return &versionedDir{ return &versionedDir{
dirs: make(map[string]*versionedDir), dirs: make(map[string]*versionedDir),
files: make(map[string]*versionedFile), files: make(map[string]*versionedFile),
node: node, node: node,
inode: inode} inode: inode,
parent: parent}
} }
func (this versionedDir) Attr(attr *fuse.Attr) { func (this versionedDir) Attr(attr *fuse.Attr) {
@ -54,11 +56,17 @@ func (this versionedDir) Attr(attr *fuse.Attr) {
func (this versionedDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { func (this versionedDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
log.Printf("versionedDir::ReadDirAll: %s", this.node) log.Printf("versionedDir::ReadDirAll: %s", this.node)
var entries []fuse.Dirent entries := []fuse.Dirent{{Inode: this.inode, Name: ".", Type: fuse.DT_Dir}}
if this.parent != nil {
entry := fuse.Dirent{Inode: this.parent.inode, Name: "..", Type: fuse.DT_Dir}
entries = append(entries, entry)
}
for name, dir := range this.dirs { for name, dir := range this.dirs {
entry := fuse.Dirent{Inode: dir.inode, Name: name, Type: fuse.DT_File} entry := fuse.Dirent{Inode: dir.inode, Name: name, Type: fuse.DT_File}
entries = append(entries, entry) entries = append(entries, entry)
} }
for name, file := range this.files { for name, file := range this.files {
entry := fuse.Dirent{Inode: file.inode, Name: name, Type: fuse.DT_Dir} entry := fuse.Dirent{Inode: file.inode, Name: name, Type: fuse.DT_Dir}
entries = append(entries, entry) entries = append(entries, entry)

View File

@ -32,10 +32,14 @@ import (
type versionedFile struct { type versionedFile struct {
node *versionedNode node *versionedNode
inode uint64 inode uint64
parent *versionedDir
} }
func newVersionedFile(node *versionedNode, inode uint64) *versionedFile { func newVersionedFile(node *versionedNode, inode uint64, parent *versionedDir) *versionedFile {
return &versionedFile{node: node, inode: inode} return &versionedFile{
node: node,
inode: inode,
parent: parent}
} }
func (this versionedFile) Attr(attr *fuse.Attr) { func (this versionedFile) Attr(attr *fuse.Attr) {

View File

@ -129,14 +129,14 @@ func (this *version) buildVerDir(dir *versionedDir) error {
for name, node := range nodes { for name, node := range nodes {
if node.info.IsDir() { if node.info.IsDir() {
subDir := newVersionedDir(node, this.inodeAloc.AllocInode()) subDir := newVersionedDir(node, this.inodeAloc.AllocInode(), dir)
if err := this.buildVerDir(subDir); err != nil { if err := this.buildVerDir(subDir); err != nil {
return err return err
} }
dir.dirs[name] = subDir dir.dirs[name] = subDir
} else { } else {
dir.files[name] = newVersionedFile(node, this.inodeAloc.AllocInode()) dir.files[name] = newVersionedFile(node, this.inodeAloc.AllocInode(), dir)
} }
} }
@ -151,7 +151,8 @@ func (this *version) resolve() error {
this.root = newVersionedDir( this.root = newVersionedDir(
this.newVersionedNode("/", node), this.newVersionedNode("/", node),
this.inodeAloc.AllocInode()) this.inodeAloc.AllocInode(),
nil)
return this.buildVerDir(this.root) return this.buildVerDir(this.root)
} }