Skip to content

Commit

Permalink
cmd: Jump to /run/host/$PWD when entering toolbox
Browse files Browse the repository at this point in the history
As a convenience to users, when entering a container
toolbx tries to maintain the working directory from
the host. This works great if the user is inside
their home directory, for instance, since the
home directory is shared between host and container.

It can be confusing in other cases, though. The issue
is that the directory in the container may have the
same path as the directory in the host, but have
completely different contents. The old contents may
actually be in /run/host/$PWD instead.

Switching to /run/host/$PWD unconditionally has its own
downsides. For one, it's ugly, and also, in common cases,
like subdirectories of the home directory, it's
unnecessary.

This commit tries to find the balance, by making toolbx
check first if the directory is shared between host and
container, and if not, only then falling back to trying
/run/host/$PWD.

Closes containers#988
  • Loading branch information
halfline committed Dec 19, 2022
1 parent fce8a3c commit a9e1f14
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ func runCommandWithFallbacks(container string, command []string, emitEscapeSeque
runFallbackCommandsIndex := 0
runFallbackWorkDirsIndex := 0
workDir := workingDirectory
runFallbackWorkDirs := append([]string{"/run/host" + workDir}, runFallbackWorkDirs...)

for {
execArgs := constructExecArgs(container, command, detachKeysSupported, envOptions, workDir)
Expand Down Expand Up @@ -522,7 +523,7 @@ func isPathPresent(container, path string) (bool, error) {
"exec",
"--user", currentUser.Username,
container,
"sh", "-c", "test -d \"$1\"", "sh", path,
"sh", "-c", "test -d \"$1\" -a \"$1\" -ef \"/run/host/$1\"", "sh", path,
}

if err := shell.Run("podman", nil, nil, nil, args...); err != nil {
Expand Down

0 comments on commit a9e1f14

Please sign in to comment.