From a92a9e4c738f14db6546868f8b126c082370f739 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 30 Nov 2015 14:45:54 -0800 Subject: [PATCH] update: Fix update command. --- notifier.go | 6 +++--- update-main.go | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/notifier.go b/notifier.go index b9020629..59e1ba28 100644 --- a/notifier.go +++ b/notifier.go @@ -35,14 +35,14 @@ func colorizeUpdateMessage(updateString string) (string, *probe.Error) { // calculate length without color coding, due to ANSI color characters padded to actual // string the final length is wrong than the original string length. - line1Str := fmt.Sprintf(" Update available: ") - line2Str := fmt.Sprintf(" Run \"%s\" to update. ", updateString) + line1Str := fmt.Sprintf(" New update available, please execute the following command to update: ") + line2Str := fmt.Sprintf(" %s ", updateString) line1Length := len(line1Str) line2Length := len(line2Str) // populate lines with color coding. line1InColor := line1Str - line2InColor := fmt.Sprintf(" Run \"%s\" to update. ", cyan(updateString)) + line2InColor := fmt.Sprintf(" %s ", cyan(updateString)) // calculate the rectangular box size. maxContentWidth := int(math.Max(float64(line1Length), float64(line2Length))) diff --git a/update-main.go b/update-main.go index ec4d2dd4..455316f4 100644 --- a/update-main.go +++ b/update-main.go @@ -19,6 +19,7 @@ package main import ( "encoding/json" "net/http" + "os" "runtime" "time" @@ -93,9 +94,15 @@ func (u updateMessage) String() string { } var msg string if runtime.GOOS == "windows" { - msg = "mc.exe cp " + u.Download + " .\\mc.exe" + // verify if the mc binary exists in the current directory. + // In such cases do not overwrite it. + if _, e := os.Stat(".\\mc.exe"); e == nil { + msg = "Download " + u.Download + } else { + msg = "mc.exe cp " + u.Download + " .\\mc.exe" + } } else { - msg = "mc cp " + u.Download + " ./mc.new; chmod 755 ./mc.new" + msg = "mc cp " + u.Download + " mc; chmod 755 mc" } msg, err := colorizeUpdateMessage(msg) fatalIf(err.Trace(msg), "Unable to colorize experimental update notification string ‘"+msg+"’.")