Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions compose/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@ def resolve_volume_paths(service_dict, working_dir=None):

def resolve_volume_path(volume, working_dir, service_name):
container_path, host_path = split_path_mapping(volume)
container_path = os.path.expanduser(container_path)

Copy link

Choose a reason for hiding this comment

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

Oh wait, why is this removed?

Copy link
Author

Choose a reason for hiding this comment

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

Because container_path should never be relative, so we don't need to call expanduser on it. @aanand spotted it last time when I was working through understanding the paths situation.

Copy link

Choose a reason for hiding this comment

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

I guess it would expand to the wrong path, that's true. We added this in 1.4.0, so we should probably call this out in the release notes as a bug fix.

if host_path is not None:
if host_path.startswith('.'):
Expand Down Expand Up @@ -527,7 +526,18 @@ def path_mappings_from_dict(d):


def split_path_mapping(volume_path):
drive, volume_config = os.path.splitdrive(volume_path)
"""
Ascertain if the volume_path contains a host path as well as a container
path. Using splitdrive so windows absolute paths won't cause issues with
splitting on ':'.
"""
# splitdrive has limitations when it comes to relative paths, so when it's
# relative, handle special case to set the drive to ''
if volume_path.startswith('.') or volume_path.startswith('~'):
drive, volume_config = '', volume_path
else:
drive, volume_config = os.path.splitdrive(volume_path)

if ':' in volume_config:
(host, container) = volume_config.split(':', 1)
return (container, drive + host)
Expand Down
1 change: 0 additions & 1 deletion tests/unit/config/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ def test_relative_path_does_expand_posix(self):
self.assertEqual(d['volumes'], ['/home/me/otherproject:/data'])

@pytest.mark.skipif(not IS_WINDOWS_PLATFORM, reason='windows paths')
@pytest.mark.skipif(IS_WINDOWS_PLATFORM, reason='waiting for this to be resolved: https://github.com/docker/compose/issues/2128')
def test_relative_path_does_expand_windows(self):
d = make_service_dict('foo', {'build': '.', 'volumes': ['./data:/data']}, working_dir='C:\\Users\\me\\myproject')
self.assertEqual(d['volumes'], ['C:\\Users\\me\\myproject\\data:/data'])
Expand Down