Skip to content

Commit

Permalink
Add a test if $PWD is available in the container
Browse files Browse the repository at this point in the history
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: containers#370
Closes: containers#369
  • Loading branch information
bureado authored and HarryMichal committed Mar 20, 2020
1 parent 5f1bcaa commit c4ac9c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions toolbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c4ac9c0

Please sign in to comment.