Skip to content

Commit

Permalink
SwarmContainer: escape occurrences of {{ in mount paths
Browse files Browse the repository at this point in the history
  • Loading branch information
mlin committed Jul 25, 2020
1 parent 57ac4b3 commit cf526fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions WDL/runtime/task_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ def touch_mount_point(container_file: str) -> None:
with open(host_file, "x") as _:
pass

def escape(s):
# docker processes {{ interpolations }}
return s.replace("{{", '{{"{{"}}')

mounts = []
# mount input files and command
if self._bind_input_files:
Expand All @@ -561,12 +565,14 @@ def touch_mount_point(container_file: str) -> None:
perm_warn = False
touch_mount_point(container_path)
mounts.append(
docker.types.Mount(container_path, host_path, type="bind", read_only=True)
docker.types.Mount(
escape(container_path), escape(host_path), type="bind", read_only=True
)
)
mounts.append(
docker.types.Mount(
os.path.join(self.container_dir, "command"),
os.path.join(self.host_dir, "command"),
escape(os.path.join(self.container_dir, "command")),
escape(os.path.join(self.host_dir, "command")),
type="bind",
read_only=True,
)
Expand All @@ -576,15 +582,15 @@ def touch_mount_point(container_file: str) -> None:
touch_mount_point(os.path.join(self.container_dir, pipe_file))
mounts.append(
docker.types.Mount(
os.path.join(self.container_dir, pipe_file),
os.path.join(self.host_dir, pipe_file),
escape(os.path.join(self.container_dir, pipe_file)),
escape(os.path.join(self.host_dir, pipe_file)),
type="bind",
)
)
mounts.append(
docker.types.Mount(
os.path.join(self.container_dir, "work"),
os.path.join(self.host_dir, "work"),
escape(os.path.join(self.container_dir, "work")),
escape(os.path.join(self.host_dir, "work")),
type="bind",
)
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_7runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def test_weird_filenames(self):
filenames.append(c)
filenames.append(c + ''.join(random.choices(chars,k=11)))
assert filenames == list(sorted(filenames))
filenames.append('ThisIsAVeryLongFilename abc...xzy1234567890!@నేనుÆды.test.ext')
filenames.append('ThisIs{{AVeryLongFilename }}abc...}}xzy1234567890!@{{నేనుÆды.test.ext')

inputs = {"files": []}
for fn in filenames:
Expand Down

0 comments on commit cf526fc

Please sign in to comment.