diff --git a/cmd/restic/cmd_mount.go b/cmd/restic/cmd_mount.go index b17c3d478..59fb4e82a 100644 --- a/cmd/restic/cmd_mount.go +++ b/cmd/restic/cmd_mount.go @@ -139,7 +139,7 @@ func mount(opts MountOptions, gopts GlobalOptions, mountpoint string) error { Paths: opts.Paths, SnapshotTemplate: opts.SnapshotTemplate, } - root := fuse.NewRoot(gopts.ctx, repo, cfg) + root := fuse.NewRoot(repo, cfg) Printf("Now serving the repository at %s\n", mountpoint) Printf("When finished, quit with Ctrl-c or umount the mountpoint.\n") diff --git a/internal/fuse/blob_size_cache.go b/internal/fuse/blob_size_cache.go deleted file mode 100644 index 4e9873092..000000000 --- a/internal/fuse/blob_size_cache.go +++ /dev/null @@ -1,34 +0,0 @@ -// +build darwin freebsd linux - -package fuse - -import ( - "github.com/restic/restic/internal/restic" - "golang.org/x/net/context" -) - -// BlobSizeCache caches the size of blobs in the repo. -type BlobSizeCache struct { - m map[restic.ID]uint -} - -// NewBlobSizeCache returns a new blob size cache containing all entries from midx. -func NewBlobSizeCache(ctx context.Context, idx restic.Index) *BlobSizeCache { - m := make(map[restic.ID]uint, 1000) - for pb := range idx.Each(ctx) { - m[pb.ID] = uint(restic.PlaintextLength(int(pb.Length))) - } - return &BlobSizeCache{ - m: m, - } -} - -// Lookup returns the size of the blob id. -func (c *BlobSizeCache) Lookup(id restic.ID) (size uint, found bool) { - if c == nil { - return 0, false - } - - size, found = c.m[id] - return size, found -} diff --git a/internal/fuse/dir.go b/internal/fuse/dir.go index 03d56883a..50094649e 100644 --- a/internal/fuse/dir.go +++ b/internal/fuse/dir.go @@ -24,8 +24,6 @@ type dir struct { inode uint64 parentInode uint64 node *restic.Node - - blobsize *BlobSizeCache } func cleanupNodeName(name string) string { diff --git a/internal/fuse/file.go b/internal/fuse/file.go index b38258fd1..e4ab27010 100644 --- a/internal/fuse/file.go +++ b/internal/fuse/file.go @@ -35,13 +35,9 @@ func newFile(ctx context.Context, root *Root, inode uint64, node *restic.Node) ( var bytes uint64 cumsize := make([]uint64, 1+len(node.Content)) for i, id := range node.Content { - size, ok := root.blobSizeCache.Lookup(id) - if !ok { - var found bool - size, found = root.repo.LookupBlobSize(id, restic.DataBlob) - if !found { - return nil, errors.Errorf("id %v not found in repository", id) - } + size, found := root.repo.LookupBlobSize(id, restic.DataBlob) + if !found { + return nil, errors.Errorf("id %v not found in repository", id) } bytes += uint64(size) diff --git a/internal/fuse/fuse_test.go b/internal/fuse/fuse_test.go index 465f7208c..ab4ecf89e 100644 --- a/internal/fuse/fuse_test.go +++ b/internal/fuse/fuse_test.go @@ -156,9 +156,7 @@ func TestFuseFile(t *testing.T) { Size: filesize, Content: content, } - root := NewRoot(context.TODO(), repo, Config{}) - - t.Logf("blob cache has %d entries", len(root.blobSizeCache.m)) + root := NewRoot(repo, Config{}) inode := fs.GenerateDynamicInode(1, "foo") f, err := newFile(context.TODO(), root, inode, node) @@ -202,7 +200,7 @@ func testTopUidGid(t *testing.T, cfg Config, repo restic.Repository, uid, gid ui t.Helper() ctx := context.Background() - root := NewRoot(ctx, repo, cfg) + root := NewRoot(repo, cfg) var attr fuse.Attr err := root.Attr(ctx, &attr) diff --git a/internal/fuse/root.go b/internal/fuse/root.go index c43f8b448..ecbd10546 100644 --- a/internal/fuse/root.go +++ b/internal/fuse/root.go @@ -9,8 +9,6 @@ import ( "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/restic" - "golang.org/x/net/context" - "bazil.org/fuse/fs" ) @@ -25,12 +23,11 @@ type Config struct { // Root is the root node of the fuse mount of a repository. type Root struct { - repo restic.Repository - cfg Config - inode uint64 - snapshots restic.Snapshots - blobCache *blobCache - blobSizeCache *BlobSizeCache + repo restic.Repository + cfg Config + inode uint64 + snapshots restic.Snapshots + blobCache *blobCache snCount int lastCheck time.Time @@ -50,15 +47,14 @@ const rootInode = 1 const blobCacheSize = 64 << 20 // NewRoot initializes a new root node from a repository. -func NewRoot(ctx context.Context, repo restic.Repository, cfg Config) *Root { +func NewRoot(repo restic.Repository, cfg Config) *Root { debug.Log("NewRoot(), config %v", cfg) root := &Root{ - repo: repo, - inode: rootInode, - cfg: cfg, - blobCache: newBlobCache(blobCacheSize), - blobSizeCache: NewBlobSizeCache(ctx, repo.Index()), + repo: repo, + inode: rootInode, + cfg: cfg, + blobCache: newBlobCache(blobCacheSize), } if !cfg.OwnerIsRoot {