From 666768cd176ffebb36112ba8eea78cd06a47fa05 Mon Sep 17 00:00:00 2001 From: Kyle Brennan Date: Wed, 25 Nov 2020 23:04:46 -0800 Subject: [PATCH 1/2] cat: Respect --no-lock flag --- changelog/unreleased/issue-2739 | 5 +++++ cmd/restic/cmd_cat.go | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 changelog/unreleased/issue-2739 diff --git a/changelog/unreleased/issue-2739 b/changelog/unreleased/issue-2739 new file mode 100644 index 000000000..a47a57d2c --- /dev/null +++ b/changelog/unreleased/issue-2739 @@ -0,0 +1,5 @@ +Bugfix: Make cat command respect --no-lock + +Restic cat would not respect the --no-lock flag, it now does. + +https://github.com/restic/restic/issues/2739 diff --git a/cmd/restic/cmd_cat.go b/cmd/restic/cmd_cat.go index e02d923bf..b0e33b5f4 100644 --- a/cmd/restic/cmd_cat.go +++ b/cmd/restic/cmd_cat.go @@ -42,10 +42,13 @@ func runCat(gopts GlobalOptions, args []string) error { return err } - lock, err := lockRepo(gopts.ctx, repo) - defer unlockRepo(lock) - if err != nil { - return err + if !gopts.NoLock { + lock, err := lockRepo(gopts.ctx, repo) + // Make the linter happy + if err != nil { + return err + } + defer func() { _ = unlockRepo(lock) }() } tpe := args[0] From a3105799c9a25bd43f9b44cb1d8782bc05782168 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 28 Nov 2020 11:31:25 +0100 Subject: [PATCH 2/2] Print warning when unlocking the repo fails --- cmd/restic/cmd_cat.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/restic/cmd_cat.go b/cmd/restic/cmd_cat.go index b0e33b5f4..85fc7942d 100644 --- a/cmd/restic/cmd_cat.go +++ b/cmd/restic/cmd_cat.go @@ -44,11 +44,16 @@ func runCat(gopts GlobalOptions, args []string) error { if !gopts.NoLock { lock, err := lockRepo(gopts.ctx, repo) - // Make the linter happy if err != nil { return err } - defer func() { _ = unlockRepo(lock) }() + + defer func() { + err := unlockRepo(lock) + if err != nil { + Warnf("unlock repo failed: %v", err) + } + }() } tpe := args[0]