From 792523b28bb0735d202a578ffa42e6efd202fcbc Mon Sep 17 00:00:00 2001 From: Pavel Frolov Date: Sat, 8 Jan 2022 14:58:06 +0300 Subject: [PATCH] [issue 3464] skip lock creation in case of dry-run --- changelog/unreleased/issue-3464 | 9 +++++++++ cmd/restic/cmd_forget.go | 15 +++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 changelog/unreleased/issue-3464 diff --git a/changelog/unreleased/issue-3464 b/changelog/unreleased/issue-3464 new file mode 100644 index 000000000..baf062c40 --- /dev/null +++ b/changelog/unreleased/issue-3464 @@ -0,0 +1,9 @@ +Enhancement: Skip lock creation on forget if --no-lock and --dry-run + +Restic used to silently ignore --no-lock option of forget. It now skips +creation of lock file in case of both --dry-run and --no-lock are specified. If +--no-lock option is specified without --dry-run then restic prints a warning +message to stderr. + +https://github.com/restic/restic/issues/3464 +https://github.com/restic/restic/pull/3623 diff --git a/cmd/restic/cmd_forget.go b/cmd/restic/cmd_forget.go index 602c897d8..fd34f4038 100644 --- a/cmd/restic/cmd_forget.go +++ b/cmd/restic/cmd_forget.go @@ -5,6 +5,7 @@ import ( "encoding/json" "io" + "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" "github.com/spf13/cobra" ) @@ -108,10 +109,16 @@ func runForget(opts ForgetOptions, gopts GlobalOptions, args []string) error { return err } - lock, err := lockRepoExclusive(gopts.ctx, repo) - defer unlockRepo(lock) - if err != nil { - return err + if gopts.NoLock && !opts.DryRun { + return errors.Fatal("--no-lock is only applicable in combination with --dry-run for forget command") + } + + if !opts.DryRun || !gopts.NoLock { + lock, err := lockRepoExclusive(gopts.ctx, repo) + defer unlockRepo(lock) + if err != nil { + return err + } } ctx, cancel := context.WithCancel(gopts.ctx)