From 2908b807b95fb8f1272d2ddab26c9ecbcc142f1d Mon Sep 17 00:00:00 2001 From: Gilbert Chen Date: Thu, 6 Jul 2017 23:12:22 -0400 Subject: [PATCH] Fixed incorrect stats during backup; also check in files missing from last commit --- src/duplicacy_backupmanager.go | 18 +++++++----------- src/duplicacy_snapshot.go | 8 ++++++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/duplicacy_backupmanager.go b/src/duplicacy_backupmanager.go index 0385e99..701e4c7 100644 --- a/src/duplicacy_backupmanager.go +++ b/src/duplicacy_backupmanager.go @@ -259,11 +259,10 @@ func (manager *BackupManager) Backup(top string, quickMode bool, threads int, ta } - var numberOfNewFileChunks int // number of new file chunks + var numberOfNewFileChunks int64 // number of new file chunks var totalUploadedFileChunkLength int64 // total length of uploaded file chunks var totalUploadedFileChunkBytes int64 // how many actual bytes have been uploaded - var numberOfNewSnapshotChunks int // number of new snapshot chunks var totalUploadedSnapshotChunkLength int64 // size of uploaded snapshot chunks var totalUploadedSnapshotChunkBytes int64 // how many actual bytes have been uploaded @@ -447,16 +446,16 @@ func (manager *BackupManager) Backup(top string, quickMode bool, threads int, ta LOG_DEBUG("CHUNK_CACHE", "Skipped chunk %s in cache", chunk.GetID()) } else { if uploadSize > 0 { - numberOfNewFileChunks++ - totalUploadedFileChunkLength += int64(chunkSize) - totalUploadedFileChunkBytes += int64(uploadSize) + atomic.AddInt64(&numberOfNewFileChunks, 1) + atomic.AddInt64(&totalUploadedFileChunkLength, int64(chunkSize)) + atomic.AddInt64(&totalUploadedFileChunkBytes, int64(uploadSize)) action = "Uploaded" } else { LOG_DEBUG("CHUNK_EXIST", "Skipped chunk %s in the storage", chunk.GetID()) } } - uploadedModifiedFileSize += int64(chunkSize) + uploadedModifiedFileSize := atomic.AddInt64(&uploadedModifiedFileSize, int64(chunkSize)) if IsTracing() || showStatistics { now := time.Now().Unix() @@ -527,10 +526,7 @@ func (manager *BackupManager) Backup(top string, quickMode bool, threads int, ta // This function is called when a new file is needed entry := fileReader.CurrentEntry entry.Hash = hash - if entry.Size != fileSize { - totalModifiedFileSize += fileSize - entry.Size - entry.Size = fileSize - } + entry.Size = fileSize uploadedEntries = append(uploadedEntries, entry) if !showStatistics || IsTracing() || RunInBackground { @@ -659,7 +655,7 @@ func (manager *BackupManager) Backup(top string, quickMode bool, threads int, ta LOG_INFO("BACKUP_STATS", "All chunks: %d total, %s bytes; %d new, %s bytes, %s bytes uploaded", len(localSnapshot.ChunkHashes) + totalSnapshotChunks, PrettyNumber(totalFileChunkLength + totalSnapshotChunkLength), - numberOfNewFileChunks + numberOfNewSnapshotChunks, + int(numberOfNewFileChunks) + numberOfNewSnapshotChunks, PrettyNumber(totalUploadedFileChunkLength + totalUploadedSnapshotChunkLength), PrettyNumber(totalUploadedFileChunkBytes + totalUploadedSnapshotChunkBytes)) diff --git a/src/duplicacy_snapshot.go b/src/duplicacy_snapshot.go index f8c758c..27e72e0 100644 --- a/src/duplicacy_snapshot.go +++ b/src/duplicacy_snapshot.go @@ -149,6 +149,7 @@ func LoadIncompleteSnapshot() (snapshot *Snapshot) { snapshotFile := path.Join(GetDuplicacyPreferencePath(), "incomplete") description, err := ioutil.ReadFile(snapshotFile) if err != nil { + LOG_DEBUG("INCOMPLETE_LOCATE", "Failed to locate incomplete snapshot: %v", err) return nil } @@ -156,6 +157,7 @@ func LoadIncompleteSnapshot() (snapshot *Snapshot) { err = json.Unmarshal(description, &incompleteSnapshot) if err != nil { + LOG_DEBUG("INCOMPLETE_PARSE", "Failed to parse incomplete snapshot: %v", err) return nil } @@ -163,6 +165,7 @@ func LoadIncompleteSnapshot() (snapshot *Snapshot) { for _, chunkHash := range incompleteSnapshot.ChunkHashes { hash, err := hex.DecodeString(chunkHash) if err != nil { + LOG_DEBUG("INCOMPLETE_DECODE", "Failed to decode incomplete snapshot: %v", err) return nil } chunkHashes = append(chunkHashes, string(hash)) @@ -181,7 +184,8 @@ func LoadIncompleteSnapshot() (snapshot *Snapshot) { func SaveIncompleteSnapshot(snapshot *Snapshot) { var files []*Entry for _, file := range snapshot.Files { - if file.EndChunk >= 0 { + // All unprocessed files will have a size of -1 + if file.Size >= 0 { file.Attributes = nil files = append(files, file) } else { @@ -199,7 +203,7 @@ func SaveIncompleteSnapshot(snapshot *Snapshot) { ChunkLengths: snapshot.ChunkLengths, } - description, err := json.Marshal(incompleteSnapshot) + description, err := json.MarshalIndent(incompleteSnapshot, "", " ") if err != nil { LOG_WARN("INCOMPLETE_ENCODE", "Failed to encode the incomplete snapshot: %v", err) return