From f51b648941a2ff536714a92519f48c81682766c8 Mon Sep 17 00:00:00 2001 From: Songmu Date: Tue, 2 Jan 2018 23:43:45 +0900 Subject: [PATCH] use os.Executable instead of using os.Args[0] --- selfupdate/update.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/selfupdate/update.go b/selfupdate/update.go index ee6e5e0..7b93f70 100644 --- a/selfupdate/update.go +++ b/selfupdate/update.go @@ -2,13 +2,14 @@ package selfupdate import ( "fmt" - "github.com/blang/semver" - "github.com/inconshreveable/go-update" "net/http" "os" "path/filepath" "runtime" "strings" + + "github.com/blang/semver" + "github.com/inconshreveable/go-update" ) // UpdateTo download an executable from assetURL and replace the current binary with the downloaded one. cmdPath is a file path to command executable. @@ -65,5 +66,9 @@ func UpdateCommand(cmdPath string, current semver.Version, slug string) (*Releas // UpdateSelf updates the running executable itself to the latest version. // 'slug' represents 'owner/name' repository on GitHub and 'current' means the current version. func UpdateSelf(current semver.Version, slug string) (*Release, error) { - return UpdateCommand(os.Args[0], current, slug) + cmdPath, err := os.Executable() + if err != nil { + return nil, err + } + return UpdateCommand(cmdPath, current, slug) }