mirror of
https://github.com/restic/restic.git
synced 2026-09-22 12:08:30 +00:00
internal/restorer: invert dependency direction to ui/restorer
The restorer imported ui/restorer which leaks ui logic into the restorer core. Swap the direction by letting the restorer use a ProgressReporter interface + associated constants.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package restorer
|
||||
|
||||
type ItemAction string
|
||||
|
||||
// Constants for the different CompleteItem actions.
|
||||
const (
|
||||
ActionDirRestored ItemAction = "dir restored"
|
||||
ActionFileRestored ItemAction = "file restored"
|
||||
ActionFileUpdated ItemAction = "file updated"
|
||||
ActionFileUnchanged ItemAction = "file unchanged"
|
||||
ActionOtherRestored ItemAction = "other restored"
|
||||
ActionDeleted ItemAction = "deleted"
|
||||
)
|
||||
|
||||
// ProgressReporter reports restore progress.
|
||||
type ProgressReporter interface {
|
||||
AddFile(size uint64)
|
||||
AddProgress(name string, action ItemAction, bytesWrittenPortion, bytesTotal uint64)
|
||||
AddSkippedFile(name string, size uint64)
|
||||
ReportDeletion(name string)
|
||||
}
|
||||
|
||||
type noopProgressReporter struct{}
|
||||
|
||||
var _ ProgressReporter = (*noopProgressReporter)(nil)
|
||||
|
||||
func (noopProgressReporter) AddFile(uint64) {}
|
||||
func (noopProgressReporter) AddProgress(string, ItemAction, uint64, uint64) {
|
||||
}
|
||||
func (noopProgressReporter) AddSkippedFile(string, uint64) {}
|
||||
func (noopProgressReporter) ReportDeletion(string) {}
|
||||
|
||||
func progressOrNoop(p ProgressReporter) ProgressReporter {
|
||||
if p == nil {
|
||||
return noopProgressReporter{}
|
||||
}
|
||||
return p
|
||||
}
|
||||
Reference in New Issue
Block a user