mirror of
https://github.com/restic/restic.git
synced 2026-06-21 08:04:18 +00:00
2f31cde517
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.
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
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
|
|
}
|