Skip to content

Commit

Permalink
volume: do not strip trailing characters from names (#3073)
Browse files Browse the repository at this point in the history
Only remove `:ro` or `:rw` suffixes in their entirety; do not
strip arbitrary `r` / `o` / `w` / `:` characters individually.

Signed-off-by: Loïc Leyendecker <loic.leyendecker@gmail.com>
  • Loading branch information
loicleyendecker committed Dec 2, 2022
1 parent 8590eaa commit 82cf559
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion docker/models/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,8 +1147,10 @@ def _host_volume_from_bind(bind):
bits = rest.split(':', 1)
if len(bits) == 1 or bits[1] in ('ro', 'rw'):
return drive + bits[0]
elif bits[1].endswith(':ro') or bits[1].endswith(':rw'):
return bits[1][:-3]
else:
return bits[1].rstrip(':ro').rstrip(':rw')
return bits[1]


ExecResult = namedtuple('ExecResult', 'exit_code,output')
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/models_containers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_create_container_args(self):
volumes=[
'/home/user1/:/mnt/vol2',
'/var/www:/mnt/vol1:ro',
'volumename:/mnt/vol3',
'volumename:/mnt/vol3r',
'/volumewithnohostpath',
'/anothervolumewithnohostpath:ro',
'C:\\windows\\path:D:\\hello\\world:rw'
Expand All @@ -123,7 +123,7 @@ def test_create_container_args(self):
'Binds': [
'/home/user1/:/mnt/vol2',
'/var/www:/mnt/vol1:ro',
'volumename:/mnt/vol3',
'volumename:/mnt/vol3r',
'/volumewithnohostpath',
'/anothervolumewithnohostpath:ro',
'C:\\windows\\path:D:\\hello\\world:rw'
Expand Down Expand Up @@ -198,7 +198,7 @@ def test_create_container_args(self):
volumes=[
'/mnt/vol2',
'/mnt/vol1',
'/mnt/vol3',
'/mnt/vol3r',
'/volumewithnohostpath',
'/anothervolumewithnohostpath',
'D:\\hello\\world'
Expand Down

0 comments on commit 82cf559

Please sign in to comment.