From 910927670f135ae08810710631f1126900743abc Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 5 Apr 2024 22:23:08 +0200 Subject: [PATCH] mount: fix exit code on cancellation --- cmd/restic/cmd_mount.go | 2 +- cmd/restic/main.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/restic/cmd_mount.go b/cmd/restic/cmd_mount.go index 1e4bff03e..5a10447f3 100644 --- a/cmd/restic/cmd_mount.go +++ b/cmd/restic/cmd_mount.go @@ -190,7 +190,7 @@ func runMount(ctx context.Context, opts MountOptions, gopts GlobalOptions, args Warnf("unable to umount (maybe already umounted or still in use?): %v\n", err) } - return nil + return ErrOK case <-done: // clean shutdown, nothing to do } diff --git a/cmd/restic/main.go b/cmd/restic/main.go index 56ddf74a4..82517c31a 100644 --- a/cmd/restic/main.go +++ b/cmd/restic/main.go @@ -25,6 +25,8 @@ func init() { _, _ = maxprocs.Set() } +var ErrOK = errors.New("ok") + // cmdRoot is the base command when no other command has been specified. var cmdRoot = &cobra.Command{ Use: "restic", @@ -125,6 +127,9 @@ func main() { if err == nil { err = ctx.Err() + } else if err == ErrOK { + // ErrOK overwrites context cancelation errors + err = nil } switch {