mirror of
https://github.com/jkl1337/duplicacy.git
synced 2026-01-02 11:44:45 -06:00
Don't download a fossil directly; resurrect it and download the chunk instead
This commit is contained in:
@@ -298,35 +298,46 @@ func (downloader *ChunkDownloader) Download(threadIndex int, task ChunkDownloadT
|
|||||||
// will be set up before the encryption
|
// will be set up before the encryption
|
||||||
chunk.Reset(false)
|
chunk.Reset(false)
|
||||||
|
|
||||||
// Find the chunk by ID first.
|
const MaxDownloadAttempts = 3
|
||||||
chunkPath, exist, _, err := downloader.storage.FindChunk(threadIndex, chunkID, false)
|
for downloadAttempt := 0; ; downloadAttempt++ {
|
||||||
if err != nil {
|
|
||||||
LOG_ERROR("DOWNLOAD_CHUNK", "Failed to find the chunk %s: %v", chunkID, err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if !exist {
|
// Find the chunk by ID first.
|
||||||
// No chunk is found. Have to find it in the fossil pool again.
|
chunkPath, exist, _, err := downloader.storage.FindChunk(threadIndex, chunkID, false)
|
||||||
chunkPath, exist, _, err = downloader.storage.FindChunk(threadIndex, chunkID, true)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LOG_ERROR("DOWNLOAD_CHUNK", "Failed to find the chunk %s: %v", chunkID, err)
|
LOG_ERROR("DOWNLOAD_CHUNK", "Failed to find the chunk %s: %v", chunkID, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exist {
|
if !exist {
|
||||||
// A chunk is not found. This is a serious error and hopefully it will never happen.
|
// No chunk is found. Have to find it in the fossil pool again.
|
||||||
|
fossilPath, exist, _, err := downloader.storage.FindChunk(threadIndex, chunkID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LOG_FATAL("DOWNLOAD_CHUNK", "Chunk %s can't be found: %v", chunkID, err)
|
LOG_ERROR("DOWNLOAD_CHUNK", "Failed to find the chunk %s: %v", chunkID, err)
|
||||||
} else {
|
return false
|
||||||
LOG_FATAL("DOWNLOAD_CHUNK", "Chunk %s can't be found", chunkID)
|
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
|
||||||
LOG_DEBUG("CHUNK_FOSSIL", "Chunk %s has been marked as a fossil", chunkID)
|
|
||||||
}
|
|
||||||
|
|
||||||
const MaxDownloadAttempts = 3
|
if !exist {
|
||||||
for downloadAttempt := 0; ; downloadAttempt++ {
|
// A chunk is not found. This is a serious error and hopefully it will never happen.
|
||||||
|
if err != nil {
|
||||||
|
LOG_FATAL("DOWNLOAD_CHUNK", "Chunk %s can't be found: %v", chunkID, err)
|
||||||
|
} else {
|
||||||
|
LOG_FATAL("DOWNLOAD_CHUNK", "Chunk %s can't be found", chunkID)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// We can't download the fossil directly. We have to turn it back into a regular chunk and try
|
||||||
|
// downloading again.
|
||||||
|
err = downloader.storage.MoveFile(threadIndex, fossilPath, chunkPath)
|
||||||
|
if err != nil {
|
||||||
|
LOG_FATAL("DOWNLOAD_CHUNK", "Failed to resurrect chunk %s: %v", chunkID, err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_WARN("DOWNLOAD_RESURRECT", "Fossil %s has been resurrected", chunkID)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
err = downloader.storage.DownloadFile(threadIndex, chunkPath, chunk)
|
err = downloader.storage.DownloadFile(threadIndex, chunkPath, chunk)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == io.ErrUnexpectedEOF && downloadAttempt < MaxDownloadAttempts {
|
if err == io.ErrUnexpectedEOF && downloadAttempt < MaxDownloadAttempts {
|
||||||
@@ -368,7 +379,7 @@ func (downloader *ChunkDownloader) Download(threadIndex int, task ChunkDownloadT
|
|||||||
|
|
||||||
if len(cachedPath) > 0 {
|
if len(cachedPath) > 0 {
|
||||||
// Save a copy to the local snapshot cache
|
// Save a copy to the local snapshot cache
|
||||||
err = downloader.snapshotCache.UploadFile(threadIndex, cachedPath, chunk.GetBytes())
|
err := downloader.snapshotCache.UploadFile(threadIndex, cachedPath, chunk.GetBytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LOG_WARN("DOWNLOAD_CACHE", "Failed to add the chunk %s to the snapshot cache: %v", chunkID, err)
|
LOG_WARN("DOWNLOAD_CACHE", "Failed to add the chunk %s to the snapshot cache: %v", chunkID, err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user