Skip to content

Commit 60f7e02

Browse files
committed
Fix split_path_mapping behavior when mounting "/"
Signed-off-by: Joffrey F <joffrey@docker.com>
1 parent e502417 commit 60f7e02

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

compose/config/config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -940,9 +940,10 @@ def split_path_mapping(volume_path):
940940
path. Using splitdrive so windows absolute paths won't cause issues with
941941
splitting on ':'.
942942
"""
943-
# splitdrive has limitations when it comes to relative paths, so when it's
944-
# relative, handle special case to set the drive to ''
945-
if volume_path.startswith('.') or volume_path.startswith('~'):
943+
# splitdrive is very naive, so handle special cases where we can be sure
944+
# the first character is not a drive.
945+
if (volume_path.startswith('.') or volume_path.startswith('~') or
946+
volume_path.startswith('/')):
946947
drive, volume_config = '', volume_path
947948
else:
948949
drive, volume_config = ntpath.splitdrive(volume_path)

tests/unit/config/config_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,6 +2682,13 @@ def test_split_path_mapping_with_windows_path_in_container(self):
26822682
mapping = config.split_path_mapping('{0}:{1}'.format(host_path, container_path))
26832683
assert mapping == expected_mapping
26842684

2685+
def test_split_path_mapping_with_root_mount(self):
2686+
host_path = '/'
2687+
container_path = '/var/hostroot'
2688+
expected_mapping = (container_path, host_path)
2689+
mapping = config.split_path_mapping('{0}:{1}'.format(host_path, container_path))
2690+
assert mapping == expected_mapping
2691+
26852692

26862693
@pytest.mark.xfail(IS_WINDOWS_PLATFORM, reason='paths use slash')
26872694
class BuildPathTest(unittest.TestCase):

0 commit comments

Comments
 (0)