Commit c835bf38 authored by Kirill Smelkov's avatar Kirill Smelkov

pull|restore: Cancel ran command on SIGINT | SIGTERM

This lets deferred cleanup to be run instead of whole process being
killed without having a chance to preserve external data in consistent
state.
parent 540f0ead
...@@ -72,6 +72,7 @@ import ( ...@@ -72,6 +72,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"os/signal"
pathpkg "path" pathpkg "path"
"path/filepath" "path/filepath"
"runtime" "runtime"
...@@ -1240,9 +1241,22 @@ func main() { ...@@ -1240,9 +1241,22 @@ func main() {
os.Exit(1) os.Exit(1)
}) })
// cancel what we'll do on SIGINT | SIGTERM
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
sigq := make(chan os.Signal, 1)
signal.Notify(sigq, os.Interrupt, syscall.SIGTERM)
go func() {
select {
case <-ctx.Done():
case <-sigq:
cancel()
}
}()
// backup repository // backup repository
gb, err := git.OpenRepository(".") gb, err := git.OpenRepository(".")
exc.Raiseif(err) exc.Raiseif(err)
cmd(context.Background(), gb, argv[1:]) cmd(ctx, gb, argv[1:])
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment