mirror of
https://github.com/restic/restic.git
synced 2026-07-05 23:05:08 +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:
@@ -0,0 +1,38 @@
|
||||
//go:build darwin || freebsd || linux
|
||||
// +build darwin freebsd linux
|
||||
|
||||
package fuse
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/anacrolix/fuse/fs"
|
||||
)
|
||||
|
||||
type treeCache struct {
|
||||
nodes map[string]fs.Node
|
||||
m sync.Mutex
|
||||
}
|
||||
|
||||
func newTreeCache() *treeCache {
|
||||
return &treeCache{
|
||||
nodes: map[string]fs.Node{},
|
||||
}
|
||||
}
|
||||
|
||||
func (t *treeCache) lookupOrCreate(name string, create func() (fs.Node, error)) (fs.Node, error) {
|
||||
t.m.Lock()
|
||||
defer t.m.Unlock()
|
||||
|
||||
if node, ok := t.nodes[name]; ok {
|
||||
return node, nil
|
||||
}
|
||||
|
||||
node, err := create()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
t.nodes[name] = node
|
||||
return node, nil
|
||||
}
|
||||
Reference in New Issue
Block a user