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 <apenwarr@tailscale.com>
This commit is contained in:
Avery Pennarun 2020-07-30 02:59:06 -04:00
parent 2ce2b63239
commit f81233524f
1 changed files with 3 additions and 2 deletions

View File

@ -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
}
}