Initialize progress printer as early as reasonable in run functions

This commit is contained in:
Michael Eischer
2025-09-14 11:30:20 +02:00
parent 6c0dccf4a5
commit b0eef4b965
5 changed files with 5 additions and 9 deletions

View File

@@ -188,14 +188,13 @@ func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOption
return errors.Fatal("--no-lock is only applicable in combination with --dry-run for forget command")
}
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, opts.DryRun && gopts.NoLock)
if err != nil {
return err
}
defer unlock()
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
var snapshots restic.Snapshots
removeSnIDs := restic.NewIDSet()

View File

@@ -49,14 +49,13 @@ func runRecover(ctx context.Context, gopts GlobalOptions, term *termstatus.Termi
return err
}
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false)
if err != nil {
return err
}
defer unlock()
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
snapshotLister, err := restic.MemorizeList(ctx, repo, restic.SnapshotFile)
if err != nil {
return err

View File

@@ -73,14 +73,13 @@ func newRebuildIndexCommand() *cobra.Command {
}
func runRebuildIndex(ctx context.Context, opts RepairIndexOptions, gopts GlobalOptions, term *termstatus.Terminal) error {
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false)
if err != nil {
return err
}
defer unlock()
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
err = repository.RepairIndex(ctx, repo, repository.RepairIndexOptions{
ReadAllPacks: opts.ReadAllPacks,
}, printer)

View File

@@ -53,14 +53,13 @@ func runRepairPacks(ctx context.Context, gopts GlobalOptions, term *termstatus.T
return errors.Fatal("no ids specified")
}
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false)
if err != nil {
return err
}
defer unlock()
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
bar := newIndexTerminalProgress(printer)
err = repo.LoadIndex(ctx, bar)
if err != nil {

View File

@@ -91,6 +91,7 @@ func (opts *RestoreOptions) AddFlags(f *pflag.FlagSet) {
func runRestore(ctx context.Context, opts RestoreOptions, gopts GlobalOptions,
term *termstatus.Terminal, args []string) error {
msg := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
excludePatternFns, err := opts.ExcludePatternOptions.CollectPatterns(Warnf)
if err != nil {
return err
@@ -146,7 +147,6 @@ func runRestore(ctx context.Context, opts RestoreOptions, gopts GlobalOptions,
return errors.Fatalf("failed to find snapshot: %v", err)
}
msg := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
bar := newIndexTerminalProgress(msg)
err = repo.LoadIndex(ctx, bar)
if err != nil {