From f81233524fddeec450940af8dc1a0dd8841bf28c Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Thu, 30 Jul 2020 02:59:06 -0400 Subject: [PATCH] version/cmdname: s/path/filepath/ and fix version.ReadExe() fallback. We were using the Go 'path' module, which apparently doesn't handle backslashes correctly. path/filepath does. However, the main bug turned out to be that we were not calling .Base() on the path if version.ReadExe() fails, which it seems to do at least on Windows 7. As a result, our logfile persistence was not working on Windows, and logids would be regenerated on every restart. Affects: #620 Signed-off-by: Avery Pennarun --- version/cmdname.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/version/cmdname.go b/version/cmdname.go index 4e5280aff..a72eb9c21 100644 --- a/version/cmdname.go +++ b/version/cmdname.go @@ -8,7 +8,7 @@ package version import ( "os" - "path" + "path/filepath" "strings" "rsc.io/goversion/version" @@ -26,12 +26,13 @@ func CmdName() string { v, err := version.ReadExe(e) if err != nil { ret = strings.TrimSuffix(strings.ToLower(e), ".exe") + ret = filepath.Base(ret) } 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")) + ret = filepath.Base(strings.TrimPrefix(line, "path\t")) break } }