forked from TrueCloudLab/restic
restore: pass action enum to restore progress
This commit is contained in:
parent
798256ec52
commit
ae978d60cc
4 changed files with 28 additions and 26 deletions
|
@ -215,7 +215,7 @@ func (r *fileRestorer) restoreEmptyFileAt(location string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
r.progress.AddProgress(location, false, true, 0, 0)
|
||||
r.progress.AddProgress(location, restore.ActionFileRestored, 0, 0)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -337,7 +337,11 @@ func (r *fileRestorer) downloadBlobs(ctx context.Context, packID restic.ID,
|
|||
createSize = file.size
|
||||
}
|
||||
writeErr := r.filesWriter.writeToFile(r.targetPath(file.location), blobData, offset, createSize, file.sparse)
|
||||
r.progress.AddProgress(file.location, false, file.state == nil, uint64(len(blobData)), uint64(file.size))
|
||||
action := restore.ActionFileUpdated
|
||||
if file.state == nil {
|
||||
action = restore.ActionFileRestored
|
||||
}
|
||||
r.progress.AddProgress(file.location, action, uint64(len(blobData)), uint64(file.size))
|
||||
return writeErr
|
||||
}
|
||||
err := r.sanitizeError(file, writeToFile())
|
||||
|
|
|
@ -234,7 +234,7 @@ func (res *Restorer) restoreNodeTo(ctx context.Context, node *restic.Node, targe
|
|||
}
|
||||
}
|
||||
|
||||
res.opts.Progress.AddProgress(location, false, true, 0, 0)
|
||||
res.opts.Progress.AddProgress(location, restoreui.ActionFileRestored, 0, 0)
|
||||
return res.restoreNodeMetadataTo(node, target, location)
|
||||
}
|
||||
|
||||
|
@ -261,7 +261,7 @@ func (res *Restorer) restoreHardlinkAt(node *restic.Node, target, path, location
|
|||
}
|
||||
}
|
||||
|
||||
res.opts.Progress.AddProgress(location, false, true, 0, 0)
|
||||
res.opts.Progress.AddProgress(location, restoreui.ActionFileRestored, 0, 0)
|
||||
// TODO investigate if hardlinks have separate metadata on any supported system
|
||||
return res.restoreNodeMetadataTo(node, path, location)
|
||||
}
|
||||
|
@ -343,8 +343,12 @@ func (res *Restorer) RestoreTo(ctx context.Context, dst string) error {
|
|||
if !res.opts.DryRun {
|
||||
filerestorer.addFile(location, node.Content, int64(node.Size), matches)
|
||||
} else {
|
||||
action := restoreui.ActionFileUpdated
|
||||
if matches == nil {
|
||||
action = restoreui.ActionFileRestored
|
||||
}
|
||||
// immediately mark as completed
|
||||
res.opts.Progress.AddProgress(location, false, matches == nil, node.Size, node.Size)
|
||||
res.opts.Progress.AddProgress(location, action, node.Size, node.Size)
|
||||
}
|
||||
}
|
||||
res.trackFile(location, updateMetadataOnly)
|
||||
|
@ -393,7 +397,7 @@ func (res *Restorer) RestoreTo(ctx context.Context, dst string) error {
|
|||
leaveDir: func(node *restic.Node, target, location string) error {
|
||||
err := res.restoreNodeMetadataTo(node, target, location)
|
||||
if err == nil {
|
||||
res.opts.Progress.AddProgress(location, false, true, 0, 0)
|
||||
res.opts.Progress.AddProgress(location, restoreui.ActionDirRestored, 0, 0)
|
||||
}
|
||||
return err
|
||||
},
|
||||
|
|
|
@ -88,7 +88,7 @@ func (p *Progress) AddFile(size uint64) {
|
|||
}
|
||||
|
||||
// AddProgress accumulates the number of bytes written for a file
|
||||
func (p *Progress) AddProgress(name string, isDir bool, isNew bool, bytesWrittenPortion uint64, bytesTotal uint64) {
|
||||
func (p *Progress) AddProgress(name string, action ItemAction, bytesWrittenPortion uint64, bytesTotal uint64) {
|
||||
if p == nil {
|
||||
return
|
||||
}
|
||||
|
@ -108,12 +108,6 @@ func (p *Progress) AddProgress(name string, isDir bool, isNew bool, bytesWritten
|
|||
delete(p.progressInfoMap, name)
|
||||
p.s.FilesFinished++
|
||||
|
||||
action := ActionFileUpdated
|
||||
if isDir {
|
||||
action = ActionDirRestored
|
||||
} else if isNew {
|
||||
action = ActionFileRestored
|
||||
}
|
||||
p.printer.CompleteItem(action, name, bytesTotal)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ func TestFirstProgressOnAFile(t *testing.T) {
|
|||
|
||||
result, items := testProgress(func(progress *Progress) bool {
|
||||
progress.AddFile(expectedBytesTotal)
|
||||
progress.AddProgress("test", false, false, expectedBytesWritten, expectedBytesTotal)
|
||||
progress.AddProgress("test", ActionFileUpdated, expectedBytesWritten, expectedBytesTotal)
|
||||
return false
|
||||
})
|
||||
test.Equals(t, printerTrace{
|
||||
|
@ -95,9 +95,9 @@ func TestLastProgressOnAFile(t *testing.T) {
|
|||
|
||||
result, items := testProgress(func(progress *Progress) bool {
|
||||
progress.AddFile(fileSize)
|
||||
progress.AddProgress("test", false, false, 30, fileSize)
|
||||
progress.AddProgress("test", false, false, 35, fileSize)
|
||||
progress.AddProgress("test", false, false, 35, fileSize)
|
||||
progress.AddProgress("test", ActionFileUpdated, 30, fileSize)
|
||||
progress.AddProgress("test", ActionFileUpdated, 35, fileSize)
|
||||
progress.AddProgress("test", ActionFileUpdated, 35, fileSize)
|
||||
return false
|
||||
})
|
||||
test.Equals(t, printerTrace{
|
||||
|
@ -114,9 +114,9 @@ func TestLastProgressOnLastFile(t *testing.T) {
|
|||
result, items := testProgress(func(progress *Progress) bool {
|
||||
progress.AddFile(fileSize)
|
||||
progress.AddFile(50)
|
||||
progress.AddProgress("test1", false, false, 50, 50)
|
||||
progress.AddProgress("test2", false, false, 50, fileSize)
|
||||
progress.AddProgress("test2", false, false, 50, fileSize)
|
||||
progress.AddProgress("test1", ActionFileUpdated, 50, 50)
|
||||
progress.AddProgress("test2", ActionFileUpdated, 50, fileSize)
|
||||
progress.AddProgress("test2", ActionFileUpdated, 50, fileSize)
|
||||
return false
|
||||
})
|
||||
test.Equals(t, printerTrace{
|
||||
|
@ -134,8 +134,8 @@ func TestSummaryOnSuccess(t *testing.T) {
|
|||
result, _ := testProgress(func(progress *Progress) bool {
|
||||
progress.AddFile(fileSize)
|
||||
progress.AddFile(50)
|
||||
progress.AddProgress("test1", false, false, 50, 50)
|
||||
progress.AddProgress("test2", false, false, fileSize, fileSize)
|
||||
progress.AddProgress("test1", ActionFileUpdated, 50, 50)
|
||||
progress.AddProgress("test2", ActionFileUpdated, fileSize, fileSize)
|
||||
return true
|
||||
})
|
||||
test.Equals(t, printerTrace{
|
||||
|
@ -149,8 +149,8 @@ func TestSummaryOnErrors(t *testing.T) {
|
|||
result, _ := testProgress(func(progress *Progress) bool {
|
||||
progress.AddFile(fileSize)
|
||||
progress.AddFile(50)
|
||||
progress.AddProgress("test1", false, false, 50, 50)
|
||||
progress.AddProgress("test2", false, false, fileSize/2, fileSize)
|
||||
progress.AddProgress("test1", ActionFileUpdated, 50, 50)
|
||||
progress.AddProgress("test2", ActionFileUpdated, fileSize/2, fileSize)
|
||||
return true
|
||||
})
|
||||
test.Equals(t, printerTrace{
|
||||
|
@ -179,8 +179,8 @@ func TestProgressTypes(t *testing.T) {
|
|||
_, items := testProgress(func(progress *Progress) bool {
|
||||
progress.AddFile(fileSize)
|
||||
progress.AddFile(0)
|
||||
progress.AddProgress("dir", true, false, fileSize, fileSize)
|
||||
progress.AddProgress("new", false, true, 0, 0)
|
||||
progress.AddProgress("dir", ActionDirRestored, fileSize, fileSize)
|
||||
progress.AddProgress("new", ActionFileRestored, 0, 0)
|
||||
return true
|
||||
})
|
||||
test.Equals(t, itemTrace{
|
||||
|
|
Loading…
Reference in a new issue