2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 19:08:55 +00:00

Fix comparison for new files with '.'

This commit is contained in:
Alexander Neumann 2015-03-09 22:56:23 +01:00
parent 14298fe232
commit 2166367039
2 changed files with 53 additions and 23 deletions

View File

@ -622,11 +622,19 @@ func (a *ArchivePipe) compare(done <-chan struct{}, out chan<- pipe.Job) {
loadNew = true loadNew = true
out <- archiveJob{new: newJob}.Copy() out <- archiveJob{new: newJob}.Copy()
continue continue
} else if dir1 == dir2 && file1 < file2 { } else if dir1 == dir2 {
if file1 < file2 {
debug.Log("ArchivePipe.compare", " %q < %q, file %q removed", file1, file2, file1) debug.Log("ArchivePipe.compare", " %q < %q, file %q removed", file1, file2, file1)
// file has been removed, load new old // file has been removed, load new old
loadOld = true loadOld = true
continue continue
} else {
debug.Log("ArchivePipe.compare", " %q > %q, file %q added", file1, file2, file2)
// file is new, send new job and load new
loadNew = true
out <- archiveJob{new: newJob}.Copy()
continue
}
} }
debug.Log("ArchivePipe.compare", " %q > %q, file %q removed", file1, file2, file1) debug.Log("ArchivePipe.compare", " %q > %q, file %q removed", file1, file2, file1)

View File

@ -9,8 +9,10 @@ import (
var treeJobs = []string{ var treeJobs = []string{
"foo/baz/subdir", "foo/baz/subdir",
"foo/bar", "foo/baz",
"foo", "foo",
"quu/bar/file1",
"quu/bar/file2",
"quu/foo/file1", "quu/foo/file1",
"quu/foo/file2", "quu/foo/file2",
"quu/foo/file3", "quu/foo/file3",
@ -25,8 +27,11 @@ var treeJobs = []string{
var pipeJobs = []string{ var pipeJobs = []string{
"foo/baz/subdir", "foo/baz/subdir",
"foo/baz/subdir2", // subdir2 added "foo/baz/subdir2", // subdir2 added
"foo/bar", "foo/baz",
"foo", "foo",
"quu/bar/.file1.swp", // file with . added
"quu/bar/file1",
"quu/bar/file2",
"quu/foo/file1", // file2 removed "quu/foo/file1", // file2 removed
"quu/foo/file3", "quu/foo/file3",
"quu/foo", "quu/foo",
@ -34,29 +39,34 @@ var pipeJobs = []string{
"quv/file1", // files added and removed "quv/file1", // files added and removed
"quv/file2", "quv/file2",
"quv", "quv",
"zz/file1", // new files removed and added at the end "yy",
"zz/file1", // files removed and added at the end
"zz/file2", "zz/file2",
"zz", "zz",
} }
var resultJobs = []struct { var resultJobs = []struct {
path string path string
hasOld bool action string
}{ }{
{"foo/baz/subdir", true}, {"foo/baz/subdir", "same, not a file"},
{"foo/baz/subdir2", false}, {"foo/baz/subdir2", "new, no old job"},
{"foo/bar", true}, {"foo/baz", "same, not a file"},
{"foo", true}, {"foo", "same, not a file"},
{"quu/foo/file1", true}, {"quu/bar/.file1.swp", "new, no old job"},
{"quu/foo/file3", true}, {"quu/bar/file1", "same, not a file"},
{"quu/foo", true}, {"quu/bar/file2", "same, not a file"},
{"quu", true}, {"quu/foo/file1", "same, not a file"},
{"quv/file1", false}, {"quu/foo/file3", "same, not a file"},
{"quv/file2", false}, {"quu/foo", "same, not a file"},
{"quv", false}, {"quu", "same, not a file"},
{"zz/file1", false}, {"quv/file1", "new, no old job"},
{"zz/file2", false}, {"quv/file2", "new, no old job"},
{"zz", false}, {"quv", "new, no old job"},
{"yy", "same, not a file"},
{"zz/file1", "testPipeJob"},
{"zz/file2", "testPipeJob"},
{"zz", "testPipeJob"},
} }
type testPipeJob struct { type testPipeJob struct {
@ -116,6 +126,18 @@ func TestArchivePipe(t *testing.T) {
if job.Path() != resultJobs[i].path { if job.Path() != resultJobs[i].path {
t.Fatalf("wrong job received: wanted %v, got %v", resultJobs[i], job) t.Fatalf("wrong job received: wanted %v, got %v", resultJobs[i], job)
} }
// switch j := job.(type) {
// case archivePipeJob:
// if j.action != resultJobs[i].action {
// t.Fatalf("wrong action for %v detected: wanted %q, got %q", job.Path(), resultJobs[i].action, j.action)
// }
// case testPipeJob:
// if resultJobs[i].action != "testPipeJob" {
// t.Fatalf("unexpected testPipeJob, expected %q: %v", resultJobs[i].action, j)
// }
// }
i++ i++
} }
} }