2021-09-11 11:26:10 +00:00
|
|
|
//go:build darwin || freebsd || linux
|
2020-05-12 09:30:41 +00:00
|
|
|
// +build darwin freebsd linux
|
2017-06-18 15:02:07 +00:00
|
|
|
|
2017-06-18 12:59:44 +00:00
|
|
|
package fuse
|
|
|
|
|
|
|
|
import (
|
2020-02-17 15:26:53 +00:00
|
|
|
"os"
|
2017-12-28 12:18:27 +00:00
|
|
|
|
2021-09-11 11:26:10 +00:00
|
|
|
"github.com/restic/restic/internal/bloblru"
|
2017-07-23 12:21:03 +00:00
|
|
|
"github.com/restic/restic/internal/debug"
|
2017-07-24 15:42:25 +00:00
|
|
|
"github.com/restic/restic/internal/restic"
|
2017-06-18 12:59:44 +00:00
|
|
|
|
2022-11-12 13:52:37 +00:00
|
|
|
"github.com/anacrolix/fuse/fs"
|
2017-06-18 12:59:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config holds settings for the fuse mount.
|
|
|
|
type Config struct {
|
2020-09-03 18:31:57 +00:00
|
|
|
OwnerIsRoot bool
|
2023-02-17 15:13:46 +00:00
|
|
|
Filter restic.SnapshotFilter
|
2020-09-03 18:31:57 +00:00
|
|
|
TimeTemplate string
|
|
|
|
PathTemplates []string
|
2017-06-18 12:59:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Root is the root node of the fuse mount of a repository.
|
|
|
|
type Root struct {
|
2020-06-14 10:49:39 +00:00
|
|
|
repo restic.Repository
|
|
|
|
cfg Config
|
2021-09-11 11:26:10 +00:00
|
|
|
blobCache *bloblru.Cache
|
2017-12-28 12:18:27 +00:00
|
|
|
|
2020-09-02 19:27:24 +00:00
|
|
|
*SnapshotsDir
|
2020-02-17 15:26:53 +00:00
|
|
|
|
|
|
|
uid, gid uint32
|
2017-06-18 12:59:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ensure that *Root implements these interfaces
|
|
|
|
var _ = fs.HandleReadDirAller(&Root{})
|
|
|
|
var _ = fs.NodeStringLookuper(&Root{})
|
|
|
|
|
2017-06-18 18:56:01 +00:00
|
|
|
const rootInode = 1
|
|
|
|
|
2020-06-17 10:17:55 +00:00
|
|
|
// Size of the blob cache. TODO: make this configurable.
|
|
|
|
const blobCacheSize = 64 << 20
|
|
|
|
|
2017-06-18 12:59:44 +00:00
|
|
|
// NewRoot initializes a new root node from a repository.
|
2020-06-14 10:49:39 +00:00
|
|
|
func NewRoot(repo restic.Repository, cfg Config) *Root {
|
2017-06-18 12:59:44 +00:00
|
|
|
debug.Log("NewRoot(), config %v", cfg)
|
|
|
|
|
|
|
|
root := &Root{
|
2020-06-14 10:49:39 +00:00
|
|
|
repo: repo,
|
|
|
|
cfg: cfg,
|
2021-09-11 11:26:10 +00:00
|
|
|
blobCache: bloblru.New(blobCacheSize),
|
2017-06-18 18:56:01 +00:00
|
|
|
}
|
|
|
|
|
2020-02-17 15:26:53 +00:00
|
|
|
if !cfg.OwnerIsRoot {
|
|
|
|
root.uid = uint32(os.Getuid())
|
|
|
|
root.gid = uint32(os.Getgid())
|
|
|
|
}
|
|
|
|
|
2020-09-03 18:31:57 +00:00
|
|
|
// set defaults, if PathTemplates is not set
|
|
|
|
if len(cfg.PathTemplates) == 0 {
|
|
|
|
cfg.PathTemplates = []string{
|
|
|
|
"ids/%i",
|
|
|
|
"snapshots/%T",
|
|
|
|
"hosts/%h/%T",
|
|
|
|
"tags/%t/%T",
|
|
|
|
}
|
2017-06-18 12:59:44 +00:00
|
|
|
}
|
|
|
|
|
2022-08-07 11:02:40 +00:00
|
|
|
root.SnapshotsDir = NewSnapshotsDir(root, rootInode, rootInode, NewSnapshotsDirStructure(root, cfg.PathTemplates, cfg.TimeTemplate), "")
|
2017-06-18 12:59:44 +00:00
|
|
|
|
2020-06-17 10:17:55 +00:00
|
|
|
return root
|
2017-06-18 12:59:44 +00:00
|
|
|
}
|
|
|
|
|
2017-06-18 18:56:01 +00:00
|
|
|
// Root is just there to satisfy fs.Root, it returns itself.
|
|
|
|
func (r *Root) Root() (fs.Node, error) {
|
|
|
|
debug.Log("Root()")
|
|
|
|
return r, nil
|
2017-06-18 12:59:44 +00:00
|
|
|
}
|