Skip to content

Commit

Permalink
Clear the attributes from last snapshot after loading to save memory
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbertchen committed Jan 28, 2018
1 parent ffe04d6 commit 7230ddb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/duplicacy_backupmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ func (manager *BackupManager) Restore(top string, revision int, inPlace bool, qu
}

remoteSnapshot := manager.SnapshotManager.DownloadSnapshot(manager.snapshotID, revision)
manager.SnapshotManager.DownloadSnapshotContents(remoteSnapshot, patterns)
manager.SnapshotManager.DownloadSnapshotContents(remoteSnapshot, patterns, true)

localSnapshot, _, _, err := CreateSnapshotFromDirectory(manager.snapshotID, top)
if err != nil {
Expand Down
28 changes: 15 additions & 13 deletions src/duplicacy_snapshotmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (manager *SnapshotManager) DownloadSequence(sequence []string) (content []b
return content
}

func (manager *SnapshotManager) DownloadSnapshotFileSequence(snapshot *Snapshot, patterns []string) bool {
func (manager *SnapshotManager) DownloadSnapshotFileSequence(snapshot *Snapshot, patterns []string, attributesNeeded bool) bool {

manager.CreateChunkDownloader()

Expand Down Expand Up @@ -304,7 +304,8 @@ func (manager *SnapshotManager) DownloadSnapshotFileSequence(snapshot *Snapshot,
return false
}

if len(patterns) != 0 && !MatchPath(entry.Path, patterns) {
// If we don't need the attributes or the file isn't included we clear the attributes to save memory
if !attributesNeeded || (len(patterns) != 0 && !MatchPath(entry.Path, patterns)) {
entry.Attributes = nil
}

Expand Down Expand Up @@ -347,9 +348,9 @@ func (manager *SnapshotManager) DownloadSnapshotSequence(snapshot *Snapshot, seq
// DownloadSnapshotContents loads all chunk sequences in a snapshot. A snapshot, when just created, only contains
// some metadata and theree sequence representing files, chunk hashes, and chunk lengths. This function must be called
// for the actual content of the snapshot to be usable.
func (manager *SnapshotManager) DownloadSnapshotContents(snapshot *Snapshot, patterns []string) bool {
func (manager *SnapshotManager) DownloadSnapshotContents(snapshot *Snapshot, patterns []string, attributesNeeded bool) bool {

manager.DownloadSnapshotFileSequence(snapshot, patterns)
manager.DownloadSnapshotFileSequence(snapshot, patterns, attributesNeeded)
manager.DownloadSnapshotSequence(snapshot, "chunks")
manager.DownloadSnapshotSequence(snapshot, "lengths")

Expand Down Expand Up @@ -553,7 +554,7 @@ func (manager *SnapshotManager) downloadLatestSnapshot(snapshotID string) (remot
}

if remote != nil {
manager.DownloadSnapshotContents(remote, nil)
manager.DownloadSnapshotContents(remote, nil, false)
}

return remote
Expand Down Expand Up @@ -679,7 +680,7 @@ func (manager *SnapshotManager) ListSnapshots(snapshotID string, revisionsToList
}

if showFiles {
manager.DownloadSnapshotFileSequence(snapshot, nil)
manager.DownloadSnapshotFileSequence(snapshot, nil, false)
}

if showFiles {
Expand Down Expand Up @@ -799,7 +800,7 @@ func (manager *SnapshotManager) CheckSnapshots(snapshotID string, revisionsToChe
}

if checkFiles {
manager.DownloadSnapshotContents(snapshot, nil)
manager.DownloadSnapshotContents(snapshot, nil, false)
manager.VerifySnapshot(snapshot)
continue
}
Expand Down Expand Up @@ -1208,7 +1209,8 @@ func (manager *SnapshotManager) PrintFile(snapshotID string, revision int, path
patterns = []string{path}
}

if !manager.DownloadSnapshotContents(snapshot, patterns) {
// If no path is specified, we're printing the snapshot so we need all attributes
if !manager.DownloadSnapshotContents(snapshot, patterns, path == "") {
return false
}

Expand Down Expand Up @@ -1268,9 +1270,9 @@ func (manager *SnapshotManager) Diff(top string, snapshotID string, revisions []

if len(filePath) > 0 {

manager.DownloadSnapshotContents(leftSnapshot, nil)
manager.DownloadSnapshotContents(leftSnapshot, nil, false)
if rightSnapshot != nil && rightSnapshot.Revision != 0 {
manager.DownloadSnapshotContents(rightSnapshot, nil)
manager.DownloadSnapshotContents(rightSnapshot, nil, false)
}

var leftFile []byte
Expand Down Expand Up @@ -1346,9 +1348,9 @@ func (manager *SnapshotManager) Diff(top string, snapshotID string, revisions []
}

// We only need to decode the 'files' sequence, not 'chunkhashes' or 'chunklengthes'
manager.DownloadSnapshotFileSequence(leftSnapshot, nil)
manager.DownloadSnapshotFileSequence(leftSnapshot, nil, false)
if rightSnapshot != nil && rightSnapshot.Revision != 0 {
manager.DownloadSnapshotFileSequence(rightSnapshot, nil)
manager.DownloadSnapshotFileSequence(rightSnapshot, nil, false)
}

maxSize := int64(9)
Expand Down Expand Up @@ -1452,7 +1454,7 @@ func (manager *SnapshotManager) ShowHistory(top string, snapshotID string, revis
sort.Ints(revisions)
for _, revision := range revisions {
snapshot := manager.DownloadSnapshot(snapshotID, revision)
manager.DownloadSnapshotFileSequence(snapshot, nil)
manager.DownloadSnapshotFileSequence(snapshot, nil, false)
file := manager.FindFile(snapshot, filePath, true)

if file != nil {
Expand Down

0 comments on commit 7230ddb

Please sign in to comment.