-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Improve volumespec parsing on windows platforms #3922
Conversation
return ('', '') | ||
if path[0] in ['.', '\\', '/', '~']: | ||
return ('', path) | ||
return ntpath.splitdrive(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, we expand volume host paths in compose.config.config.process_service()
before we get to VolumeSpec.parse()
. So paths here shouldn't ever start with .
or ~
. Or is VolumeSpec.parse()
used in other contexts where paths might be relative?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that shouldn't be an issue in that scenario. I think it's still nice to have a splitdrive
function that can handle those corner cases and be used elsewhere, however, but if you feel strongly about it I can remove those from the list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved splitdrive
to compose.utils
so we can use it in both VolumeSpec.parse
and compose.config.split_path_mapping
, with the latter occuring before the path expansion.
if external_path: | ||
external_path = _normalize(external_path) | ||
|
||
return external_path, _normalize(internal_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is normalize_paths_for_engine()
still a useful function? Seems like we could just move _normalize()
up to the top level (maybe renaming it to normalize_path_for_engine()
, singular) and invoke it directly from VolumeSpec._parse_win32()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right, we could do without it.
os.path.normpath(external), os.path.normpath(parts[0]) | ||
) | ||
if len(parts) > 1: | ||
mode = parts[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there's some repeated logic here where we call splitdrive
, call split(':')
on the tail, then prepend the drive onto the first part. Could it be factored out into a helper function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
a0b426c
to
6292024
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after the comment is removed!
@@ -944,11 +944,7 @@ def split_path_mapping(volume_path): | |||
""" | |||
# splitdrive is very naive, so handle special cases where we can be sure | |||
# the first character is not a drive. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment is now untrue.
Signed-off-by: Joffrey F <joffrey@docker.com>
6292024
to
7911659
Compare
Fixes #3897