From 4ea62ecbcc25150bb094214e042c0114aae04630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Batlle=20i=20Rossell?= Date: Mon, 9 May 2016 14:32:17 +0200 Subject: [PATCH 1/3] Traverse paths in the same order as parent snapshot This is the 2nd partial fix to #513. The archivepipe requires the snapshot paths and the backup paths to be traversed in the same order, and they were sorted differently: the backup paths by full path, and the snapshot by basename path. --- src/restic/archiver.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/restic/archiver.go b/src/restic/archiver.go index 9f9298f83..967665f36 100644 --- a/src/restic/archiver.go +++ b/src/restic/archiver.go @@ -622,12 +622,21 @@ func unique(items []string) []string { return items } +// Snapshots have contents sorted by basename, but we receive full paths. +// For the archivePipe to advance them in pairs, we traverse the given +// paths in the same order as the snapshot. +type BaseNameSlice []string + +func (p BaseNameSlice) Len() int { return len(p) } +func (p BaseNameSlice) Less(i, j int) bool { return filepath.Base(p[i]) < filepath.Base(p[j]) } +func (p BaseNameSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } + // Snapshot creates a snapshot of the given paths. If parentID is set, this is // used to compare the files to the ones archived at the time this snapshot was // taken. func (arch *Archiver) Snapshot(p *Progress, paths []string, parentID *backend.ID) (*Snapshot, backend.ID, error) { paths = unique(paths) - sort.Strings(paths) + sort.Sort(BaseNameSlice(paths)) debug.Log("Archiver.Snapshot", "start for %v", paths) From aed73be93d33c6dd9026d7641430b41feea3038c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Batlle=20i=20Rossell?= Date: Mon, 9 May 2016 14:44:03 +0200 Subject: [PATCH 2/3] Improve comment according to hound guidelines --- src/restic/archiver.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/restic/archiver.go b/src/restic/archiver.go index 967665f36..96d1e7977 100644 --- a/src/restic/archiver.go +++ b/src/restic/archiver.go @@ -622,6 +622,8 @@ func unique(items []string) []string { return items } +// BaseNameSlice allows sorting paths by basename. +// // Snapshots have contents sorted by basename, but we receive full paths. // For the archivePipe to advance them in pairs, we traverse the given // paths in the same order as the snapshot. From 83aa63365a50211e23ec4aba7025d16dd2b7e88b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Batlle=20i=20Rossell?= Date: Mon, 9 May 2016 14:46:14 +0200 Subject: [PATCH 3/3] Not exporting baseNameSlice. Noone else wants it. --- src/restic/archiver.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/restic/archiver.go b/src/restic/archiver.go index 96d1e7977..1f1eeeda6 100644 --- a/src/restic/archiver.go +++ b/src/restic/archiver.go @@ -622,23 +622,23 @@ func unique(items []string) []string { return items } -// BaseNameSlice allows sorting paths by basename. +// baseNameSlice allows sorting paths by basename. // // Snapshots have contents sorted by basename, but we receive full paths. // For the archivePipe to advance them in pairs, we traverse the given // paths in the same order as the snapshot. -type BaseNameSlice []string +type baseNameSlice []string -func (p BaseNameSlice) Len() int { return len(p) } -func (p BaseNameSlice) Less(i, j int) bool { return filepath.Base(p[i]) < filepath.Base(p[j]) } -func (p BaseNameSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } +func (p baseNameSlice) Len() int { return len(p) } +func (p baseNameSlice) Less(i, j int) bool { return filepath.Base(p[i]) < filepath.Base(p[j]) } +func (p baseNameSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } // Snapshot creates a snapshot of the given paths. If parentID is set, this is // used to compare the files to the ones archived at the time this snapshot was // taken. func (arch *Archiver) Snapshot(p *Progress, paths []string, parentID *backend.ID) (*Snapshot, backend.ID, error) { paths = unique(paths) - sort.Sort(BaseNameSlice(paths)) + sort.Sort(baseNameSlice(paths)) debug.Log("Archiver.Snapshot", "start for %v", paths)