Skip to content

Commit

Permalink
tsh: use package filepath for working with file paths (#44782)
Browse files Browse the repository at this point in the history
We were using package path to date, which assumes a path separator
of '/' and does not work correctly on Windows.
  • Loading branch information
zmb3 authored Jul 31, 2024
1 parent 8e212a9 commit 8dc1aa9
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions tool/tsh/common/tsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"os"
"os/exec"
"os/signal"
"path"
"path/filepath"
"regexp"
"runtime"
Expand Down Expand Up @@ -559,7 +558,7 @@ func Main() {

// lets see: if the executable name is 'ssh' or 'scp' we convert
// that to "tsh ssh" or "tsh scp"
switch path.Base(os.Args[0]) {
switch filepath.Base(os.Args[0]) {
case "ssh":
cmdLine = append([]string{"ssh"}, cmdLineOrig...)
case "scp":
Expand Down Expand Up @@ -1727,7 +1726,7 @@ func onPlay(cf *CLIConf) error {

func exportSession(cf *CLIConf) error {
format := strings.ToLower(cf.Format)
isLocalFile := path.Ext(cf.SessionID) == ".tar"
isLocalFile := filepath.Ext(cf.SessionID) == ".tar"
if isLocalFile {
return trace.Wrap(exportFile(cf.Context, cf.SessionID, format))
}
Expand Down Expand Up @@ -1763,7 +1762,7 @@ func exportSession(cf *CLIConf) error {
}

func playSession(cf *CLIConf) error {
isLocalFile := path.Ext(cf.SessionID) == ".tar"
isLocalFile := filepath.Ext(cf.SessionID) == ".tar"
if isLocalFile {
sid := sessionIDFromPath(cf.SessionID)
tarFile, err := os.Open(cf.SessionID)
Expand Down Expand Up @@ -4991,10 +4990,10 @@ func serializeEnvironment(profile *client.ProfileStatus, format string) (string,
func setEnvFlags(cf *CLIConf) {
// these can only be set with env vars.
if homeDir := os.Getenv(types.HomeEnvVar); homeDir != "" {
cf.HomePath = path.Clean(homeDir)
cf.HomePath = filepath.Clean(homeDir)
}
if configPath := os.Getenv(globalTshConfigEnvVar); configPath != "" {
cf.GlobalTshConfigPath = path.Clean(configPath)
cf.GlobalTshConfigPath = filepath.Clean(configPath)
}

// prioritize CLI input for the rest.
Expand Down

0 comments on commit 8dc1aa9

Please sign in to comment.