use os.Executable instead of using os.Args[0]

This commit is contained in:
Songmu 2018-01-02 23:43:45 +09:00
parent 533ad72291
commit f51b648941

View file

@ -2,13 +2,14 @@ package selfupdate
import ( import (
"fmt" "fmt"
"github.com/blang/semver"
"github.com/inconshreveable/go-update"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "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. // 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. // UpdateSelf updates the running executable itself to the latest version.
// 'slug' represents 'owner/name' repository on GitHub and 'current' means the current version. // 'slug' represents 'owner/name' repository on GitHub and 'current' means the current version.
func UpdateSelf(current semver.Version, slug string) (*Release, error) { 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)
} }