summaryrefslogtreecommitdiffhomepage
path: root/version/cmdname.go
diff options
context:
space:
mode:
authorDavid Anderson <danderson@tailscale.com>2020-08-01 02:44:40 +0000
committerDavid Anderson <danderson@tailscale.com>2020-08-01 02:44:40 +0000
commite98ed6319a417caf4d665ec759d71d4bb8c8aaee (patch)
tree1c625a4c1275d91b46e3a0ff8e613625d652531d /version/cmdname.go
parent2ce2b632396801600b057859ae26c4b508f10e57 (diff)
parent9e26ffecf87e3a4deafc5875a8283853d7527458 (diff)
downloadtailscale-1.0.1.tar.xz
tailscale-1.0.1.zip
Merge branch 'main' into release-branch/1.0v1.0.1
Diffstat (limited to 'version/cmdname.go')
-rw-r--r--version/cmdname.go26
1 files changed, 16 insertions, 10 deletions
diff --git a/version/cmdname.go b/version/cmdname.go
index 4e5280aff..a7899ed9f 100644
--- a/version/cmdname.go
+++ b/version/cmdname.go
@@ -9,6 +9,7 @@ package version
import (
"os"
"path"
+ "path/filepath"
"strings"
"rsc.io/goversion/version"
@@ -22,22 +23,27 @@ func CmdName() string {
if err != nil {
return "cmd"
}
+
+ // fallbackName, the lowercase basename of the executable, is what we return if
+ // we can't find the Go module metadata embedded in the file.
+ fallbackName := filepath.Base(strings.TrimSuffix(strings.ToLower(e), ".exe"))
+
var ret string
v, err := version.ReadExe(e)
if err != nil {
- ret = strings.TrimSuffix(strings.ToLower(e), ".exe")
- } else {
- // v is like:
- // "path\ttailscale.com/cmd/tailscale\nmod\ttailscale.com\t(devel)\t\ndep\tgithub.com/apenwarr/fixconsole\tv0.0.0-20191012055117-5a9f6489cc29\th1:muXWUcay7DDy1/hEQWrYlBy+g0EuwT70sBHg65SeUc4=\ndep\tgithub....
- for _, line := range strings.Split(v.ModuleInfo, "\n") {
- if strings.HasPrefix(line, "path\t") {
- ret = path.Base(strings.TrimPrefix(line, "path\t"))
- break
- }
+ return fallbackName
+ }
+ // v is like:
+ // "path\ttailscale.com/cmd/tailscale\nmod\ttailscale.com\t(devel)\t\ndep\tgithub.com/apenwarr/fixconsole\tv0.0.0-20191012055117-5a9f6489cc29\th1:muXWUcay7DDy1/hEQWrYlBy+g0EuwT70sBHg65SeUc4=\ndep\tgithub....
+ for _, line := range strings.Split(v.ModuleInfo, "\n") {
+ if strings.HasPrefix(line, "path\t") {
+ goPkg := strings.TrimPrefix(line, "path\t") // like "tailscale.com/cmd/tailscale"
+ ret = path.Base(goPkg) // goPkg is always forward slashes; use path, not filepath
+ break
}
}
if ret == "" {
- return "cmd"
+ return fallbackName
}
return ret
}