mirror of
https://github.com/gilbertchen/duplicacy
synced 2025-12-10 13:23:17 +00:00
Skip chunks already verified in previous runs for check -chunks.
This is done by storing the list of verified chunks in a file `.duplicacy/cache/<storage>/verified_chunks`.
This commit is contained in:
@@ -1017,7 +1017,48 @@ func (manager *SnapshotManager) CheckSnapshots(snapshotID string, revisionsToChe
|
|||||||
manager.ShowStatistics(snapshotMap, chunkSizeMap, chunkUniqueMap, chunkSnapshotMap)
|
manager.ShowStatistics(snapshotMap, chunkSizeMap, chunkUniqueMap, chunkSnapshotMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
if checkChunks && !checkFiles {
|
// Don't verify chunks with -files
|
||||||
|
if !checkChunks || checkFiles {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// This contains chunks that have been verifed in previous checks and is loaded from
|
||||||
|
// .duplicacy/cache/storage/verified_chunks. Note that it contains the chunk ids not chunk
|
||||||
|
// hashes.
|
||||||
|
verifiedChunks := make(map[string]int64)
|
||||||
|
verifiedChunksFile := "verified_chunks"
|
||||||
|
|
||||||
|
manager.fileChunk.Reset(false)
|
||||||
|
err = manager.snapshotCache.DownloadFile(0, verifiedChunksFile, manager.fileChunk)
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
LOG_WARN("SNAPSHOT_VERIFY", "Failed to load the file containing verified chunks: %v", err)
|
||||||
|
} else {
|
||||||
|
err = json.Unmarshal(manager.fileChunk.GetBytes(), &verifiedChunks)
|
||||||
|
if err != nil {
|
||||||
|
LOG_WARN("SNAPSHOT_VERIFY", "Failed to parse the file containing verified chunks: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
numberOfVerifiedChunks := len(verifiedChunks)
|
||||||
|
|
||||||
|
saveVerifiedChunks := func() {
|
||||||
|
if len(verifiedChunks) > numberOfVerifiedChunks {
|
||||||
|
var description []byte
|
||||||
|
description, err = json.Marshal(verifiedChunks)
|
||||||
|
if err != nil {
|
||||||
|
LOG_WARN("SNAPSHOT_VERIFY", "Failed to create a json file for the set of verified chunks: %v", err)
|
||||||
|
} else {
|
||||||
|
err = manager.snapshotCache.UploadFile(0, verifiedChunksFile, description)
|
||||||
|
if err != nil {
|
||||||
|
LOG_WARN("SNAPSHOT_VERIFY", "Failed to save the verified chunks file: %v", err)
|
||||||
|
} else {
|
||||||
|
LOG_INFO("SNAPSHOT_VERIFY", "Added %d chunks to the list of verified chunks", len(verifiedChunks) - numberOfVerifiedChunks)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
defer saveVerifiedChunks()
|
||||||
|
RunAtError = saveVerifiedChunks
|
||||||
|
|
||||||
manager.chunkDownloader.snapshotCache = nil
|
manager.chunkDownloader.snapshotCache = nil
|
||||||
LOG_INFO("SNAPSHOT_VERIFY", "Verifying %d chunks", len(*allChunkHashes))
|
LOG_INFO("SNAPSHOT_VERIFY", "Verifying %d chunks", len(*allChunkHashes))
|
||||||
|
|
||||||
@@ -1028,7 +1069,15 @@ func (manager *SnapshotManager) CheckSnapshots(snapshotID string, revisionsToChe
|
|||||||
// some metadata chunks so the index doesn't start with 0.
|
// some metadata chunks so the index doesn't start with 0.
|
||||||
chunkIndex := -1
|
chunkIndex := -1
|
||||||
|
|
||||||
|
skippedChunks := 0
|
||||||
for chunkHash := range *allChunkHashes {
|
for chunkHash := range *allChunkHashes {
|
||||||
|
if len(verifiedChunks) > 0 {
|
||||||
|
chunkID := manager.config.GetChunkIDFromHash(chunkHash)
|
||||||
|
if _, found := verifiedChunks[chunkID]; found {
|
||||||
|
skippedChunks++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
chunkHashes = append(chunkHashes, chunkHash)
|
chunkHashes = append(chunkHashes, chunkHash)
|
||||||
if chunkIndex == -1 {
|
if chunkIndex == -1 {
|
||||||
chunkIndex = manager.chunkDownloader.AddChunk(chunkHash)
|
chunkIndex = manager.chunkDownloader.AddChunk(chunkHash)
|
||||||
@@ -1037,13 +1086,19 @@ func (manager *SnapshotManager) CheckSnapshots(snapshotID string, revisionsToChe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if skippedChunks > 0 {
|
||||||
|
LOG_INFO("SNAPSHOT_VERIFY", "Skipped %d chunks that have already been verified before", skippedChunks)
|
||||||
|
}
|
||||||
|
|
||||||
var downloadedChunkSize int64
|
var downloadedChunkSize int64
|
||||||
totalChunks := len(*allChunkHashes)
|
totalChunks := len(chunkHashes)
|
||||||
for i := 0; i < totalChunks; i++ {
|
for i := 0; i < totalChunks; i++ {
|
||||||
chunk := manager.chunkDownloader.WaitForChunk(i + chunkIndex)
|
chunk := manager.chunkDownloader.WaitForChunk(i + chunkIndex)
|
||||||
|
chunkID := manager.config.GetChunkIDFromHash(chunkHashes[i])
|
||||||
if chunk.isBroken {
|
if chunk.isBroken {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
verifiedChunks[chunkID] = startTime.Unix()
|
||||||
downloadedChunkSize += int64(chunk.GetLength())
|
downloadedChunkSize += int64(chunk.GetLength())
|
||||||
|
|
||||||
elapsedTime := time.Now().Sub(startTime).Seconds()
|
elapsedTime := time.Now().Sub(startTime).Seconds()
|
||||||
@@ -1051,15 +1106,13 @@ func (manager *SnapshotManager) CheckSnapshots(snapshotID string, revisionsToChe
|
|||||||
remainingTime := int64(float64(totalChunks - i - 1) / float64(i + 1) * elapsedTime)
|
remainingTime := int64(float64(totalChunks - i - 1) / float64(i + 1) * elapsedTime)
|
||||||
percentage := float64(i + 1) / float64(totalChunks) * 100.0
|
percentage := float64(i + 1) / float64(totalChunks) * 100.0
|
||||||
LOG_INFO("VERIFY_PROGRESS", "Verified chunk %s (%d/%d), %sB/s %s %.1f%%",
|
LOG_INFO("VERIFY_PROGRESS", "Verified chunk %s (%d/%d), %sB/s %s %.1f%%",
|
||||||
manager.config.GetChunkIDFromHash(chunkHashes[i]), i + 1, totalChunks,
|
chunkID, i + 1, totalChunks, PrettySize(speed), PrettyTime(remainingTime), percentage)
|
||||||
PrettySize(speed), PrettyTime(remainingTime), percentage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if manager.chunkDownloader.NumberOfFailedChunks > 0 {
|
if manager.chunkDownloader.NumberOfFailedChunks > 0 {
|
||||||
LOG_ERROR("SNAPSHOT_VERIFY", "%d out of %d chunks are corrupted", manager.chunkDownloader.NumberOfFailedChunks, totalChunks)
|
LOG_ERROR("SNAPSHOT_VERIFY", "%d out of %d chunks are corrupted", manager.chunkDownloader.NumberOfFailedChunks, len(*allChunkHashes))
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("SNAPSHOT_VERIFY", "All %d chunks have been successfully verified", totalChunks)
|
LOG_INFO("SNAPSHOT_VERIFY", "All %d chunks have been successfully verified", len(*allChunkHashes))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user