From 76817da922be684f4d7f6931088c27b188739b73 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 19 Jul 2015 17:57:18 +0200 Subject: [PATCH] Run cleanup handlers in main function --- cmd/restic/cleanup.go | 6 ++++++ cmd/restic/main.go | 2 ++ 2 files changed, 8 insertions(+) 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) }