Only cleanup temporary file after run is over

Mac apparently sends SIGKILL to processes spawned by a process that no
longer exists on disk! ... or something like that.
This commit is contained in:
Matthew Holt 2020-04-23 15:04:06 -06:00
parent 7e4f9a06d3
commit 68d27a0401
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5

View file

@ -24,7 +24,6 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
"time"
"github.com/caddyserver/xcaddy" "github.com/caddyserver/xcaddy"
) )
@ -203,17 +202,11 @@ func runDev(ctx context.Context, args []string) error {
if err != nil { if err != nil {
return err return err
} }
defer func() {
cleanup := func() {
err = os.Remove(binOutput) err = os.Remove(binOutput)
if err != nil && !os.IsNotExist(err) { if err != nil && !os.IsNotExist(err) {
log.Printf("[ERROR] Deleting temporary binary %s: %v", binOutput, err) log.Printf("[ERROR] Deleting temporary binary %s: %v", binOutput, err)
} }
}
defer cleanup()
go func() {
time.Sleep(5 * time.Second)
cleanup()
}() }()
return cmd.Wait() return cmd.Wait()