2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-25 20:11:06 +00:00

deduplicate index progress bar setup

This commit is contained in:
Michael Eischer 2023-10-01 19:38:09 +02:00
parent 75f6bd89ed
commit b0da0f152f
16 changed files with 25 additions and 17 deletions

View File

@ -547,7 +547,7 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter
progressPrinter.V("load index files")
}
bar := newTerminalProgressMax(!gopts.Quiet && !gopts.JSON, 0, "index files loaded", term)
bar := newIndexTerminalProgress(gopts.Quiet, gopts.JSON, term)
err = repo.LoadIndex(ctx, bar)
if err != nil {

View File

@ -169,7 +169,7 @@ func runCat(ctx context.Context, gopts GlobalOptions, args []string) error {
return err
case "blob":
bar := newProgressMax(!gopts.Quiet && !gopts.JSON, 0, "index files loaded")
bar := newIndexProgress(gopts.Quiet, gopts.JSON)
err = repo.LoadIndex(ctx, bar)
if err != nil {
return err
@ -198,7 +198,7 @@ func runCat(ctx context.Context, gopts GlobalOptions, args []string) error {
return errors.Fatalf("could not find snapshot: %v\n", err)
}
bar := newProgressMax(!gopts.Quiet && !gopts.JSON, 0, "index files loaded")
bar := newIndexProgress(gopts.Quiet, gopts.JSON)
err = repo.LoadIndex(ctx, bar)
if err != nil {
return err

View File

@ -99,11 +99,11 @@ func runCopy(ctx context.Context, opts CopyOptions, gopts GlobalOptions, args []
}
debug.Log("Loading source index")
bar := newProgressMax(!gopts.Quiet && !gopts.JSON, 0, "index files loaded")
bar := newIndexProgress(gopts.Quiet, gopts.JSON)
if err := srcRepo.LoadIndex(ctx, bar); err != nil {
return err
}
bar = newProgressMax(!gopts.Quiet && !gopts.JSON, 0, "index files loaded")
bar = newIndexProgress(gopts.Quiet, gopts.JSON)
debug.Log("Loading destination index")
if err := dstRepo.LoadIndex(ctx, bar); err != nil {
return err

View File

@ -469,7 +469,7 @@ func runDebugExamine(ctx context.Context, gopts GlobalOptions, args []string) er
}
}
bar := newProgressMax(!gopts.Quiet && !gopts.JSON, 0, "index files loaded")
bar := newIndexProgress(gopts.Quiet, gopts.JSON)
err = repo.LoadIndex(ctx, bar)
if err != nil {
return err

View File

@ -363,7 +363,7 @@ func runDiff(ctx context.Context, opts DiffOptions, gopts GlobalOptions, args []
if !gopts.JSON {
Verbosef("comparing snapshot %v to %v:\n\n", sn1.ID().Str(), sn2.ID().Str())
}
bar := newProgressMax(!gopts.Quiet && !gopts.JSON, 0, "index files loaded")
bar := newIndexProgress(gopts.Quiet, gopts.JSON)
if err = repo.LoadIndex(ctx, bar); err != nil {
return err
}

View File

@ -152,7 +152,7 @@ func runDump(ctx context.Context, opts DumpOptions, gopts GlobalOptions, args []
return errors.Fatalf("failed to find snapshot: %v", err)
}
bar := newProgressMax(!gopts.Quiet && !gopts.JSON, 0, "index files loaded")
bar := newIndexProgress(gopts.Quiet, gopts.JSON)
err = repo.LoadIndex(ctx, bar)
if err != nil {
return err

View File

@ -589,7 +589,7 @@ func runFind(ctx context.Context, opts FindOptions, gopts GlobalOptions, args []
if err != nil {
return err
}
bar := newProgressMax(!gopts.Quiet && !gopts.JSON, 0, "index files loaded")
bar := newIndexProgress(gopts.Quiet, gopts.JSON)
if err = repo.LoadIndex(ctx, bar); err != nil {
return err
}

View File

@ -173,7 +173,7 @@ func runLs(ctx context.Context, opts LsOptions, gopts GlobalOptions, args []stri
return err
}
bar := newProgressMax(!gopts.Quiet && !gopts.JSON, 0, "index files loaded")
bar := newIndexProgress(gopts.Quiet, gopts.JSON)
if err = repo.LoadIndex(ctx, bar); err != nil {
return err
}

View File

@ -130,7 +130,7 @@ func runMount(ctx context.Context, opts MountOptions, gopts GlobalOptions, args
}
}
bar := newProgressMax(!gopts.Quiet && !gopts.JSON, 0, "index files loaded")
bar := newIndexProgress(gopts.Quiet, gopts.JSON)
err = repo.LoadIndex(ctx, bar)
if err != nil {
return err

View File

@ -187,7 +187,7 @@ func runPruneWithRepo(ctx context.Context, opts PruneOptions, gopts GlobalOption
Verbosef("loading indexes...\n")
// loading the index before the snapshots is ok, as we use an exclusive lock here
bar := newProgressMax(!gopts.Quiet && !gopts.JSON, 0, "index files loaded")
bar := newIndexProgress(gopts.Quiet, gopts.JSON)
err := repo.LoadIndex(ctx, bar)
if err != nil {
return err

View File

@ -58,7 +58,7 @@ func runRecover(ctx context.Context, gopts GlobalOptions) error {
}
Verbosef("load index files\n")
bar := newProgressMax(!gopts.Quiet && !gopts.JSON, 0, "index files loaded")
bar := newIndexProgress(gopts.Quiet, gopts.JSON)
if err = repo.LoadIndex(ctx, bar); err != nil {
return err
}

View File

@ -89,7 +89,7 @@ func runRepairSnapshots(ctx context.Context, gopts GlobalOptions, opts RepairOpt
return err
}
bar := newProgressMax(!gopts.Quiet && !gopts.JSON, 0, "index files loaded")
bar := newIndexProgress(gopts.Quiet, gopts.JSON)
if err := repo.LoadIndex(ctx, bar); err != nil {
return err
}

View File

@ -173,7 +173,7 @@ func runRestore(ctx context.Context, opts RestoreOptions, gopts GlobalOptions,
return errors.Fatalf("failed to find snapshot: %v", err)
}
bar := newTerminalProgressMax(!gopts.Quiet && !gopts.JSON, 0, "index files loaded", term)
bar := newIndexTerminalProgress(gopts.Quiet, gopts.JSON, term)
err = repo.LoadIndex(ctx, bar)
if err != nil {
return err

View File

@ -212,7 +212,7 @@ func runRewrite(ctx context.Context, opts RewriteOptions, gopts GlobalOptions, a
return err
}
bar := newProgressMax(!gopts.Quiet && !gopts.JSON, 0, "index files loaded")
bar := newIndexProgress(gopts.Quiet, gopts.JSON)
if err = repo.LoadIndex(ctx, bar); err != nil {
return err
}

View File

@ -98,7 +98,7 @@ func runStats(ctx context.Context, opts StatsOptions, gopts GlobalOptions, args
if err != nil {
return err
}
bar := newProgressMax(!gopts.Quiet && !gopts.JSON, 0, "index files loaded")
bar := newIndexProgress(gopts.Quiet, gopts.JSON)
if err = repo.LoadIndex(ctx, bar); err != nil {
return err
}

View File

@ -96,3 +96,11 @@ func printProgress(status string) {
_, _ = os.Stdout.Write([]byte(clear + status + carriageControl))
}
func newIndexProgress(quiet bool, json bool) *progress.Counter {
return newProgressMax(!quiet && !json, 0, "index files loaded")
}
func newIndexTerminalProgress(quiet bool, json bool, term *termstatus.Terminal) *progress.Counter {
return newTerminalProgressMax(!quiet && !json, 0, "index files loaded", term)
}