mirror of
https://github.com/restic/restic.git
synced 2026-11-06 07:19:21 +00:00
fuse: cache fs.Node instances
A particular node should always be represented by a single instance. This is necessary to allow the fuse library to assign a stable nodeId to a node. macOS Sonoma trips over the previous, unstable behavior when using fuse-t.
This commit is contained in:
1 parent
c1532179d4
commit
6ec2b62ec5
3 files changed
+71
-24
No files matched your search
+24
-19
@@ -29,6 +29,7 @@ type dir struct {
|
||||
parentInode uint64
|
||||
node *restic.Node
|
||||
m sync.Mutex
|
||||
cache treeCache
|
||||
}
|
||||
|
||||
func cleanupNodeName(name string) string {
|
||||
@@ -43,6 +44,7 @@ func newDir(root *Root, inode, parentInode uint64, node *restic.Node) (*dir, err
|
||||
node: node,
|
||||
inode: inode,
|
||||
parentInode: parentInode,
|
||||
cache: *newTreeCache(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -87,6 +89,7 @@ func newDirFromSnapshot(root *Root, inode uint64, snapshot *restic.Snapshot) (*d
|
||||
Subtree: snapshot.Tree,
|
||||
},
|
||||
inode: inode,
|
||||
cache: *newTreeCache(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -208,25 +211,27 @@ func (d *dir) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
node, ok := d.items[name]
|
||||
if !ok {
|
||||
debug.Log(" Lookup(%v) -> not found", name)
|
||||
return nil, syscall.ENOENT
|
||||
}
|
||||
inode := inodeFromNode(d.inode, node)
|
||||
switch node.Type {
|
||||
case restic.NodeTypeDir:
|
||||
return newDir(d.root, inode, d.inode, node)
|
||||
case restic.NodeTypeFile:
|
||||
return newFile(d.root, inode, node)
|
||||
case restic.NodeTypeSymlink:
|
||||
return newLink(d.root, inode, node)
|
||||
case restic.NodeTypeDev, restic.NodeTypeCharDev, restic.NodeTypeFifo, restic.NodeTypeSocket:
|
||||
return newOther(d.root, inode, node)
|
||||
default:
|
||||
debug.Log(" node %v has unknown type %v", name, node.Type)
|
||||
return nil, syscall.ENOENT
|
||||
}
|
||||
return d.cache.lookupOrCreate(name, func() (fs.Node, error) {
|
||||
node, ok := d.items[name]
|
||||
if !ok {
|
||||
debug.Log(" Lookup(%v) -> not found", name)
|
||||
return nil, syscall.ENOENT
|
||||
}
|
||||
inode := inodeFromNode(d.inode, node)
|
||||
switch node.Type {
|
||||
case restic.NodeTypeDir:
|
||||
return newDir(d.root, inode, d.inode, node)
|
||||
case restic.NodeTypeFile:
|
||||
return newFile(d.root, inode, node)
|
||||
case restic.NodeTypeSymlink:
|
||||
return newLink(d.root, inode, node)
|
||||
case restic.NodeTypeDev, restic.NodeTypeCharDev, restic.NodeTypeFifo, restic.NodeTypeSocket:
|
||||
return newOther(d.root, inode, node)
|
||||
default:
|
||||
debug.Log(" node %v has unknown type %v", name, node.Type)
|
||||
return nil, syscall.ENOENT
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (d *dir) Listxattr(_ context.Context, req *fuse.ListxattrRequest, resp *fuse.ListxattrResponse) error {
|
||||
|
||||
Reference in new issue
Block a user