diff --git a/cmd/restic/cleanup.go b/cmd/restic/cleanup.go index a29d45be4..b4d4771d5 100644 --- a/cmd/restic/cleanup.go +++ b/cmd/restic/cleanup.go @@ -13,6 +13,7 @@ import ( var cleanupHandlers struct { sync.Mutex list []func() error + done bool } var stderr = os.Stderr @@ -39,6 +40,11 @@ func RunCleanupHandlers() { cleanupHandlers.Lock() defer cleanupHandlers.Unlock() + if cleanupHandlers.done { + return + } + cleanupHandlers.done = true + for _, f := range cleanupHandlers.list { err := f() if err != nil { diff --git a/cmd/restic/main.go b/cmd/restic/main.go index 3acab925e..a11bab84f 100644 --- a/cmd/restic/main.go +++ b/cmd/restic/main.go @@ -32,6 +32,8 @@ func main() { fmt.Fprintf(os.Stderr, "\nthe `unlock` command can be used to remove stale locks\n") } + RunCleanupHandlers() + if err != nil { os.Exit(1) }