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 (
"fmt"
"io/ioutil"
"os"
"os/signal"
pathpkg "path"
"path/filepath"
"runtime"
......@@ -1240,9 +1241,22 @@ func main() {
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
gb, err := git.OpenRepository(".")
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