mirror of
https://github.com/jkl1337/duplicacy.git
synced 2026-01-02 11:44:45 -06:00
Calculate file hash during in-place restore
This commit is contained in:
@@ -21,6 +21,7 @@ ${DUPLICACY} check --files -stats
|
|||||||
rm file1 file3
|
rm file1 file3
|
||||||
|
|
||||||
${DUPLICACY} restore -r 1
|
${DUPLICACY} restore -r 1
|
||||||
|
${DUPLICACY} -v restore -r 1 -overwrite -stats -hash
|
||||||
|
|
||||||
ls -lsh file3
|
ls -lsh file3
|
||||||
|
|
||||||
|
|||||||
@@ -1193,6 +1193,7 @@ func (manager *BackupManager) RestoreFile(chunkDownloader *ChunkDownloader, chun
|
|||||||
if inPlace {
|
if inPlace {
|
||||||
// In inplace mode, we only consider chunks in the existing file with the same offsets, so we
|
// 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
|
// break the original file at offsets retrieved from the backup
|
||||||
|
fileHasher := manager.config.NewFileHasher()
|
||||||
buffer := make([]byte, 64 * 1024)
|
buffer := make([]byte, 64 * 1024)
|
||||||
err = nil
|
err = nil
|
||||||
for i := entry.StartChunk; i <= entry.EndChunk; i++ {
|
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])
|
n, err := existingFile.Read(buffer[:n])
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
hasher.Write(buffer[:n])
|
hasher.Write(buffer[:n])
|
||||||
|
fileHasher.Write(buffer[:n])
|
||||||
count += n
|
count += n
|
||||||
}
|
}
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
@@ -1235,6 +1237,7 @@ func (manager *BackupManager) RestoreFile(chunkDownloader *ChunkDownloader, chun
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fileHash = hex.EncodeToString(fileHasher.Sum(nil))
|
||||||
} else {
|
} else {
|
||||||
// If it is not inplace, we want to reuse any chunks in the existing file regardless their offets, so
|
// 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.
|
// we run the chunk maker to split the original file.
|
||||||
@@ -1253,10 +1256,10 @@ func (manager *BackupManager) RestoreFile(chunkDownloader *ChunkDownloader, chun
|
|||||||
fileHash = hash
|
fileHash = hash
|
||||||
return nil, false
|
return nil, false
|
||||||
})
|
})
|
||||||
if fileHash == entry.Hash && fileHash != "" {
|
}
|
||||||
LOG_TRACE("DOWNLOAD_SKIP", "File %s unchanged (by hash)", entry.Path)
|
if fileHash == entry.Hash && fileHash != "" {
|
||||||
return false
|
LOG_TRACE("DOWNLOAD_SKIP", "File %s unchanged (by hash)", entry.Path)
|
||||||
}
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user