From c4ac9c06c7e7d873c2add31bead03b5b863f944f Mon Sep 17 00:00:00 2001 From: Jose Miguel Parrella Date: Sat, 1 Feb 2020 17:53:54 +0100 Subject: [PATCH] Add a test if $PWD is available in the container In some cases the current directory is not available in a container. Until now if such scenario happened, then Toolbox would fail silently. The introduced test uses the 'test' utility to check if the current working directory is available. See: #370 Closes: #369 --- cmd/run.go | 10 ++++++++++ toolbox.sh | 8 ++++++++ 2 files changed, 18 insertions(+) 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