From d1319c0a2c40ba868481830f298cebb48f7432cc Mon Sep 17 00:00:00 2001 From: Sylvie Crowe <107814465+oneirocosm@users.noreply.github.com> Date: Sat, 30 Dec 2023 22:52:30 -0800 Subject: [PATCH] Fix Commands that Require Quoted Paths (#198) * fix commands that require quoted paths Several commands did not wrap the path in quotes which caused problems when attempting to store the waveterm installation in a place that had a space in the path. This corrects this in the particular case where the username does not have spaces but the path to the executable does. Note: the case of a user name having spaces has not been tested but likely does not work. * fix logging problem for wavesrv A previous fix replaced the getWaveSrvCmd with getWaveSrvPath. This needs to be getWaveSrvCmd to enable logging. * fix variable name --- src/electron/emain.ts | 13 +++++++------ wavesrv/pkg/remote/remote.go | 5 +++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/electron/emain.ts b/src/electron/emain.ts index d4819add6..c31d3912c 100644 --- a/src/electron/emain.ts +++ b/src/electron/emain.ts @@ -140,7 +140,7 @@ function getWaveSrvCmd() { let waveSrvPath = getWaveSrvPath(); let waveHome = getWaveHomeDir(); let logFile = path.join(waveHome, "wavesrv.log"); - return `${waveSrvPath} >> "${logFile}" 2>&1`; + return `"${waveSrvPath}" >> "${logFile}" 2>&1`; } function getWaveSrvCwd() { @@ -540,8 +540,8 @@ function sendWSSC() { } function runWaveSrv() { - let pResolve = null; - let pReject = null; + let pResolve: (value: unknown) => void; + let pReject: (reason?: any) => void; let rtnPromise = new Promise((argResolve, argReject) => { pResolve = argResolve; pReject = argReject; @@ -551,8 +551,9 @@ function runWaveSrv() { if (isDev) { envCopy[WaveDevVarName] = "1"; } - console.log("trying to run local server", getWaveSrvPath()); - let proc = child_process.spawn("bash", ["-c", getWaveSrvCmd()], { + let waveSrvCmd = getWaveSrvCmd(); + console.log("trying to run local server", waveSrvCmd); + let proc = child_process.spawn("bash", ["-c", waveSrvCmd], { cwd: getWaveSrvCwd(), env: envCopy, }); @@ -560,7 +561,7 @@ function runWaveSrv() { console.log("wavesrv exit", e); waveSrvProc = null; sendWSSC(); - pReject(new Error(sprintf("failed to start local server (%s)", getWaveSrvPath()))); + pReject(new Error(sprintf("failed to start local server (%s)", waveSrvCmd))); if (waveSrvShouldRestart) { waveSrvShouldRestart = false; this.runWaveSrv(); diff --git a/wavesrv/pkg/remote/remote.go b/wavesrv/pkg/remote/remote.go index 7b6b5cbf7..145920962 100644 --- a/wavesrv/pkg/remote/remote.go +++ b/wavesrv/pkg/remote/remote.go @@ -21,6 +21,7 @@ import ( "syscall" "time" + "github.com/alessio/shellescape" "github.com/armon/circbuf" "github.com/creack/pty" "github.com/google/uuid" @@ -66,9 +67,9 @@ func MakeLocalMShellCommandStr(isSudo bool) (string, error) { return "", err } if isSudo { - return fmt.Sprintf(`%s; sudo %s --server`, PrintPingPacket, mshellPath), nil + return fmt.Sprintf(`%s; sudo %s --server`, PrintPingPacket, shellescape.Quote(mshellPath)), nil } else { - return fmt.Sprintf(`%s; %s --server`, PrintPingPacket, mshellPath), nil + return fmt.Sprintf(`%s; %s --server`, PrintPingPacket, shellescape.Quote(mshellPath)), nil } }