mirror of
https://github.com/jkl1337/duplicacy.git
synced 2026-01-03 04:04:45 -06:00
Don't compute file hashes when DUPLICACY_SKIP_FILE_HASH is set; handle vertical backup-style hashes in restore
This commit is contained in:
@@ -1233,7 +1233,7 @@ func (manager *BackupManager) RestoreFile(chunkDownloader *ChunkDownloader, chun
|
|||||||
|
|
||||||
// Verify the download by hash
|
// Verify the download by hash
|
||||||
hash := hex.EncodeToString(hasher.Sum(nil))
|
hash := hex.EncodeToString(hasher.Sum(nil))
|
||||||
if hash != entry.Hash {
|
if hash != entry.Hash && hash != "" && entry.Hash != "" && !strings.HasPrefix(entry.Hash, "#") {
|
||||||
LOG_ERROR("DOWNLOAD_HASH", "File %s has a mismatched hash: %s instead of %s (in-place)",
|
LOG_ERROR("DOWNLOAD_HASH", "File %s has a mismatched hash: %s instead of %s (in-place)",
|
||||||
fullPath, "", entry.Hash)
|
fullPath, "", entry.Hash)
|
||||||
return false
|
return false
|
||||||
@@ -1306,7 +1306,7 @@ func (manager *BackupManager) RestoreFile(chunkDownloader *ChunkDownloader, chun
|
|||||||
}
|
}
|
||||||
|
|
||||||
hash := hex.EncodeToString(hasher.Sum(nil))
|
hash := hex.EncodeToString(hasher.Sum(nil))
|
||||||
if hash != entry.Hash {
|
if hash != entry.Hash && hash != "" && entry.Hash != "" && !strings.HasPrefix(entry.Hash, "#") {
|
||||||
LOG_ERROR("DOWNLOAD_HASH", "File %s has a mismatched hash: %s instead of %s",
|
LOG_ERROR("DOWNLOAD_HASH", "File %s has a mismatched hash: %s instead of %s",
|
||||||
entry.Path, hash, entry.Hash)
|
entry.Path, hash, entry.Hash)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -225,8 +225,41 @@ func (config *Config) NewKeyedHasher(key []byte) hash.Hash {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var SkipFileHash = false
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if value, found := os.LookupEnv("DUPLICACY_SKIP_FILE_HASH"); found && value != "" && value != "0" {
|
||||||
|
SkipFileHash = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implement a dummy hasher to be used when SkipFileHash is true.
|
||||||
|
type DummyHasher struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (hasher *DummyHasher) Write(p []byte) (int, error) {
|
||||||
|
return len(p), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (hasher *DummyHasher) Sum(b []byte) []byte {
|
||||||
|
return []byte("")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (hasher *DummyHasher) Reset() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (hasher *DummyHasher) Size() int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (hasher *DummyHasher) BlockSize() int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
func (config *Config) NewFileHasher() hash.Hash {
|
func (config *Config) NewFileHasher() hash.Hash {
|
||||||
if config.CompressionLevel == DEFAULT_COMPRESSION_LEVEL {
|
if SkipFileHash {
|
||||||
|
return &DummyHasher {}
|
||||||
|
} else if config.CompressionLevel == DEFAULT_COMPRESSION_LEVEL {
|
||||||
hasher, _ := blake2.New(&blake2.Config{ Size: 32 })
|
hasher, _ := blake2.New(&blake2.Config{ Size: 32 })
|
||||||
return hasher
|
return hasher
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1084,7 +1084,7 @@ func (manager *SnapshotManager) RetrieveFile(snapshot *Snapshot, file *Entry, ou
|
|||||||
if alternateHash {
|
if alternateHash {
|
||||||
fileHash = "#" + fileHash
|
fileHash = "#" + fileHash
|
||||||
}
|
}
|
||||||
if strings.ToLower(fileHash) != strings.ToLower(file.Hash) {
|
if strings.ToLower(fileHash) != strings.ToLower(file.Hash) && !SkipFileHash {
|
||||||
LOG_WARN("SNAPSHOT_HASH", "File %s has mismatched hashes: %s vs %s", file.Path, file.Hash, fileHash)
|
LOG_WARN("SNAPSHOT_HASH", "File %s has mismatched hashes: %s vs %s", file.Path, file.Hash, fileHash)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user