[issue 3464] skip lock creation in case of dry-run

This commit is contained in:
Pavel Frolov
2022-01-08 14:58:06 +03:00
parent 2ff3b7d69c
commit 792523b28b
2 changed files with 20 additions and 4 deletions

View File

@@ -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)