2017-06-18 15:02:07 +00:00
|
|
|
// +build !openbsd
|
|
|
|
// +build !windows
|
|
|
|
|
2017-06-18 12:59:44 +00:00
|
|
|
package fuse
|
|
|
|
|
|
|
|
import (
|
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
|
|
|
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
|
|
|
"bazil.org/fuse/fs"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config holds settings for the fuse mount.
|
|
|
|
type Config struct {
|
|
|
|
OwnerIsRoot bool
|
|
|
|
Host string
|
2017-07-09 07:47:41 +00:00
|
|
|
Tags []restic.TagList
|
2017-06-18 12:59:44 +00:00
|
|
|
Paths []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
blobSizeCache *BlobSizeCache
|
2017-06-18 18:25:31 +00:00
|
|
|
|
2017-06-18 18:56:01 +00:00
|
|
|
*MetaDir
|
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
|
|
|
|
|
2017-06-18 12:59:44 +00:00
|
|
|
// NewRoot initializes a new root node from a repository.
|
|
|
|
func NewRoot(ctx context.Context, repo restic.Repository, cfg Config) (*Root, error) {
|
|
|
|
debug.Log("NewRoot(), config %v", cfg)
|
|
|
|
|
|
|
|
root := &Root{
|
2017-06-18 18:56:01 +00:00
|
|
|
repo: repo,
|
|
|
|
inode: rootInode,
|
|
|
|
cfg: cfg,
|
|
|
|
blobSizeCache: NewBlobSizeCache(ctx, repo.Index()),
|
|
|
|
}
|
|
|
|
|
|
|
|
entries := map[string]fs.Node{
|
2017-10-05 12:55:55 +00:00
|
|
|
"snapshots": NewSnapshotsDir(root, fs.GenerateDynamicInode(root.inode, "snapshots"), "", ""),
|
|
|
|
"tags": NewTagsDir(root, fs.GenerateDynamicInode(root.inode, "tags")),
|
|
|
|
"hosts": NewHostsDir(root, fs.GenerateDynamicInode(root.inode, "hosts")),
|
|
|
|
"ids": NewSnapshotsIDSDir(root, fs.GenerateDynamicInode(root.inode, "ids")),
|
2017-06-18 12:59:44 +00:00
|
|
|
}
|
|
|
|
|
2017-06-18 18:56:01 +00:00
|
|
|
root.MetaDir = NewMetaDir(root, rootInode, entries)
|
2017-06-18 12:59:44 +00:00
|
|
|
|
|
|
|
return root, nil
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|