From edfbf7769e0e6c9d5edfce5fb0fc6ef74ccddce0 Mon Sep 17 00:00:00 2001 From: David Dworken Date: Wed, 20 Apr 2022 21:57:37 -0700 Subject: [PATCH] Fix updating on m1 darwin For some reason, calling unlink() on the binary causes all future spawned processes to die with a "signal: killed" error. I have no idea why this happens, but it doesn't seem to be necessary to call unlink on darwin, so I'm just tweaking this to not call unlink on darwin. Also remove tidy from the pre-commit since macos ships with a truly ancient version of tidy --- .pre-commit-config.yaml | 5 ----- client/lib/lib.go | 22 ++++++++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e9a321b..3f787b3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,8 +14,3 @@ repos: entry: errcheck -exclude .errcheck_excludes.txt ./... language: system pass_filenames: false - - id: html-tidy - name: html-tidy - entry: tidy -quiet -modify -indent -wrap 140 backend/web/landing/www/index.html - language: system - pass_filenames: false diff --git a/client/lib/lib.go b/client/lib/lib.go index ba1627e..9cc9fc4 100644 --- a/client/lib/lib.go +++ b/client/lib/lib.go @@ -521,20 +521,26 @@ func Update() error { } // Unlink the existing binary so we can overwrite it even though it is still running - homedir, err := os.UserHomeDir() - if err != nil { - return fmt.Errorf("failed to get user's home directory: %v", err) - } - err = syscall.Unlink(path.Join(homedir, shared.HISHTORY_PATH, "hishtory")) - if err != nil { - return fmt.Errorf("failed to unlink %s for update: %v", path.Join(homedir, shared.HISHTORY_PATH, "hishtory"), err) + if runtime.GOOS == "linux" { + homedir, err := os.UserHomeDir() + if err != nil { + return fmt.Errorf("failed to get user's home directory: %v", err) + } + err = syscall.Unlink(path.Join(homedir, shared.HISHTORY_PATH, "hishtory")) + if err != nil { + return fmt.Errorf("failed to unlink %s for update: %v", path.Join(homedir, shared.HISHTORY_PATH, "hishtory"), err) + } } // Install the new one cmd := exec.Command("chmod", "+x", "/tmp/hishtory-client") + var stdout bytes.Buffer + cmd.Stdout = &stdout + var stderr bytes.Buffer + cmd.Stderr = &stderr err = cmd.Run() if err != nil { - return fmt.Errorf("failed to chmod +x the update: %v", err) + return fmt.Errorf("failed to chmod +x the update (out=%#v, err=%#v): %v", stdout.String(), stderr.String(), err) } cmd = exec.Command("/tmp/hishtory-client", "install") err = cmd.Run()