mirror of
https://github.com/gilbertchen/duplicacy
synced 2025-12-06 00:03:38 +00:00
Handle zero-byte files correctly
This commit fixed 2 bugs. The first bug occurs when an incomplete backup contains a zero-byte file and no chunks. The second bug occurs when the repository contains only zero-byte files.
This commit is contained in:
@@ -301,26 +301,27 @@ func (manager *BackupManager) Backup(top string, quickMode bool, threads int, ta
|
|||||||
if compareResult == 0 {
|
if compareResult == 0 {
|
||||||
// No need to check if it is in hash mode -- in that case remote listing is nil
|
// No need to check if it is in hash mode -- in that case remote listing is nil
|
||||||
if localEntry.IsSameAs(remoteEntry) && localEntry.IsFile() {
|
if localEntry.IsSameAs(remoteEntry) && localEntry.IsFile() {
|
||||||
|
if localEntry.Size > 0 {
|
||||||
|
localEntry.Hash = remoteEntry.Hash
|
||||||
|
localEntry.StartOffset = remoteEntry.StartOffset
|
||||||
|
localEntry.EndOffset = remoteEntry.EndOffset
|
||||||
|
delta := remoteEntry.StartChunk - len(localEntryList.PreservedChunkHashes)
|
||||||
|
if lastPreservedChunk != remoteEntry.StartChunk {
|
||||||
|
lastPreservedChunk = remoteEntry.StartChunk
|
||||||
|
localEntryList.AddPreservedChunk(remoteSnapshot.ChunkHashes[lastPreservedChunk], remoteSnapshot.ChunkLengths[lastPreservedChunk])
|
||||||
|
} else {
|
||||||
|
delta++
|
||||||
|
}
|
||||||
|
|
||||||
localEntry.Hash = remoteEntry.Hash
|
for i := remoteEntry.StartChunk + 1; i <= remoteEntry.EndChunk; i++ {
|
||||||
localEntry.StartOffset = remoteEntry.StartOffset
|
localEntryList.AddPreservedChunk(remoteSnapshot.ChunkHashes[i], remoteSnapshot.ChunkLengths[i])
|
||||||
localEntry.EndOffset = remoteEntry.EndOffset
|
lastPreservedChunk = i
|
||||||
delta := remoteEntry.StartChunk - len(localEntryList.PreservedChunkHashes)
|
}
|
||||||
if lastPreservedChunk != remoteEntry.StartChunk {
|
|
||||||
lastPreservedChunk = remoteEntry.StartChunk
|
localEntry.StartChunk = remoteEntry.StartChunk - delta
|
||||||
localEntryList.AddPreservedChunk(remoteSnapshot.ChunkHashes[lastPreservedChunk], remoteSnapshot.ChunkLengths[lastPreservedChunk])
|
localEntry.EndChunk = remoteEntry.EndChunk - delta
|
||||||
} else {
|
preservedFileSize += localEntry.Size
|
||||||
delta++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := remoteEntry.StartChunk + 1; i <= remoteEntry.EndChunk; i++ {
|
|
||||||
localEntryList.AddPreservedChunk(remoteSnapshot.ChunkHashes[i], remoteSnapshot.ChunkLengths[i])
|
|
||||||
lastPreservedChunk = i
|
|
||||||
}
|
|
||||||
|
|
||||||
localEntry.StartChunk = remoteEntry.StartChunk - delta
|
|
||||||
localEntry.EndChunk = remoteEntry.EndChunk - delta
|
|
||||||
preservedFileSize += localEntry.Size
|
|
||||||
} else {
|
} else {
|
||||||
totalModifiedFileSize += localEntry.Size
|
totalModifiedFileSize += localEntry.Size
|
||||||
if localEntry.Size > 0 {
|
if localEntry.Size > 0 {
|
||||||
@@ -1047,24 +1048,24 @@ func (manager *BackupManager) UploadSnapshot(chunkOperator *ChunkOperator, top s
|
|||||||
|
|
||||||
uploadEntryInfoFunc := func(entry *Entry) error {
|
uploadEntryInfoFunc := func(entry *Entry) error {
|
||||||
|
|
||||||
delta := entry.StartChunk - len(chunkHashes) + 1
|
if entry.IsFile() && entry.Size > 0 {
|
||||||
if entry.StartChunk != lastChunk {
|
delta := entry.StartChunk - len(chunkHashes) + 1
|
||||||
chunkHashes = append(chunkHashes, snapshot.ChunkHashes[entry.StartChunk])
|
if entry.StartChunk != lastChunk {
|
||||||
chunkLengths = append(chunkLengths, snapshot.ChunkLengths[entry.StartChunk])
|
chunkHashes = append(chunkHashes, snapshot.ChunkHashes[entry.StartChunk])
|
||||||
delta--
|
chunkLengths = append(chunkLengths, snapshot.ChunkLengths[entry.StartChunk])
|
||||||
}
|
delta--
|
||||||
|
}
|
||||||
|
|
||||||
for i := entry.StartChunk + 1; i <= entry.EndChunk; i++ {
|
for i := entry.StartChunk + 1; i <= entry.EndChunk; i++ {
|
||||||
chunkHashes = append(chunkHashes, snapshot.ChunkHashes[i])
|
chunkHashes = append(chunkHashes, snapshot.ChunkHashes[i])
|
||||||
chunkLengths = append(chunkLengths, snapshot.ChunkLengths[i])
|
chunkLengths = append(chunkLengths, snapshot.ChunkLengths[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
lastChunk = entry.EndChunk
|
lastChunk = entry.EndChunk
|
||||||
entry.StartChunk -= delta
|
entry.StartChunk -= delta
|
||||||
entry.EndChunk -= delta
|
entry.EndChunk -= delta
|
||||||
|
|
||||||
if entry.IsFile() {
|
delta = entry.EndChunk - entry.StartChunk
|
||||||
delta := entry.EndChunk - entry.StartChunk
|
|
||||||
entry.StartChunk -= lastEndChunk
|
entry.StartChunk -= lastEndChunk
|
||||||
lastEndChunk = entry.EndChunk
|
lastEndChunk = entry.EndChunk
|
||||||
entry.EndChunk = delta
|
entry.EndChunk = delta
|
||||||
|
|||||||
Reference in New Issue
Block a user