From dd11641611386ad7b970034429ae5ab6e4582f01 Mon Sep 17 00:00:00 2001 From: Gilbert Chen Date: Fri, 9 Jun 2017 21:05:44 -0400 Subject: [PATCH] Fixed a bug that caused restoration of two adjacent files to crash --- src/duplicacy_backupmanager_test.go | 14 ++++++++++++++ src/duplicacy_chunkdownloader.go | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/duplicacy_backupmanager_test.go b/src/duplicacy_backupmanager_test.go index 056d3ec..0a48dbb 100644 --- a/src/duplicacy_backupmanager_test.go +++ b/src/duplicacy_backupmanager_test.go @@ -267,6 +267,20 @@ func TestBackupManager(t *testing.T) { } } + // Remove file2 and dir1/file3 and restore them from revision 3 + os.Remove(testDir + "/repository1/file2") + os.Remove(testDir + "/repository1/dir1/file3") + backupManager.Restore(testDir + "/repository1", 3, /*inPlace=*/true, /*quickMode=*/false, threads, /*overwrite=*/true, + /*deleteMode=*/false, /*showStatistics=*/false, /*patterns=*/[]string{"+file2", "+dir1/file3", "-*"}) + + for _, f := range []string{ "file1", "file2", "dir1/file3" } { + hash1 := getFileHash(testDir + "/repository1/" + f) + hash2 := getFileHash(testDir + "/repository2/" + f) + if hash1 != hash2 { + t.Errorf("File %s has different hashes: %s vs %s", f, hash1, hash2) + } + } + /*buf := make([]byte, 1<<16) runtime.Stack(buf, true) fmt.Printf("%s", buf)*/ diff --git a/src/duplicacy_chunkdownloader.go b/src/duplicacy_chunkdownloader.go index a2eac77..74d8ec7 100644 --- a/src/duplicacy_chunkdownloader.go +++ b/src/duplicacy_chunkdownloader.go @@ -110,7 +110,7 @@ func (downloader *ChunkDownloader) AddFiles(snapshot *Snapshot, files [] *Entry) } downloader.taskList = append(downloader.taskList, task) } else { - downloader.taskList[lastChunkIndex].needed = true + downloader.taskList[len(downloader.taskList) - 1].needed = true } lastChunkIndex = i }