1
0
mirror of https://github.com/gilbertchen/duplicacy synced 2025-12-06 00:03:38 +00:00

Calculate file hash during in-place restore

This commit is contained in:
Gilbert Chen
2017-07-21 15:19:11 -04:00
parent d881ac9169
commit 2d1ea86d8e
2 changed files with 8 additions and 4 deletions

View File

@@ -21,6 +21,7 @@ ${DUPLICACY} check --files -stats
rm file1 file3
${DUPLICACY} restore -r 1
${DUPLICACY} -v restore -r 1 -overwrite -stats -hash
ls -lsh file3

View File

@@ -1193,6 +1193,7 @@ func (manager *BackupManager) RestoreFile(chunkDownloader *ChunkDownloader, chun
if inPlace {
// In inplace mode, we only consider chunks in the existing file with the same offsets, so we
// break the original file at offsets retrieved from the backup
fileHasher := manager.config.NewFileHasher()
buffer := make([]byte, 64 * 1024)
err = nil
for i := entry.StartChunk; i <= entry.EndChunk; i++ {
@@ -1212,6 +1213,7 @@ func (manager *BackupManager) RestoreFile(chunkDownloader *ChunkDownloader, chun
n, err := existingFile.Read(buffer[:n])
if n > 0 {
hasher.Write(buffer[:n])
fileHasher.Write(buffer[:n])
count += n
}
if err == io.EOF {
@@ -1235,6 +1237,7 @@ func (manager *BackupManager) RestoreFile(chunkDownloader *ChunkDownloader, chun
break
}
}
fileHash = hex.EncodeToString(fileHasher.Sum(nil))
} else {
// If it is not inplace, we want to reuse any chunks in the existing file regardless their offets, so
// we run the chunk maker to split the original file.
@@ -1253,10 +1256,10 @@ func (manager *BackupManager) RestoreFile(chunkDownloader *ChunkDownloader, chun
fileHash = hash
return nil, false
})
if fileHash == entry.Hash && fileHash != "" {
LOG_TRACE("DOWNLOAD_SKIP", "File %s unchanged (by hash)", entry.Path)
return false
}
}
if fileHash == entry.Hash && fileHash != "" {
LOG_TRACE("DOWNLOAD_SKIP", "File %s unchanged (by hash)", entry.Path)
return false
}
}