From bc8edceabbe5fa10f9ebf54e9cfd24caa0528865 Mon Sep 17 00:00:00 2001 From: Denis Vaumoron Date: Tue, 4 Jun 2024 23:46:25 +0200 Subject: [PATCH] Fallback when last version retrieving fail (#1) --- cmd/go/install.go | 3 +-- cmd/go/last.go | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/go/install.go b/cmd/go/install.go index abef1dc..de3986e 100644 --- a/cmd/go/install.go +++ b/cmd/go/install.go @@ -23,7 +23,6 @@ import ( "io" "net/http" "net/url" - "os" "runtime" "strings" @@ -101,7 +100,7 @@ func getLastVersion(conf config) versionDesc { if err != nil || len(versions) == 0 { fmt.Println("Unable to retrieve last version :", err) - os.Exit(1) + return versionDesc{} } datefile.Write(conf.dateFilePath) diff --git a/cmd/go/last.go b/cmd/go/last.go index 55b62b8..81fa879 100644 --- a/cmd/go/last.go +++ b/cmd/go/last.go @@ -41,7 +41,13 @@ func main() { installedVersion, versionMessage := getInstalledVersion(conf) notInstalled := installedVersion == "" if notInstalled || datefile.OutsideInterval(conf.dateFilePath, conf.checkInterval) { - if lastVersionDesc := getLastVersion(conf); installedVersion != lastVersionDesc.version { + if lastVersionDesc := getLastVersion(conf); lastVersionDesc.version == "" { + if notInstalled { + fmt.Println("Can not fallback, Go is not installed yet") + os.Exit(1) + } + fmt.Println("Fallback to", installedVersion, "already installed") + } else if installedVersion != lastVersionDesc.version { doUpdate := true if notInstalled { fmt.Println("Install", lastVersionDesc.version)