From bc6b3f970b5fd0fa646dbf166d02d16b556731c5 Mon Sep 17 00:00:00 2001 From: Mazz Mosley Date: Tue, 13 Oct 2015 17:03:09 +0100 Subject: [PATCH 1/2] container paths don't need to be expanded They should not ever be relative. Signed-off-by: Mazz Mosley --- compose/config/config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/compose/config/config.py b/compose/config/config.py index 9e9cb857fbf..373299fd876 100644 --- a/compose/config/config.py +++ b/compose/config/config.py @@ -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) if host_path is not None: if host_path.startswith('.'): From c1d5ecaafe3e2e7b1f06342cbeeaef77d72fbac5 Mon Sep 17 00:00:00 2001 From: Mazz Mosley Date: Tue, 13 Oct 2015 17:27:25 +0100 Subject: [PATCH 2/2] Workaround splitdrive limitations splitdrive doesn't handle relative paths, so if volume_path contains a relative path, we handle that differently and manually set drive to ''. Signed-off-by: Mazz Mosley --- compose/config/config.py | 13 ++++++++++++- tests/unit/config/config_test.py | 1 - 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/compose/config/config.py b/compose/config/config.py index 373299fd876..adba3bda50c 100644 --- a/compose/config/config.py +++ b/compose/config/config.py @@ -526,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) diff --git a/tests/unit/config/config_test.py b/tests/unit/config/config_test.py index d3fb4d5f17b..0028210559e 100644 --- a/tests/unit/config/config_test.py +++ b/tests/unit/config/config_test.py @@ -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'])