depot/patches/base/ipfs/ipfs-fuse-cache-child-nodes.patch

44 lines
1.5 KiB
Diff
Raw Normal View History

2021-06-05 23:59:06 +03:00
diff --git a/fuse/readonly/readonly_unix.go b/fuse/readonly/readonly_unix.go
index 866cdca1a..3a2269393 100644
--- a/fuse/readonly/readonly_unix.go
+++ b/fuse/readonly/readonly_unix.go
@@ -73,7 +73,7 @@ func (s *Root) Lookup(ctx context.Context, name string) (fs.Node, error) {
switch nd := nd.(type) {
case *mdag.ProtoNode, *mdag.RawNode:
- return &Node{Ipfs: s.Ipfs, Nd: nd}, nil
+ return &Node{Ipfs: s.Ipfs, Nd: nd, children: make(map[string]fs.Node)}, nil
default:
log.Error("fuse node was not a protobuf node")
return nil, fuse.ENOTSUP
@@ -92,6 +92,7 @@ type Node struct {
Ipfs *core.IpfsNode
Nd ipld.Node
cached *ft.FSNode
+ children map[string]fs.Node
}
func (s *Node) loadData() error {
@@ -144,6 +145,9 @@ func (s *Node) Attr(ctx context.Context, a *fuse.Attr) error {
// Lookup performs a lookup under this node.
func (s *Node) Lookup(ctx context.Context, name string) (fs.Node, error) {
log.Debugf("Lookup '%s'", name)
+ if childNode, ok := s.children[name] ; ok {
+ return childNode, nil
+ }
link, _, err := uio.ResolveUnixfsOnce(ctx, s.Ipfs.DAG, s.Nd, []string{name})
switch err {
case os.ErrNotExist, mdag.ErrLinkNotFound:
@@ -165,8 +169,9 @@ func (s *Node) Lookup(ctx context.Context, name string) (fs.Node, error) {
case nil:
// noop
}
-
- return &Node{Ipfs: s.Ipfs, Nd: nd}, nil
+ childNode := &Node{Ipfs: s.Ipfs, Nd: nd, children: make(map[string]fs.Node)}
+ s.children[name] = childNode
+ return childNode, nil
}
// ReadDirAll reads the link structure as directory entries