From 1a25af3eaafd11b4be28020e3d86ba88dd942a29 Mon Sep 17 00:00:00 2001 From: Debdut Chakraborty Date: Thu, 21 Mar 2024 11:02:04 +0530 Subject: [PATCH] fix: truncating novm binary before making sure update exists or not --- update_check.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/update_check.go b/update_check.go index f33c05c..1490636 100644 --- a/update_check.go +++ b/update_check.go @@ -6,8 +6,10 @@ import ( "log" "net/http" "os" + "os/signal" "path/filepath" "runtime" + "syscall" "golang.org/x/mod/semver" @@ -123,12 +125,32 @@ func startCheckUpdate() (chan bool, chan bool) { } } + } else { + <-cont // consume + log.Println("no new novm updates found.") + return } + // we ignore sigint and sigterm here to not lose the binary + + sig := make(chan os.Signal, 1) + + signal.Notify(sig, syscall.SIGINT, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGQUIT) + + go func() { + for { + <-sig + + log.Println("ignoring signal since novm is still updating") + } + }() + <-cont // upgrade the binary // we expect current binary to be a symlink + log.Printf("Updating novm to %s", release.Tag) + root, _ := common.RootDir() bin := filepath.Join(root, "bin", "node")