fuse: Add a snapshot IDs directory (#1102)

This commit is contained in:
Tobias Klein 2017-09-30 14:10:16 +02:00
parent ac92e2dd2d
commit 49bc1d0b3b
2 changed files with 21 additions and 0 deletions

View file

@ -56,6 +56,7 @@ func NewRoot(ctx context.Context, repo restic.Repository, cfg Config) (*Root, er
"snapshots": NewSnapshotsDir(root, fs.GenerateDynamicInode(root.inode, "snapshots"), snapshots),
"tags": NewTagsDir(root, fs.GenerateDynamicInode(root.inode, "tags"), snapshots),
"hosts": NewHostsDir(root, fs.GenerateDynamicInode(root.inode, "hosts"), snapshots),
"ids": NewSnapshotsIDSDir(root, fs.GenerateDynamicInode(root.inode, "ids"), snapshots),
}
root.MetaDir = NewMetaDir(root, rootInode, entries)

View file

@ -66,6 +66,26 @@ func NewSnapshotsDir(root *Root, inode uint64, snapshots restic.Snapshots) *Snap
return d
}
// NewSnapshotsIDSDir returns a new directory containing snapshots named by ids.
func NewSnapshotsIDSDir(root *Root, inode uint64, snapshots restic.Snapshots) *SnapshotsDir {
debug.Log("create snapshots ids dir with %d snapshots, inode %d", len(snapshots), inode)
d := &SnapshotsDir{
root: root,
inode: inode,
snapshots: snapshots,
names: make(map[string]*restic.Snapshot, len(snapshots)),
}
for _, sn := range snapshots {
name := sn.ID().Str()
d.names[name] = sn
debug.Log(" add snapshot %v", name)
}
return d
}
// Attr returns the attributes for the root node.
func (d *SnapshotsDir) Attr(ctx context.Context, attr *fuse.Attr) error {
attr.Inode = d.inode