fuse/mount: Add option for snapshot template

This commit is contained in:
Alexander Neumann
2018-01-14 14:22:08 +01:00
parent f49f5c5903
commit 97565d68a2
4 changed files with 61 additions and 26 deletions

View File

@@ -16,10 +16,11 @@ import (
// Config holds settings for the fuse mount.
type Config struct {
OwnerIsRoot bool
Host string
Tags []restic.TagList
Paths []string
OwnerIsRoot bool
Host string
Tags []restic.TagList
Paths []string
SnapshotTemplate string
}
// Root is the root node of the fuse mount of a repository.

View File

@@ -26,6 +26,8 @@ type SnapshotsDir struct {
tag string
host string
snCount int
template string
}
// SnapshotsIDSDir is a fuse directory which contains snapshots named by ids.
@@ -112,12 +114,13 @@ func updateSnapshotIDSNames(d *SnapshotsIDSDir) {
func NewSnapshotsDir(root *Root, inode uint64, tag string, host string) *SnapshotsDir {
debug.Log("create snapshots dir, inode %d", inode)
d := &SnapshotsDir{
root: root,
inode: inode,
names: make(map[string]*restic.Snapshot),
latest: "",
tag: tag,
host: host,
root: root,
inode: inode,
names: make(map[string]*restic.Snapshot),
latest: "",
tag: tag,
host: host,
template: root.cfg.SnapshotTemplate,
}
return d
@@ -239,7 +242,7 @@ func updateSnapshots(ctx context.Context, root *Root) {
}
// read snapshot timestamps from the current repository-state.
func updateSnapshotNames(d *SnapshotsDir) {
func updateSnapshotNames(d *SnapshotsDir, template string) {
if d.snCount != d.root.snCount {
d.snCount = d.root.snCount
var latestTime time.Time
@@ -248,7 +251,7 @@ func updateSnapshotNames(d *SnapshotsDir) {
for _, sn := range d.root.snapshots {
if d.tag == "" || isElem(d.tag, sn.Tags) {
if d.host == "" || d.host == sn.Hostname {
name := sn.Time.Format(time.RFC3339)
name := sn.Time.Format(template)
if d.latest == "" || !sn.Time.Before(latestTime) {
latestTime = sn.Time
d.latest = name
@@ -258,7 +261,7 @@ func updateSnapshotNames(d *SnapshotsDir) {
break
}
name = fmt.Sprintf("%s-%d", sn.Time.Format(time.RFC3339), i)
name = fmt.Sprintf("%s-%d", sn.Time.Format(template), i)
}
d.names[name] = sn
@@ -276,7 +279,7 @@ func (d *SnapshotsDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
updateSnapshots(ctx, d.root)
// update snapshot names
updateSnapshotNames(d)
updateSnapshotNames(d, d.root.cfg.SnapshotTemplate)
items := []fuse.Dirent{
{
@@ -450,7 +453,7 @@ func (d *SnapshotsDir) Lookup(ctx context.Context, name string) (fs.Node, error)
updateSnapshots(ctx, d.root)
// update snapshot names
updateSnapshotNames(d)
updateSnapshotNames(d, d.root.cfg.SnapshotTemplate)
sn, ok := d.names[name]
if ok {