Skip to content

Commit 087594e

Browse files
committed
workaround for Singularity + InitialWorkDirRequriement
Does cause increased IO for writable: True
1 parent e6dd92a commit 087594e

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

cwltool/singularity.py

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os.path
66
import re
77
import shutil
8+
import stat
89
import sys
910
from io import open # pylint: disable=redefined-builtin
1011
from typing import Dict, List, MutableMapping, Optional
@@ -170,18 +171,36 @@ def add_volumes(self, pathmapper, runtime, stage_output):
170171
containertgt = container_outdir + vol.target[len(host_outdir):]
171172
else:
172173
containertgt = vol.target
173-
if vol.target.startswith(container_outdir + "/"):
174-
host_outdir_tgt = os.path.join(
175-
host_outdir, vol.target[len(container_outdir) + 1:])
176174
if vol.type in ("File", "Directory"):
177-
178-
if not vol.resolved.startswith("_:"):
175+
if vol.target.startswith(container_outdir + "/"):
176+
# workaround for lack of overlapping mounts in Singularity
177+
# revert to daa923d5b0be3819b6ed0e6440e7193e65141052
178+
# once https://github.com/sylabs/singularity/issues/1607
179+
# is fixed
180+
target = os.path.join(
181+
self.outdir, os.path.basename(vol.target))
182+
os.link(os.path.realpath(vol.resolved), target)
183+
os.chmod(target, stat.S_IRUSR)
184+
elif not vol.resolved.startswith("_:"):
179185
runtime.append(u"--bind")
180186
runtime.append("{}:{}:ro".format(
181187
docker_windows_path_adjust(vol.resolved),
182188
docker_windows_path_adjust(containertgt)))
183189
elif vol.type == "WritableFile":
184-
if self.inplace_update:
190+
if containertgt.startswith(container_outdir + "/"):
191+
# workaround for lack of overlapping mounts in Singularity
192+
# revert to daa923d5b0be3819b6ed0e6440e7193e65141052
193+
# once https://github.com/sylabs/singularity/issues/1607
194+
# is fixed
195+
target = os.path.join(
196+
self.outdir, os.path.basename(containertgt))
197+
if self.inplace_update:
198+
os.link(os.path.realpath(vol.resolved), target)
199+
os.chmod(target, stat.S_IRUSR | stat.S_IWUSR)
200+
else:
201+
shutil.copy(vol.resolved, target)
202+
ensure_writable(target)
203+
elif self.inplace_update:
185204
runtime.append(u"--bind")
186205
runtime.append(u"{}:{}:rw".format(
187206
docker_windows_path_adjust(vol.resolved),
@@ -193,7 +212,19 @@ def add_volumes(self, pathmapper, runtime, stage_output):
193212
if vol.resolved.startswith("_:") and host_outdir_tgt:
194213
os.makedirs(host_outdir_tgt, 0o0755)
195214
else:
196-
if self.inplace_update:
215+
if containertgt.startswith(container_outdir + "/"):
216+
# workaround for lack of overlapping mounts in Singularity
217+
# revert to daa923d5b0be3819b6ed0e6440e7193e65141052
218+
# once https://github.com/sylabs/singularity/issues/1607
219+
# is fixed
220+
target = os.path.join(
221+
self.outdir, os.path.basename(containertgt))
222+
if self.inplace_update:
223+
os.link(os.path.realpath(vol.resolved), target)
224+
os.chmod(target, stat.S_IRUSR | stat.S_IWUSR)
225+
else:
226+
shutil.copytree(vol.resolved, target)
227+
elif self.inplace_update:
197228
runtime.append(u"--bind")
198229
runtime.append(u"{}:{}:rw".format(
199230
docker_windows_path_adjust(vol.resolved),

0 commit comments

Comments
 (0)