diff --git a/cmd/run.go b/cmd/run.go index d2289d97f..017308d02 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -220,6 +220,16 @@ func run(args []string) error { logrus.Warn("Consider recreating it with Toolbox version 0.0.17 or newer") } + logrus.Info("Checking if the current working directory is in the container") + args = []string{"exec", + "--user", viper.GetString("USER"), + containerName, + "sh", "-c", fmt.Sprintf("test -d %s", viper.GetString("PWD"))} + err = podman.CmdRun(args...) + if err != nil { + logrus.Fatalf("Directory '%s' does not exist in container '%s', try running 'cd && !!'", viper.GetString("PWD"), containerName) + } + logrus.Infof("Looking for program '%s' in container %s", commands[0], containerName) args = []string{"exec", diff --git a/toolbox.sh b/toolbox.sh index 8726f255e..6bfb5392f 100755 --- a/toolbox.sh +++ b/toolbox.sh @@ -1581,6 +1581,14 @@ run() fi fi + if ! $podman_command exec \ + --user "$USER" \ + "$toolbox_container" \ + sh -c "test -d $PWD" >/dev/null 2>&3; then + echo "Directory $PWD does not exist in container $toolbox_container, try cd && !!" >&2 + exit 127 + fi + echo "$base_toolbox_command: running in container $toolbox_container:" >&3 echo "$base_toolbox_command: $program" >&3 for i in "$@"; do