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:
Michael Eischer
2026-06-20 17:49:20 +02:00
parent 5cd39d01c1
commit 2f31cde517
12 changed files with 189 additions and 116 deletions
+38
View File
@@ -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
}