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

Improve volumespec parsing on windows platforms #3922

Merged
merged 1 commit into from
Sep 20, 2016

Conversation

shin-
Copy link

@shin- shin- commented Sep 8, 2016

Fixes #3897

return ('', '')
if path[0] in ['.', '\\', '/', '~']:
return ('', path)
return ntpath.splitdrive(path)
Copy link

@aanand aanand Sep 19, 2016

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?

Copy link
Author

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.

Copy link
Author

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)
Copy link

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().

Copy link
Author

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]
Copy link

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?

Copy link
Author

Choose a reason for hiding this comment

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

Done!

@shin- shin- force-pushed the 3897-volumespec_parse_win32 branch 2 times, most recently from a0b426c to 6292024 Compare September 20, 2016 00:03
Copy link

@aanand aanand left a 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.
Copy link

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>
@shin- shin- merged commit 7687412 into docker:master Sep 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants