Compare commits

..

1 Commits

Author SHA1 Message Date
c642efcf8c
WIP: feat: cancel git clone ops gracefully
All checks were successful
continuous-integration/drone/push Build is passing
See #528
2025-04-22 22:38:59 +02:00

View File

@ -28,17 +28,17 @@ func gitCloneIgnoreErr(err error) bool {
// Clone runs a git clone which accounts for different default branches.
func Clone(dir, url string) error {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
ctx, cancelCtx := context.WithCancel(ctx)
sigIntCh := make(chan os.Signal, 1)
signal.Notify(sigIntCh, os.Interrupt)
defer func() {
signal.Stop(sigIntCh)
cancelCtx()
}()
errCh := make(chan error)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
defer func() {
signal.Stop(c)
cancel()
}()
go func() {
if _, err := os.Stat(dir); os.IsNotExist(err) {
log.Debugf("git clone: %s", url)
@ -88,8 +88,8 @@ func Clone(dir, url string) error {
}()
select {
case <-c:
cancel()
case <-sigIntCh:
cancelCtx()
fmt.Println() // NOTE(d1): newline after ^C
if err := os.RemoveAll(dir); err != nil {
return fmt.Errorf("unable to clean up git clone of %s: %s", dir, err)