2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 14:56:29 +00:00

ui: move SetDryRun to ProgressReporter

This commit is contained in:
Michael Eischer 2021-08-18 13:03:08 +02:00
parent 77b129ec74
commit d62bfed65d
4 changed files with 13 additions and 19 deletions

View File

@ -537,7 +537,7 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, term *termstatus.Termina
if opts.DryRun {
repo.SetDryRun()
progressPrinter.SetDryRun()
progressReporter.SetDryRun()
}
// use the terminal for stdout/stderr

View File

@ -17,7 +17,6 @@ type Backup struct {
*StdioWrapper
term *termstatus.Terminal
dry bool // true if writes are faked
}
// NewBackup returns a new backup progress reporter.
@ -165,14 +164,14 @@ func (b *Backup) Reset() {
}
// Finish prints the finishing messages.
func (b *Backup) Finish(snapshotID restic.ID, start time.Time, summary *Summary) {
func (b *Backup) Finish(snapshotID restic.ID, start time.Time, summary *Summary, dryRun bool) {
b.P("\n")
b.P("Files: %5d new, %5d changed, %5d unmodified\n", summary.Files.New, summary.Files.Changed, summary.Files.Unchanged)
b.P("Dirs: %5d new, %5d changed, %5d unmodified\n", summary.Dirs.New, summary.Dirs.Changed, summary.Dirs.Unchanged)
b.V("Data Blobs: %5d new\n", summary.ItemStats.DataBlobs)
b.V("Tree Blobs: %5d new\n", summary.ItemStats.TreeBlobs)
verb := "Added"
if b.dry {
if dryRun {
verb = "Would add"
}
b.P("%s to the repo: %-5s\n", verb, formatBytes(summary.ItemStats.DataSize+summary.ItemStats.TreeSize))
@ -183,7 +182,3 @@ func (b *Backup) Finish(snapshotID restic.ID, start time.Time, summary *Summary)
formatDuration(time.Since(start)),
)
}
func (b *Backup) SetDryRun() {
b.dry = true
}

View File

@ -20,7 +20,6 @@ type Backup struct {
term *termstatus.Terminal
v uint
dry bool
}
// NewBackup returns a new backup progress reporter.
@ -169,7 +168,7 @@ func (b *Backup) ReportTotal(item string, start time.Time, s archiver.ScanStats)
}
// Finish prints the finishing messages.
func (b *Backup) Finish(snapshotID restic.ID, start time.Time, summary *ui.Summary) {
func (b *Backup) Finish(snapshotID restic.ID, start time.Time, summary *ui.Summary, dryRun bool) {
b.print(summaryOutput{
MessageType: "summary",
FilesNew: summary.Files.New,
@ -185,7 +184,7 @@ func (b *Backup) Finish(snapshotID restic.ID, start time.Time, summary *ui.Summa
TotalBytesProcessed: summary.ProcessedBytes,
TotalDuration: time.Since(start).Seconds(),
SnapshotID: snapshotID.Str(),
DryRun: b.dry,
DryRun: dryRun,
})
}
@ -193,11 +192,6 @@ func (b *Backup) Finish(snapshotID restic.ID, start time.Time, summary *ui.Summa
func (b *Backup) Reset() {
}
// SetDryRun marks the backup as a "dry run".
func (b *Backup) SetDryRun() {
b.dry = true
}
type statusUpdate struct {
MessageType string `json:"message_type"` // "status"
SecondsElapsed uint64 `json:"seconds_elapsed,omitempty"`

View File

@ -18,9 +18,8 @@ type ProgressPrinter interface {
ScannerError(item string, fi os.FileInfo, err error) error
CompleteItem(messageType string, item string, previous, current *restic.Node, s archiver.ItemStats, d time.Duration)
ReportTotal(item string, start time.Time, s archiver.ScanStats)
Finish(snapshotID restic.ID, start time.Time, summary *Summary)
Finish(snapshotID restic.ID, start time.Time, summary *Summary, dryRun bool)
Reset()
SetDryRun()
// ui.StdioWrapper
Stdout() io.WriteCloser
@ -69,6 +68,7 @@ type Progress struct {
MinUpdatePause time.Duration
start time.Time
dry bool
totalBytes uint64
@ -310,7 +310,7 @@ func (p *Progress) ReportTotal(item string, s archiver.ScanStats) {
func (p *Progress) Finish(snapshotID restic.ID) {
// wait for the status update goroutine to shut down
<-p.closed
p.printer.Finish(snapshotID, p.start, p.summary)
p.printer.Finish(snapshotID, p.start, p.summary, p.dry)
}
// SetMinUpdatePause sets b.MinUpdatePause. It satisfies the
@ -318,3 +318,8 @@ func (p *Progress) Finish(snapshotID restic.ID) {
func (p *Progress) SetMinUpdatePause(d time.Duration) {
p.MinUpdatePause = d
}
// SetDryRun marks the backup as a "dry run".
func (p *Progress) SetDryRun() {
p.dry = true
}