Skip to content

Commit 82cf559

Browse files
volume: do not strip trailing characters from names (#3073)
Only remove `:ro` or `:rw` suffixes in their entirety; do not strip arbitrary `r` / `o` / `w` / `:` characters individually. Signed-off-by: Loïc Leyendecker <[email protected]>
1 parent 8590eaa commit 82cf559

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

docker/models/containers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,10 @@ def _host_volume_from_bind(bind):
11471147
bits = rest.split(':', 1)
11481148
if len(bits) == 1 or bits[1] in ('ro', 'rw'):
11491149
return drive + bits[0]
1150+
elif bits[1].endswith(':ro') or bits[1].endswith(':rw'):
1151+
return bits[1][:-3]
11501152
else:
1151-
return bits[1].rstrip(':ro').rstrip(':rw')
1153+
return bits[1]
11521154

11531155

11541156
ExecResult = namedtuple('ExecResult', 'exit_code,output')

tests/unit/models_containers_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def test_create_container_args(self):
103103
volumes=[
104104
'/home/user1/:/mnt/vol2',
105105
'/var/www:/mnt/vol1:ro',
106-
'volumename:/mnt/vol3',
106+
'volumename:/mnt/vol3r',
107107
'/volumewithnohostpath',
108108
'/anothervolumewithnohostpath:ro',
109109
'C:\\windows\\path:D:\\hello\\world:rw'
@@ -123,7 +123,7 @@ def test_create_container_args(self):
123123
'Binds': [
124124
'/home/user1/:/mnt/vol2',
125125
'/var/www:/mnt/vol1:ro',
126-
'volumename:/mnt/vol3',
126+
'volumename:/mnt/vol3r',
127127
'/volumewithnohostpath',
128128
'/anothervolumewithnohostpath:ro',
129129
'C:\\windows\\path:D:\\hello\\world:rw'
@@ -198,7 +198,7 @@ def test_create_container_args(self):
198198
volumes=[
199199
'/mnt/vol2',
200200
'/mnt/vol1',
201-
'/mnt/vol3',
201+
'/mnt/vol3r',
202202
'/volumewithnohostpath',
203203
'/anothervolumewithnohostpath',
204204
'D:\\hello\\world'

0 commit comments

Comments
 (0)