Skip to content

Commit 8171595

Browse files
authored
[path with spaces] run scripts for projects with paths in spaces (#1924)
## Summary Related to #1914 Ran into this scenario during further testing ## How was it tested? move the plugins examples: `mv devbox/examples "devbox/examples with plugins"` `cd examples/plugins with spaces/v2-github` `devbox run run_test` -> this would previously fail
1 parent 7f1fc7c commit 8171595

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

internal/devbox/devbox.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func (d *Devbox) RunScript(ctx context.Context, cmdName string, cmdArgs []string
282282
env["DEVBOX_RUN_CMD"] = strings.Join(append([]string{cmdName}, cmdArgs...), " ")
283283
}
284284

285-
return nix.RunScript(d.projectDir, strings.Join(cmdWithArgs, " "), env)
285+
return nix.RunScript(d.projectDir, cmdWithArgs, env)
286286
}
287287

288288
// Install ensures that all the packages in the config are installed

internal/nix/run.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import (
88
"fmt"
99
"os"
1010
"os/exec"
11+
"strings"
1112

1213
"go.jetpack.io/devbox/internal/boxcli/usererr"
1314
"go.jetpack.io/devbox/internal/cmdutil"
1415
"go.jetpack.io/devbox/internal/debug"
1516
)
1617

17-
func RunScript(projectDir, cmdWithArgs string, env map[string]string) error {
18-
if cmdWithArgs == "" {
18+
func RunScript(projectDir string, cmdWithArgs []string, env map[string]string) error {
19+
if len(cmdWithArgs) == 0 {
1920
return errors.New("attempted to run an empty command or script")
2021
}
2122

@@ -24,9 +25,13 @@ func RunScript(projectDir, cmdWithArgs string, env map[string]string) error {
2425
envPairs = append(envPairs, fmt.Sprintf("%s=%s", k, v))
2526
}
2627

28+
// Wrap in quotations since the command's path may contain spaces.
29+
cmdWithArgs[0] = "\"" + cmdWithArgs[0] + "\""
30+
cmdWithArgsStr := strings.Join(cmdWithArgs, " ")
31+
2732
// Try to find sh in the PATH, if not, default to a well known absolute path.
2833
shPath := cmdutil.GetPathOrDefault("sh", "/bin/sh")
29-
cmd := exec.Command(shPath, "-c", cmdWithArgs)
34+
cmd := exec.Command(shPath, "-c", cmdWithArgsStr)
3035
cmd.Env = envPairs
3136
cmd.Dir = projectDir
3237
cmd.Stdin = os.Stdin

0 commit comments

Comments
 (0)