2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-02 11:46:36 +00:00

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.
This commit is contained in:
Lluís Batlle i Rossell 2016-05-09 14:32:17 +02:00
parent 7572586ded
commit 4ea62ecbcc

View File

@ -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)