aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2019-08-07 08:21:15 +0200
committerDrew DeVault <sir@cmpwn.com>2019-08-08 10:24:03 +0900
commit072b5f453ccb8c3d79f55be80f5db9e71cf17a31 (patch)
tree2b83400568fad92a5c434e26e3b8b8af53e0cc77
parentd4416e74ac64e10249ad085f0bcd12887b077bf2 (diff)
downloadaerc-072b5f453ccb8c3d79f55be80f5db9e71cf17a31.tar.gz
Close backends prior to shutdown
We need some way to signal the backends that we are about to shutdown, allowing them to clean up (for example in notmuch committing the db changes). This commit implements a hook which gets called upon shutdown, providing backends implement the io.Closer interface.
-rw-r--r--aerc.go1
-rw-r--r--widgets/aerc.go19
2 files changed, 20 insertions, 0 deletions
diff --git a/aerc.go b/aerc.go
index c71c3843..c5d93ac5 100644
--- a/aerc.go
+++ b/aerc.go
@@ -178,4 +178,5 @@ func main() {
time.Sleep(16 * time.Millisecond)
}
}
+ aerc.CloseBackends()
}
diff --git a/widgets/aerc.go b/widgets/aerc.go
index 23dac3e2..5a7914a0 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -2,6 +2,7 @@ package widgets
import (
"errors"
+ "io"
"log"
"net/url"
"strings"
@@ -405,3 +406,21 @@ func (aerc *Aerc) Mailto(addr *url.URL) error {
})
return nil
}
+
+func (aerc *Aerc) CloseBackends() error {
+ var returnErr error
+ for _, acct := range aerc.accounts {
+ var raw interface{} = acct.worker.Backend
+ c, ok := raw.(io.Closer)
+ if !ok {
+ continue
+ }
+ err := c.Close()
+ if err != nil {
+ returnErr = err
+ aerc.logger.Printf("Closing backend failed for %v: %v\n",
+ acct.Name(), err)
+ }
+ }
+ return returnErr
+}