From a0f3e94655244cb691f38dfd5181e44034699d55 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Thu, 15 Sep 2016 21:15:49 +0200 Subject: [PATCH] fuse: handle duplicate timestamps for snapshots This closes #606, which fails because several snapshots are created with exactly the same timestamp, and the code checks that for each snapshot there is a dir in the fuse mount. This fails for colliding timestamps, so we now add a suffix "-1", "-2" etc for each duplicate timestamp. --- src/restic/fuse/snapshot.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/restic/fuse/snapshot.go b/src/restic/fuse/snapshot.go index d71adbc79..9270e9adc 100644 --- a/src/restic/fuse/snapshot.go +++ b/src/restic/fuse/snapshot.go @@ -4,6 +4,7 @@ package fuse import ( + "fmt" "os" "sync" "time" @@ -65,11 +66,24 @@ func (sn *SnapshotsDir) updateCache(ctx context.Context) error { defer sn.Unlock() for id := range sn.repo.List(restic.SnapshotFile, ctx.Done()) { + debug.Log("SnapshotsDir.List", "found snapshot id %v", id.Str()) snapshot, err := restic.LoadSnapshot(sn.repo, id) if err != nil { return err } - sn.knownSnapshots[snapshot.Time.Format(time.RFC3339)] = SnapshotWithId{snapshot, id} + + timestamp := snapshot.Time.Format(time.RFC3339) + + for i := 1; ; i++ { + if _, ok := sn.knownSnapshots[timestamp]; !ok { + break + } + + timestamp = fmt.Sprintf("%s-%d", snapshot.Time.Format(time.RFC3339), i) + } + + debug.Log("SnapshotsDir.List", " add %v as dir %v", id.Str(), timestamp) + sn.knownSnapshots[timestamp] = SnapshotWithId{snapshot, id} } return nil }