fuse: Add '.' and '..' entries to all directories

This commit is contained in:
Alexander Neumann 2017-06-18 17:12:05 +02:00
parent f8176a74ec
commit f4e85a53e7

View file

@ -19,15 +19,16 @@ var _ = fs.HandleReadDirAller(&dir{})
var _ = fs.NodeStringLookuper(&dir{}) var _ = fs.NodeStringLookuper(&dir{})
type dir struct { type dir struct {
root *Root root *Root
items map[string]*restic.Node items map[string]*restic.Node
inode uint64 inode uint64
node *restic.Node parentInode uint64
node *restic.Node
blobsize *BlobSizeCache blobsize *BlobSizeCache
} }
func newDir(ctx context.Context, root *Root, inode uint64, node *restic.Node) (*dir, error) { func newDir(ctx context.Context, root *Root, inode, parentInode uint64, node *restic.Node) (*dir, error) {
debug.Log("new dir for %v (%v)", node.Name, node.Subtree.Str()) debug.Log("new dir for %v (%v)", node.Name, node.Subtree.Str())
tree, err := root.repo.LoadTree(ctx, *node.Subtree) tree, err := root.repo.LoadTree(ctx, *node.Subtree)
if err != nil { if err != nil {
@ -40,10 +41,11 @@ func newDir(ctx context.Context, root *Root, inode uint64, node *restic.Node) (*
} }
return &dir{ return &dir{
root: root, root: root,
node: node, node: node,
items: items, items: items,
inode: inode, inode: inode,
parentInode: parentInode,
}, nil }, nil
} }
@ -134,7 +136,19 @@ func (d *dir) calcNumberOfLinks() uint32 {
func (d *dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { func (d *dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
debug.Log("called") debug.Log("called")
ret := make([]fuse.Dirent, 0, len(d.items)) ret := make([]fuse.Dirent, 0, len(d.items)+2)
ret = append(ret, fuse.Dirent{
Inode: d.inode,
Name: ".",
Type: fuse.DT_Dir,
})
ret = append(ret, fuse.Dirent{
Inode: d.parentInode,
Name: "..",
Type: fuse.DT_Dir,
})
for _, node := range d.items { for _, node := range d.items {
var typ fuse.DirentType var typ fuse.DirentType
@ -166,7 +180,7 @@ func (d *dir) Lookup(ctx context.Context, name string) (fs.Node, error) {
} }
switch node.Type { switch node.Type {
case "dir": case "dir":
return newDir(ctx, d.root, fs.GenerateDynamicInode(d.inode, name), node) return newDir(ctx, d.root, fs.GenerateDynamicInode(d.inode, name), d.inode, node)
case "file": case "file":
return newFile(ctx, d.root, fs.GenerateDynamicInode(d.inode, name), node) return newFile(ctx, d.root, fs.GenerateDynamicInode(d.inode, name), node)
case "symlink": case "symlink":