mirror of
https://github.com/octoleo/restic.git
synced 2024-12-24 11:55:28 +00:00
restore: pass action enum to restore progress
This commit is contained in:
parent
798256ec52
commit
ae978d60cc
@ -215,7 +215,7 @@ func (r *fileRestorer) restoreEmptyFileAt(location string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
r.progress.AddProgress(location, false, true, 0, 0)
|
r.progress.AddProgress(location, restore.ActionFileRestored, 0, 0)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,7 +337,11 @@ func (r *fileRestorer) downloadBlobs(ctx context.Context, packID restic.ID,
|
|||||||
createSize = file.size
|
createSize = file.size
|
||||||
}
|
}
|
||||||
writeErr := r.filesWriter.writeToFile(r.targetPath(file.location), blobData, offset, createSize, file.sparse)
|
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
|
return writeErr
|
||||||
}
|
}
|
||||||
err := r.sanitizeError(file, writeToFile())
|
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)
|
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
|
// TODO investigate if hardlinks have separate metadata on any supported system
|
||||||
return res.restoreNodeMetadataTo(node, path, location)
|
return res.restoreNodeMetadataTo(node, path, location)
|
||||||
}
|
}
|
||||||
@ -343,8 +343,12 @@ func (res *Restorer) RestoreTo(ctx context.Context, dst string) error {
|
|||||||
if !res.opts.DryRun {
|
if !res.opts.DryRun {
|
||||||
filerestorer.addFile(location, node.Content, int64(node.Size), matches)
|
filerestorer.addFile(location, node.Content, int64(node.Size), matches)
|
||||||
} else {
|
} else {
|
||||||
|
action := restoreui.ActionFileUpdated
|
||||||
|
if matches == nil {
|
||||||
|
action = restoreui.ActionFileRestored
|
||||||
|
}
|
||||||
// immediately mark as completed
|
// 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)
|
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 {
|
leaveDir: func(node *restic.Node, target, location string) error {
|
||||||
err := res.restoreNodeMetadataTo(node, target, location)
|
err := res.restoreNodeMetadataTo(node, target, location)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
res.opts.Progress.AddProgress(location, false, true, 0, 0)
|
res.opts.Progress.AddProgress(location, restoreui.ActionDirRestored, 0, 0)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
|
@ -88,7 +88,7 @@ func (p *Progress) AddFile(size uint64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddProgress accumulates the number of bytes written for a file
|
// 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 {
|
if p == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -108,12 +108,6 @@ func (p *Progress) AddProgress(name string, isDir bool, isNew bool, bytesWritten
|
|||||||
delete(p.progressInfoMap, name)
|
delete(p.progressInfoMap, name)
|
||||||
p.s.FilesFinished++
|
p.s.FilesFinished++
|
||||||
|
|
||||||
action := ActionFileUpdated
|
|
||||||
if isDir {
|
|
||||||
action = ActionDirRestored
|
|
||||||
} else if isNew {
|
|
||||||
action = ActionFileRestored
|
|
||||||
}
|
|
||||||
p.printer.CompleteItem(action, name, bytesTotal)
|
p.printer.CompleteItem(action, name, bytesTotal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ func TestFirstProgressOnAFile(t *testing.T) {
|
|||||||
|
|
||||||
result, items := testProgress(func(progress *Progress) bool {
|
result, items := testProgress(func(progress *Progress) bool {
|
||||||
progress.AddFile(expectedBytesTotal)
|
progress.AddFile(expectedBytesTotal)
|
||||||
progress.AddProgress("test", false, false, expectedBytesWritten, expectedBytesTotal)
|
progress.AddProgress("test", ActionFileUpdated, expectedBytesWritten, expectedBytesTotal)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
test.Equals(t, printerTrace{
|
test.Equals(t, printerTrace{
|
||||||
@ -95,9 +95,9 @@ func TestLastProgressOnAFile(t *testing.T) {
|
|||||||
|
|
||||||
result, items := testProgress(func(progress *Progress) bool {
|
result, items := testProgress(func(progress *Progress) bool {
|
||||||
progress.AddFile(fileSize)
|
progress.AddFile(fileSize)
|
||||||
progress.AddProgress("test", false, false, 30, fileSize)
|
progress.AddProgress("test", ActionFileUpdated, 30, fileSize)
|
||||||
progress.AddProgress("test", false, false, 35, fileSize)
|
progress.AddProgress("test", ActionFileUpdated, 35, fileSize)
|
||||||
progress.AddProgress("test", false, false, 35, fileSize)
|
progress.AddProgress("test", ActionFileUpdated, 35, fileSize)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
test.Equals(t, printerTrace{
|
test.Equals(t, printerTrace{
|
||||||
@ -114,9 +114,9 @@ func TestLastProgressOnLastFile(t *testing.T) {
|
|||||||
result, items := testProgress(func(progress *Progress) bool {
|
result, items := testProgress(func(progress *Progress) bool {
|
||||||
progress.AddFile(fileSize)
|
progress.AddFile(fileSize)
|
||||||
progress.AddFile(50)
|
progress.AddFile(50)
|
||||||
progress.AddProgress("test1", false, false, 50, 50)
|
progress.AddProgress("test1", ActionFileUpdated, 50, 50)
|
||||||
progress.AddProgress("test2", false, false, 50, fileSize)
|
progress.AddProgress("test2", ActionFileUpdated, 50, fileSize)
|
||||||
progress.AddProgress("test2", false, false, 50, fileSize)
|
progress.AddProgress("test2", ActionFileUpdated, 50, fileSize)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
test.Equals(t, printerTrace{
|
test.Equals(t, printerTrace{
|
||||||
@ -134,8 +134,8 @@ func TestSummaryOnSuccess(t *testing.T) {
|
|||||||
result, _ := testProgress(func(progress *Progress) bool {
|
result, _ := testProgress(func(progress *Progress) bool {
|
||||||
progress.AddFile(fileSize)
|
progress.AddFile(fileSize)
|
||||||
progress.AddFile(50)
|
progress.AddFile(50)
|
||||||
progress.AddProgress("test1", false, false, 50, 50)
|
progress.AddProgress("test1", ActionFileUpdated, 50, 50)
|
||||||
progress.AddProgress("test2", false, false, fileSize, fileSize)
|
progress.AddProgress("test2", ActionFileUpdated, fileSize, fileSize)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
test.Equals(t, printerTrace{
|
test.Equals(t, printerTrace{
|
||||||
@ -149,8 +149,8 @@ func TestSummaryOnErrors(t *testing.T) {
|
|||||||
result, _ := testProgress(func(progress *Progress) bool {
|
result, _ := testProgress(func(progress *Progress) bool {
|
||||||
progress.AddFile(fileSize)
|
progress.AddFile(fileSize)
|
||||||
progress.AddFile(50)
|
progress.AddFile(50)
|
||||||
progress.AddProgress("test1", false, false, 50, 50)
|
progress.AddProgress("test1", ActionFileUpdated, 50, 50)
|
||||||
progress.AddProgress("test2", false, false, fileSize/2, fileSize)
|
progress.AddProgress("test2", ActionFileUpdated, fileSize/2, fileSize)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
test.Equals(t, printerTrace{
|
test.Equals(t, printerTrace{
|
||||||
@ -179,8 +179,8 @@ func TestProgressTypes(t *testing.T) {
|
|||||||
_, items := testProgress(func(progress *Progress) bool {
|
_, items := testProgress(func(progress *Progress) bool {
|
||||||
progress.AddFile(fileSize)
|
progress.AddFile(fileSize)
|
||||||
progress.AddFile(0)
|
progress.AddFile(0)
|
||||||
progress.AddProgress("dir", true, false, fileSize, fileSize)
|
progress.AddProgress("dir", ActionDirRestored, fileSize, fileSize)
|
||||||
progress.AddProgress("new", false, true, 0, 0)
|
progress.AddProgress("new", ActionFileRestored, 0, 0)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
test.Equals(t, itemTrace{
|
test.Equals(t, itemTrace{
|
||||||
|
Loading…
Reference in New Issue
Block a user