Skip to content

Improve volumespec parsing on windows platforms - #3922

Merged
shin- merged 1 commit into
docker:masterfrom
shin-:3897-volumespec_parse_win32
Sep 20, 2016
Merged

shin- merged 1 commit into
docker:masterfrom
shin-:3897-volumespec_parse_win32

Conversation

@shin-

@shin- shin- commented Sep 8, 2016

Copy link
Copy Markdown

Fixes #3897

Comment thread compose/config/types.py Outdated
return ('', '')
if path[0] in ['.', '\\', '/', '~']:
return ('', path)
return ntpath.splitdrive(path)

@aanand aanand Sep 19, 2016 •

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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.

Comment thread compose/config/types.py Outdated
if external_path:
external_path = _normalize(external_path)

return external_path, _normalize(internal_path)

Copy link
Copy Markdown

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
Copy Markdown
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.

Comment thread compose/config/types.py
os.path.normpath(external), os.path.normpath(parts[0])
)
if len(parts) > 1:
mode = parts[1]

Copy link
Copy Markdown

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
Copy Markdown
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

@aanand aanand left a comment

Copy link
Copy Markdown

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!

Comment thread compose/config/config.py Outdated
@@ -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
Copy Markdown

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.

@shin-
shin- force-pushed the 3897-volumespec_parse_win32 branch from 6292024 to 7911659 Compare September 20, 2016 18:24
@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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants