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

Don't convert slashes for UNIX paths on Windows hosts #6204

Merged
merged 1 commit into from
Sep 21, 2018

Conversation

shin-
Copy link

@shin- shin- commented Sep 19, 2018

@shin- shin- added this to the 1.23.0 milestone Sep 19, 2018
Signed-off-by: Joffrey F <joffrey@docker.com>
@shin- shin- force-pushed the 5716-unix-paths-from-winhost branch from 34c37f9 to 9f9122c Compare September 19, 2018 18:37
""" Custom path normalizer that handles Compose-specific edge cases like
UNIX paths on Windows hosts and vice-versa. """

sysnorm = ntpath.normpath if win_host else os.path.normpath
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be:

-sysnorm = ntpath.normpath if win_host else os.path.normpath
+sysnorm = ntpath.normpath if win_host else posix.normpath

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

win_host will be true only if COMPOSE_FORCE_WINDOWS_HOST is set. In this case we want to produce NT style paths regardless of the client platform. In all other cases, we want to use the default normalization for the client system, hence the use of os.path.normpath

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we? If you have a compose on Windows talking to a remote linux engine?

@Dimrok
Copy link

Dimrok commented Sep 20, 2018

Just to note everything related to path here:

  • docker-compose runs on both Windows- and Unix-based distributions, so os.path.normpath can be either posixpath or ntpath.
  • the host can be Linux running Linux containers, Windows running Windows containers and Windows running Linux containers.
  • The volume definition can be <linux>:<linux>, <windows>:<linux> and <windows>:<windows>.
  • Docker for Widows running a Linux container has a proxy that does some path manipulation and validation:
    • if you write C:/foo/bar:/bar, the proxy will ensure the volume is mounted somewhere (/c/foo/bar) and translate the given path to /mnt/c/foo/bar (where the volume is mounted).
    • if you write /c/foo/bar:/bar, no validation is done but the path is still translated to /mnt/c/foo/bar (we don't want that, because if you forgot to mount the volume, /mnt/c/foo/bar will be created).
    • You can have both Posix and NT path (e.g. /var/run/docker.sock:/var/run/docker.sock and C:\\Users\\toto:/toto) for the same container. Docker for Windows understands absolute Linux path as being part of the host (in this case, bind-mounting the socket) unless they look like /<drive>/..., in this case, they are translate to /mnt/<drive>/....
    • An ill-formed path such as C:/foo/bar is translated to /mnt/c/foo/bar.
  • Docker for Windows running Windows containers doesn't manipulate paths.
  • Docker for Windows running Linux containers doesn't manipulate paths (to be verified).
  • Volume configuration like C:\\Users\\foo:C:\\foo works natively on Docker for Windows using Windows containers.
  • You can have multi-arch images so you have to be aware of the host's platform.

The point is: We shouldn't normalize the paths at all. The engine is clever enough to understand what you meant. Or if we really want to (e.g. to change /foo/bar/../shiny to /foo/shiny if we want to be fancy), we shouldn't change the type of paths the user provided.

@shin-
Copy link
Author

shin- commented Sep 20, 2018

I think you make a good point about not having to normalize paths ; that said, I'd want to do a thorough check first to make sure we're not breaking anything by doing so, and have a follow-up PR for that specifically. For the time being, if this fixes docker/for-win#1829, let's roll with it.

@Dimrok
Copy link

Dimrok commented Sep 21, 2018

let's roll with it.
👍

@shin- shin- merged commit 2a7beb6 into master Sep 21, 2018
@shin- shin- deleted the 5716-unix-paths-from-winhost branch October 4, 2018 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants