Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a test for $PWD in the container #370

Merged
merged 1 commit into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,11 @@ func runCommand(container string,
case 126:
err = fmt.Errorf("failed to invoke command %s in container %s", command[0], container)
case 127:
err = fmt.Errorf("command %s not found in container %s", command[0], container)
if pathPresent, _ := isPathPresent(container, workingDirectory); !pathPresent {
err = fmt.Errorf("directory %s not found in container %s", workingDirectory, container)
} else {
err = fmt.Errorf("command %s not found in container %s", command[0], container)
}
default:
err = nil
}
Expand Down Expand Up @@ -398,6 +402,25 @@ func isCommandPresent(container, command string) (bool, error) {
return true, nil
}

func isPathPresent(container, path string) (bool, error) {
logrus.Debugf("Looking for path %s in container %s", path, container)

logLevelString := podman.LogLevel.String()
args := []string{
"--log-level", logLevelString,
"exec",
"--user", currentUser.Username,
container,
"sh", "-c", "test -d \"$1\"", "sh", path,
}

if err := shell.Run("podman", nil, nil, nil, args...); err != nil {
return false, err
}

return true, nil
}

func startContainer(container string) error {
var stderr strings.Builder
if err := podman.Start(container, &stderr); err == nil {
Expand Down
10 changes: 10 additions & 0 deletions toolbox
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,16 @@ run()

$emit_escape_sequence && printf "\033]777;container;pop;;\033\\"

if [ "$ret_val" -eq 127 ] 2>&3; then
# shellcheck disable=SC2016
if ! $podman_command exec \
--user "$USER" \
"$toolbox_container" \
sh -c 'test -d "$1"' sh "$PWD" >/dev/null 2>&3; then
echo "$base_toolbox_command: directory '$PWD' not found in container $toolbox_container" >&2
fi
fi

exit "$ret_val"
)

Expand Down