Skip to content

Commit

Permalink
Fixed incorrect stats during backup; also check in files missing from…
Browse files Browse the repository at this point in the history
… last commit
  • Loading branch information
gilbertchen committed Jul 7, 2017
1 parent ba37026 commit 2908b80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
18 changes: 7 additions & 11 deletions src/duplicacy_backupmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))

Expand Down
8 changes: 6 additions & 2 deletions src/duplicacy_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,23 @@ 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
}

var incompleteSnapshot IncompleteSnapshot

err = json.Unmarshal(description, &incompleteSnapshot)
if err != nil {
LOG_DEBUG("INCOMPLETE_PARSE", "Failed to parse incomplete snapshot: %v", err)
return nil
}

var chunkHashes []string
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))
Expand All @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 2908b80

Please sign in to comment.