diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index 108504429..6b694a2bc 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -511,7 +511,7 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter msg.P("open repository") } - ctx, repo, unlock, err := openWithAppendLock(ctx, gopts, opts.DryRun) + ctx, repo, unlock, err := openWithAppendLock(ctx, gopts, opts.DryRun, msg) if err != nil { return err } diff --git a/cmd/restic/cmd_cat.go b/cmd/restic/cmd_cat.go index 099cae6a9..44049c86a 100644 --- a/cmd/restic/cmd_cat.go +++ b/cmd/restic/cmd_cat.go @@ -73,7 +73,7 @@ func runCat(ctx context.Context, gopts GlobalOptions, args []string, term *terms return err } - ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock) + ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer) if err != nil { return err } diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go index fa8e864d9..d659af67a 100644 --- a/cmd/restic/cmd_check.go +++ b/cmd/restic/cmd_check.go @@ -239,7 +239,7 @@ func runCheck(ctx context.Context, opts CheckOptions, gopts GlobalOptions, args if !gopts.NoLock { printer.P("create exclusive lock for repository\n") } - ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, gopts.NoLock) + ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, gopts.NoLock, printer) if err != nil { return summary, err } diff --git a/cmd/restic/cmd_copy.go b/cmd/restic/cmd_copy.go index 1467a9982..a90170056 100644 --- a/cmd/restic/cmd_copy.go +++ b/cmd/restic/cmd_copy.go @@ -81,13 +81,13 @@ func runCopy(ctx context.Context, opts CopyOptions, gopts GlobalOptions, args [] printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) - ctx, srcRepo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock) + ctx, srcRepo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer) if err != nil { return err } defer unlock() - ctx, dstRepo, unlock, err := openWithAppendLock(ctx, secondaryGopts, false) + ctx, dstRepo, unlock, err := openWithAppendLock(ctx, secondaryGopts, false, printer) if err != nil { return err } diff --git a/cmd/restic/cmd_debug.go b/cmd/restic/cmd_debug.go index 10471394c..b3e3aac30 100644 --- a/cmd/restic/cmd_debug.go +++ b/cmd/restic/cmd_debug.go @@ -194,7 +194,7 @@ func runDebugDump(ctx context.Context, gopts GlobalOptions, args []string, term return errors.Fatal("type not specified") } - ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock) + ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer) if err != nil { return err } @@ -465,7 +465,7 @@ func runDebugExamine(ctx context.Context, gopts GlobalOptions, opts DebugExamine return fmt.Errorf("--extract-pack and --no-lock are mutually exclusive") } - ctx, repo, unlock, err := openWithAppendLock(ctx, gopts, gopts.NoLock) + ctx, repo, unlock, err := openWithAppendLock(ctx, gopts, gopts.NoLock, printer) if err != nil { return err } diff --git a/cmd/restic/cmd_diff.go b/cmd/restic/cmd_diff.go index 0e4f8aaf7..d3c0c4cd6 100644 --- a/cmd/restic/cmd_diff.go +++ b/cmd/restic/cmd_diff.go @@ -370,7 +370,7 @@ func runDiff(ctx context.Context, opts DiffOptions, gopts GlobalOptions, args [] printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) - ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock) + ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer) if err != nil { return err } diff --git a/cmd/restic/cmd_dump.go b/cmd/restic/cmd_dump.go index 2a1f9cb1e..336d37648 100644 --- a/cmd/restic/cmd_dump.go +++ b/cmd/restic/cmd_dump.go @@ -148,7 +148,7 @@ func runDump(ctx context.Context, opts DumpOptions, gopts GlobalOptions, args [] splittedPath := splitPath(path.Clean(pathToPrint)) - ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock) + ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer) if err != nil { return err } diff --git a/cmd/restic/cmd_find.go b/cmd/restic/cmd_find.go index a34c749f9..392696769 100644 --- a/cmd/restic/cmd_find.go +++ b/cmd/restic/cmd_find.go @@ -615,7 +615,7 @@ func runFind(ctx context.Context, opts FindOptions, gopts GlobalOptions, args [] return errors.Fatal("cannot have several ID types") } - ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock) + ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer) if err != nil { return err } diff --git a/cmd/restic/cmd_forget.go b/cmd/restic/cmd_forget.go index 7ad1aeb5f..7531bed70 100644 --- a/cmd/restic/cmd_forget.go +++ b/cmd/restic/cmd_forget.go @@ -189,7 +189,7 @@ func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOption } printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) - ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, opts.DryRun && gopts.NoLock) + ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, opts.DryRun && gopts.NoLock, printer) if err != nil { return err } @@ -343,7 +343,7 @@ func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOption printer.P("%d snapshots have been removed, running prune\n", len(removeSnIDs)) } pruneOptions.DryRun = opts.DryRun - return runPruneWithRepo(ctx, pruneOptions, gopts, repo, removeSnIDs, term) + return runPruneWithRepo(ctx, pruneOptions, gopts, repo, removeSnIDs, printer) } return nil diff --git a/cmd/restic/cmd_key_add.go b/cmd/restic/cmd_key_add.go index 7e598abd2..dc07d6889 100644 --- a/cmd/restic/cmd_key_add.go +++ b/cmd/restic/cmd_key_add.go @@ -62,7 +62,7 @@ func runKeyAdd(ctx context.Context, gopts GlobalOptions, opts KeyAddOptions, arg } printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) - ctx, repo, unlock, err := openWithAppendLock(ctx, gopts, false) + ctx, repo, unlock, err := openWithAppendLock(ctx, gopts, false, printer) if err != nil { return err } diff --git a/cmd/restic/cmd_key_list.go b/cmd/restic/cmd_key_list.go index 8dd0bc132..f24e2af32 100644 --- a/cmd/restic/cmd_key_list.go +++ b/cmd/restic/cmd_key_list.go @@ -48,7 +48,7 @@ func runKeyList(ctx context.Context, gopts GlobalOptions, args []string, term *t } printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) - ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock) + ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer) if err != nil { return err } diff --git a/cmd/restic/cmd_key_passwd.go b/cmd/restic/cmd_key_passwd.go index 45f4fc59a..8e3be9ed4 100644 --- a/cmd/restic/cmd_key_passwd.go +++ b/cmd/restic/cmd_key_passwd.go @@ -57,7 +57,7 @@ func runKeyPasswd(ctx context.Context, gopts GlobalOptions, opts KeyPasswdOption } printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) - ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false) + ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer) if err != nil { return err } diff --git a/cmd/restic/cmd_key_remove.go b/cmd/restic/cmd_key_remove.go index b4f84d06f..94db263ee 100644 --- a/cmd/restic/cmd_key_remove.go +++ b/cmd/restic/cmd_key_remove.go @@ -45,7 +45,7 @@ func runKeyRemove(ctx context.Context, gopts GlobalOptions, args []string, term } printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) - ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false) + ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer) if err != nil { return err } diff --git a/cmd/restic/cmd_list.go b/cmd/restic/cmd_list.go index 5500f1932..993c77dba 100644 --- a/cmd/restic/cmd_list.go +++ b/cmd/restic/cmd_list.go @@ -51,7 +51,7 @@ func runList(ctx context.Context, gopts GlobalOptions, args []string, term *term return errors.Fatal("type not specified") } - ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock || args[0] == "locks") + ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock || args[0] == "locks", printer) if err != nil { return err } diff --git a/cmd/restic/cmd_ls.go b/cmd/restic/cmd_ls.go index 9b457c2fb..c5e7e485c 100644 --- a/cmd/restic/cmd_ls.go +++ b/cmd/restic/cmd_ls.go @@ -364,7 +364,7 @@ func runLs(ctx context.Context, opts LsOptions, gopts GlobalOptions, args []stri return false } - ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock) + ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, termPrinter) if err != nil { return err } diff --git a/cmd/restic/cmd_migrate.go b/cmd/restic/cmd_migrate.go index 9f33749f9..1960135af 100644 --- a/cmd/restic/cmd_migrate.go +++ b/cmd/restic/cmd_migrate.go @@ -138,7 +138,7 @@ func applyMigrations(ctx context.Context, opts MigrateOptions, gopts GlobalOptio func runMigrate(ctx context.Context, opts MigrateOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) - ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false) + ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer) if err != nil { return err } diff --git a/cmd/restic/cmd_mount.go b/cmd/restic/cmd_mount.go index 6fff63cac..85f6c6410 100644 --- a/cmd/restic/cmd_mount.go +++ b/cmd/restic/cmd_mount.go @@ -142,7 +142,7 @@ func runMount(ctx context.Context, opts MountOptions, gopts GlobalOptions, args debug.Log("start mount") defer debug.Log("finish mount") - ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock) + ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer) if err != nil { return err } diff --git a/cmd/restic/cmd_mount_integration_test.go b/cmd/restic/cmd_mount_integration_test.go index c7b7a78c1..4fbf42694 100644 --- a/cmd/restic/cmd_mount_integration_test.go +++ b/cmd/restic/cmd_mount_integration_test.go @@ -128,7 +128,10 @@ func checkSnapshots(t testing.TB, gopts GlobalOptions, mountpoint string, snapsh } } - _, repo, unlock, err := openWithReadLock(context.TODO(), gopts, false) + term, cancel := setupTermstatus() + defer cancel() + printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) + _, repo, unlock, err := openWithReadLock(context.TODO(), gopts, false, printer) rtest.OK(t, err) defer unlock() diff --git a/cmd/restic/cmd_prune.go b/cmd/restic/cmd_prune.go index 97efb3b2b..0b0d94440 100644 --- a/cmd/restic/cmd_prune.go +++ b/cmd/restic/cmd_prune.go @@ -169,7 +169,8 @@ func runPrune(ctx context.Context, opts PruneOptions, gopts GlobalOptions, term return errors.Fatal("--no-lock is only applicable in combination with --dry-run for prune command") } - ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, opts.DryRun && gopts.NoLock) + printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) + ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, opts.DryRun && gopts.NoLock, printer) if err != nil { return err } @@ -183,11 +184,10 @@ func runPrune(ctx context.Context, opts PruneOptions, gopts GlobalOptions, term opts.unsafeRecovery = true } - return runPruneWithRepo(ctx, opts, gopts, repo, restic.NewIDSet(), term) + return runPruneWithRepo(ctx, opts, gopts, repo, restic.NewIDSet(), printer) } -func runPruneWithRepo(ctx context.Context, opts PruneOptions, gopts GlobalOptions, repo *repository.Repository, ignoreSnapshots restic.IDSet, term *termstatus.Terminal) error { - printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) +func runPruneWithRepo(ctx context.Context, opts PruneOptions, gopts GlobalOptions, repo *repository.Repository, ignoreSnapshots restic.IDSet, printer progress.Printer) error { if repo.Cache() == nil { printer.S("warning: running prune without a cache, this may be very slow!") } diff --git a/cmd/restic/cmd_recover.go b/cmd/restic/cmd_recover.go index 60c6d4e84..60a3d445f 100644 --- a/cmd/restic/cmd_recover.go +++ b/cmd/restic/cmd_recover.go @@ -50,7 +50,7 @@ func runRecover(ctx context.Context, gopts GlobalOptions, term *termstatus.Termi } printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) - ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false) + ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer) if err != nil { return err } diff --git a/cmd/restic/cmd_repair_index.go b/cmd/restic/cmd_repair_index.go index a4f230e05..e8bb31fca 100644 --- a/cmd/restic/cmd_repair_index.go +++ b/cmd/restic/cmd_repair_index.go @@ -74,7 +74,8 @@ 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) + + ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer) if err != nil { return err } diff --git a/cmd/restic/cmd_repair_packs.go b/cmd/restic/cmd_repair_packs.go index d6d57012f..01c652120 100644 --- a/cmd/restic/cmd_repair_packs.go +++ b/cmd/restic/cmd_repair_packs.go @@ -54,7 +54,8 @@ func runRepairPacks(ctx context.Context, gopts GlobalOptions, term *termstatus.T } printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) - ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false) + + ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer) if err != nil { return err } diff --git a/cmd/restic/cmd_repair_snapshots.go b/cmd/restic/cmd_repair_snapshots.go index 758048caa..b0b09673d 100644 --- a/cmd/restic/cmd_repair_snapshots.go +++ b/cmd/restic/cmd_repair_snapshots.go @@ -78,7 +78,7 @@ func (opts *RepairOptions) AddFlags(f *pflag.FlagSet) { func runRepairSnapshots(ctx context.Context, gopts GlobalOptions, opts RepairOptions, args []string, term *termstatus.Terminal) error { printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) - ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, opts.DryRun) + ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, opts.DryRun, printer) if err != nil { return err } diff --git a/cmd/restic/cmd_restore.go b/cmd/restic/cmd_restore.go index 754832507..d04b8a6b1 100644 --- a/cmd/restic/cmd_restore.go +++ b/cmd/restic/cmd_restore.go @@ -131,7 +131,7 @@ func runRestore(ctx context.Context, opts RestoreOptions, gopts GlobalOptions, debug.Log("restore %v to %v", snapshotIDString, opts.Target) - ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock) + ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, msg) if err != nil { return err } diff --git a/cmd/restic/cmd_rewrite.go b/cmd/restic/cmd_rewrite.go index 5674fe1e4..82f3e0ea9 100644 --- a/cmd/restic/cmd_rewrite.go +++ b/cmd/restic/cmd_rewrite.go @@ -306,9 +306,9 @@ func runRewrite(ctx context.Context, opts RewriteOptions, gopts GlobalOptions, a if opts.Forget { printer.P("create exclusive lock for repository") - ctx, repo, unlock, err = openWithExclusiveLock(ctx, gopts, opts.DryRun) + ctx, repo, unlock, err = openWithExclusiveLock(ctx, gopts, opts.DryRun, printer) } else { - ctx, repo, unlock, err = openWithAppendLock(ctx, gopts, opts.DryRun) + ctx, repo, unlock, err = openWithAppendLock(ctx, gopts, opts.DryRun, printer) } if err != nil { return err diff --git a/cmd/restic/cmd_rewrite_integration_test.go b/cmd/restic/cmd_rewrite_integration_test.go index 195ab37e5..57b223591 100644 --- a/cmd/restic/cmd_rewrite_integration_test.go +++ b/cmd/restic/cmd_rewrite_integration_test.go @@ -41,7 +41,10 @@ func createBasicRewriteRepo(t testing.TB, env *testEnvironment) restic.ID { func getSnapshot(t testing.TB, snapshotID restic.ID, env *testEnvironment) *restic.Snapshot { t.Helper() - ctx, repo, unlock, err := openWithReadLock(context.TODO(), env.gopts, false) + term, cancel := setupTermstatus() + defer cancel() + printer := newTerminalProgressPrinter(env.gopts.JSON, env.gopts.verbosity, term) + ctx, repo, unlock, err := openWithReadLock(context.TODO(), env.gopts, false, printer) rtest.OK(t, err) defer unlock() @@ -112,7 +115,10 @@ func testRewriteMetadata(t *testing.T, metadata snapshotMetadataArgs) { createBasicRewriteRepo(t, env) testRunRewriteExclude(t, env.gopts, []string{}, true, metadata) - ctx, repo, unlock, err := openWithReadLock(context.TODO(), env.gopts, false) + term, cancel := setupTermstatus() + defer cancel() + printer := newTerminalProgressPrinter(env.gopts.JSON, env.gopts.verbosity, term) + ctx, repo, unlock, err := openWithReadLock(context.TODO(), env.gopts, false, printer) rtest.OK(t, err) defer unlock() @@ -155,7 +161,10 @@ func TestRewriteSnaphotSummary(t *testing.T) { snapshots := testListSnapshots(t, env.gopts, 1) // replace snapshot by one without a summary - _, repo, unlock, err := openWithExclusiveLock(context.TODO(), env.gopts, false) + term, cancel := setupTermstatus() + defer cancel() + printer := newTerminalProgressPrinter(env.gopts.JSON, env.gopts.verbosity, term) + _, repo, unlock, err := openWithExclusiveLock(context.TODO(), env.gopts, false, printer) rtest.OK(t, err) sn, err := restic.LoadSnapshot(context.TODO(), repo, snapshots[0]) rtest.OK(t, err) diff --git a/cmd/restic/cmd_snapshots.go b/cmd/restic/cmd_snapshots.go index 62f0cdd1f..29ab08e07 100644 --- a/cmd/restic/cmd_snapshots.go +++ b/cmd/restic/cmd_snapshots.go @@ -71,7 +71,7 @@ func (opts *SnapshotOptions) AddFlags(f *pflag.FlagSet) { func runSnapshots(ctx context.Context, opts SnapshotOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) - ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock) + ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer) if err != nil { return err } diff --git a/cmd/restic/cmd_stats.go b/cmd/restic/cmd_stats.go index 20b4d12eb..2b87384f0 100644 --- a/cmd/restic/cmd_stats.go +++ b/cmd/restic/cmd_stats.go @@ -104,7 +104,7 @@ func runStats(ctx context.Context, opts StatsOptions, gopts GlobalOptions, args printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) - ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock) + ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer) if err != nil { return err } diff --git a/cmd/restic/cmd_tag.go b/cmd/restic/cmd_tag.go index efae969b9..dc5e33fa8 100644 --- a/cmd/restic/cmd_tag.go +++ b/cmd/restic/cmd_tag.go @@ -130,7 +130,7 @@ func runTag(ctx context.Context, opts TagOptions, gopts GlobalOptions, term *ter } printer.P("create exclusive lock for repository") - ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false) + ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer) if err != nil { return err } diff --git a/cmd/restic/integration_helpers_test.go b/cmd/restic/integration_helpers_test.go index c265272e9..233316c59 100644 --- a/cmd/restic/integration_helpers_test.go +++ b/cmd/restic/integration_helpers_test.go @@ -246,7 +246,10 @@ func testSetupBackupData(t testing.TB, env *testEnvironment) string { } func listPacks(gopts GlobalOptions, t *testing.T) restic.IDSet { - ctx, r, unlock, err := openWithReadLock(context.TODO(), gopts, false) + term, cancel := setupTermstatus() + defer cancel() + printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) + ctx, r, unlock, err := openWithReadLock(context.TODO(), gopts, false, printer) rtest.OK(t, err) defer unlock() @@ -260,7 +263,10 @@ func listPacks(gopts GlobalOptions, t *testing.T) restic.IDSet { } func listTreePacks(gopts GlobalOptions, t *testing.T) restic.IDSet { - ctx, r, unlock, err := openWithReadLock(context.TODO(), gopts, false) + term, cancel := setupTermstatus() + defer cancel() + printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) + ctx, r, unlock, err := openWithReadLock(context.TODO(), gopts, false, printer) rtest.OK(t, err) defer unlock() @@ -288,7 +294,10 @@ func captureBackend(gopts *GlobalOptions) func() backend.Backend { func removePacks(gopts GlobalOptions, t testing.TB, remove restic.IDSet) { be := captureBackend(&gopts) - ctx, _, unlock, err := openWithExclusiveLock(context.TODO(), gopts, false) + term, cancel := setupTermstatus() + defer cancel() + printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) + ctx, _, unlock, err := openWithExclusiveLock(context.TODO(), gopts, false, printer) rtest.OK(t, err) defer unlock() @@ -299,7 +308,10 @@ func removePacks(gopts GlobalOptions, t testing.TB, remove restic.IDSet) { func removePacksExcept(gopts GlobalOptions, t testing.TB, keep restic.IDSet, removeTreePacks bool) { be := captureBackend(&gopts) - ctx, r, unlock, err := openWithExclusiveLock(context.TODO(), gopts, false) + term, cancel := setupTermstatus() + defer cancel() + printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) + ctx, r, unlock, err := openWithExclusiveLock(context.TODO(), gopts, false, printer) rtest.OK(t, err) defer unlock() @@ -355,7 +367,10 @@ func lastSnapshot(old, new map[string]struct{}) (map[string]struct{}, string) { } func testLoadSnapshot(t testing.TB, gopts GlobalOptions, id restic.ID) *restic.Snapshot { - _, repo, unlock, err := openWithReadLock(context.TODO(), gopts, false) + term, cancel := setupTermstatus() + defer cancel() + printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) + _, repo, unlock, err := openWithReadLock(context.TODO(), gopts, false, printer) defer unlock() rtest.OK(t, err) snapshot, err := restic.LoadSnapshot(context.TODO(), repo, id) diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index 3ef98a168..0525c7e29 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -161,7 +161,10 @@ func TestFindListOnce(t *testing.T) { testRunBackup(t, "", []string{filepath.Join(env.testdata, "0", "0", "9", "3")}, opts, env.gopts) thirdSnapshot := restic.NewIDSet(testListSnapshots(t, env.gopts, 3)...) - ctx, repo, unlock, err := openWithReadLock(context.TODO(), env.gopts, false) + term, cancel := setupTermstatus() + defer cancel() + printer := newTerminalProgressPrinter(env.gopts.JSON, env.gopts.verbosity, term) + ctx, repo, unlock, err := openWithReadLock(context.TODO(), env.gopts, false, printer) rtest.OK(t, err) defer unlock() diff --git a/cmd/restic/lock.go b/cmd/restic/lock.go index 0e3dea6d5..f50d5633d 100644 --- a/cmd/restic/lock.go +++ b/cmd/restic/lock.go @@ -4,9 +4,10 @@ import ( "context" "github.com/restic/restic/internal/repository" + "github.com/restic/restic/internal/ui/progress" ) -func internalOpenWithLocked(ctx context.Context, gopts GlobalOptions, dryRun bool, exclusive bool) (context.Context, *repository.Repository, func(), error) { +func internalOpenWithLocked(ctx context.Context, gopts GlobalOptions, dryRun bool, exclusive bool, printer progress.Printer) (context.Context, *repository.Repository, func(), error) { repo, err := OpenRepository(ctx, gopts) if err != nil { return nil, nil, nil, err @@ -18,9 +19,9 @@ func internalOpenWithLocked(ctx context.Context, gopts GlobalOptions, dryRun boo lock, ctx, err = repository.Lock(ctx, repo, exclusive, gopts.RetryLock, func(msg string) { if !gopts.JSON { - Verbosef("%s", msg) + printer.P("%s", msg) } - }, Warnf) + }, printer.E) if err != nil { return nil, nil, nil, err } @@ -33,16 +34,16 @@ func internalOpenWithLocked(ctx context.Context, gopts GlobalOptions, dryRun boo return ctx, repo, unlock, nil } -func openWithReadLock(ctx context.Context, gopts GlobalOptions, noLock bool) (context.Context, *repository.Repository, func(), error) { +func openWithReadLock(ctx context.Context, gopts GlobalOptions, noLock bool, printer progress.Printer) (context.Context, *repository.Repository, func(), error) { // TODO enforce read-only operations once the locking code has moved to the repository - return internalOpenWithLocked(ctx, gopts, noLock, false) + return internalOpenWithLocked(ctx, gopts, noLock, false, printer) } -func openWithAppendLock(ctx context.Context, gopts GlobalOptions, dryRun bool) (context.Context, *repository.Repository, func(), error) { +func openWithAppendLock(ctx context.Context, gopts GlobalOptions, dryRun bool, printer progress.Printer) (context.Context, *repository.Repository, func(), error) { // TODO enforce non-exclusive operations once the locking code has moved to the repository - return internalOpenWithLocked(ctx, gopts, dryRun, false) + return internalOpenWithLocked(ctx, gopts, dryRun, false, printer) } -func openWithExclusiveLock(ctx context.Context, gopts GlobalOptions, dryRun bool) (context.Context, *repository.Repository, func(), error) { - return internalOpenWithLocked(ctx, gopts, dryRun, true) +func openWithExclusiveLock(ctx context.Context, gopts GlobalOptions, dryRun bool, printer progress.Printer) (context.Context, *repository.Repository, func(), error) { + return internalOpenWithLocked(ctx, gopts, dryRun, true, printer) }