Adding ".." and "." directory handling
This commit is contained in:
parent
eed33efdc8
commit
adb06273ab
28
dir.go
28
dir.go
@ -30,18 +30,20 @@ import (
|
||||
)
|
||||
|
||||
type versionedDir struct {
|
||||
dirs map[string]*versionedDir
|
||||
files map[string]*versionedFile
|
||||
node *versionedNode
|
||||
inode uint64
|
||||
dirs map[string]*versionedDir
|
||||
files map[string]*versionedFile
|
||||
node *versionedNode
|
||||
inode uint64
|
||||
parent *versionedDir
|
||||
}
|
||||
|
||||
func newVersionedDir(node *versionedNode, inode uint64) *versionedDir {
|
||||
func newVersionedDir(node *versionedNode, inode uint64, parent *versionedDir) *versionedDir {
|
||||
return &versionedDir{
|
||||
dirs: make(map[string]*versionedDir),
|
||||
files: make(map[string]*versionedFile),
|
||||
node: node,
|
||||
inode: inode}
|
||||
dirs: make(map[string]*versionedDir),
|
||||
files: make(map[string]*versionedFile),
|
||||
node: node,
|
||||
inode: inode,
|
||||
parent: parent}
|
||||
}
|
||||
|
||||
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) {
|
||||
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 {
|
||||
entry := fuse.Dirent{Inode: dir.inode, Name: name, Type: fuse.DT_File}
|
||||
entries = append(entries, entry)
|
||||
}
|
||||
|
||||
for name, file := range this.files {
|
||||
entry := fuse.Dirent{Inode: file.inode, Name: name, Type: fuse.DT_Dir}
|
||||
entries = append(entries, entry)
|
||||
|
12
file.go
12
file.go
@ -30,12 +30,16 @@ import (
|
||||
)
|
||||
|
||||
type versionedFile struct {
|
||||
node *versionedNode
|
||||
inode uint64
|
||||
node *versionedNode
|
||||
inode uint64
|
||||
parent *versionedDir
|
||||
}
|
||||
|
||||
func newVersionedFile(node *versionedNode, inode uint64) *versionedFile {
|
||||
return &versionedFile{node: node, inode: inode}
|
||||
func newVersionedFile(node *versionedNode, inode uint64, parent *versionedDir) *versionedFile {
|
||||
return &versionedFile{
|
||||
node: node,
|
||||
inode: inode,
|
||||
parent: parent}
|
||||
}
|
||||
|
||||
func (this versionedFile) Attr(attr *fuse.Attr) {
|
||||
|
@ -129,14 +129,14 @@ func (this *version) buildVerDir(dir *versionedDir) error {
|
||||
|
||||
for name, node := range nodes {
|
||||
if node.info.IsDir() {
|
||||
subDir := newVersionedDir(node, this.inodeAloc.AllocInode())
|
||||
subDir := newVersionedDir(node, this.inodeAloc.AllocInode(), dir)
|
||||
if err := this.buildVerDir(subDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dir.dirs[name] = subDir
|
||||
} 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.newVersionedNode("/", node),
|
||||
this.inodeAloc.AllocInode())
|
||||
this.inodeAloc.AllocInode(),
|
||||
nil)
|
||||
|
||||
return this.buildVerDir(this.root)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user