Skip to content

Commit 75e4c3b

Browse files
author
Peter Amstutz
committed
Ensure that files copied for update are writable.
1 parent a73d5bf commit 75e4c3b

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

cwltool/job.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from .builder import Builder
2222
from .docker_id import docker_vm_id
2323
from .errors import WorkflowException
24-
from .pathmapper import PathMapper
24+
from .pathmapper import PathMapper, ensure_writable
2525
from .process import (UnsupportedRequirement, empty_subtree, get_feature,
2626
stageFiles)
2727
from .utils import bytes2str_in_dicts
@@ -113,7 +113,7 @@ def relink_initialworkdir(pathmapper, host_outdir, container_outdir, inplace_upd
113113
shutil.rmtree(host_outdir_tgt)
114114
if onWindows():
115115
if vol.type in ("File", "WritableFile"):
116-
shutil.copy(vol.resolved,host_outdir_tgt)
116+
shutil.copy(vol.resolved, host_outdir_tgt)
117117
elif vol.type in ("Directory", "WritableDirectory"):
118118
copytree_with_merge(vol.resolved, host_outdir_tgt)
119119
else:
@@ -332,6 +332,7 @@ def add_volumes(self, pathmapper, runtime):
332332
runtime.append(u"--volume=%s:%s:rw" % (docker_windows_path_adjust(vol.resolved), docker_windows_path_adjust(vol.target)))
333333
else:
334334
shutil.copy(vol.resolved, host_outdir_tgt)
335+
ensure_writable(host_outdir_tgt)
335336
elif vol.type == "WritableDirectory":
336337
if vol.resolved.startswith("_:"):
337338
os.makedirs(vol.target, 0o0755)
@@ -340,6 +341,7 @@ def add_volumes(self, pathmapper, runtime):
340341
runtime.append(u"--volume=%s:%s:rw" % (docker_windows_path_adjust(vol.resolved), docker_windows_path_adjust(vol.target)))
341342
else:
342343
shutil.copytree(vol.resolved, host_outdir_tgt)
344+
ensure_writable(host_outdir_tgt)
343345
elif vol.type == "CreateFile":
344346
if host_outdir_tgt:
345347
with open(host_outdir_tgt, "wb") as f:

cwltool/pathmapper.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,24 @@ def downloadHttpFile(httpurl):
168168
r.close()
169169
return f.name
170170

171+
def ensure_writable(path):
172+
if os.path.isdir(path):
173+
for root, dirs, files in os.walk(path):
174+
for name in files:
175+
j = os.path.join(root, name)
176+
st = os.stat(j)
177+
mode = stat.S_IMODE(st.st_mode)
178+
os.chmod(j, mode|stat.S_IWUSR)
179+
for name in dirs:
180+
j = os.path.join(root, name)
181+
st = os.stat(j)
182+
mode = stat.S_IMODE(st.st_mode)
183+
os.chmod(j, mode|stat.S_IWUSR)
184+
else:
185+
st = os.stat(path)
186+
mode = stat.S_IMODE(st.st_mode)
187+
os.chmod(path, mode|stat.S_IWUSR)
188+
171189
class PathMapper(object):
172190
"""Mapping of files from relative path provided in the file to a tuple of
173191
(absolute local path, absolute container path)

cwltool/process.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
from .builder import Builder
3535
from .errors import UnsupportedRequirement, WorkflowException
3636
from .pathmapper import (PathMapper, adjustDirObjs, get_listing,
37-
normalizeFilesDirs, visit_class, trim_listing)
37+
normalizeFilesDirs, visit_class, trim_listing,
38+
ensure_writable)
3839
from .stdfsaccess import StdFsAccess
3940
from .utils import aslist, get_feature, copytree_with_merge, onWindows
4041

@@ -230,15 +231,17 @@ def stageFiles(pm, stageFunc=None, ignoreWritable=False, symLink=True):
230231
os.makedirs(p.target, 0o0755)
231232
elif p.type == "WritableFile" and not ignoreWritable:
232233
shutil.copy(p.resolved, p.target)
234+
ensure_writable(p.target)
233235
elif p.type == "WritableDirectory" and not ignoreWritable:
234236
if p.resolved.startswith("_:"):
235237
os.makedirs(p.target, 0o0755)
236238
else:
237239
shutil.copytree(p.resolved, p.target)
240+
ensure_writable(p.target)
238241
elif p.type == "CreateFile":
239242
with open(p.target, "wb") as n:
240243
n.write(p.resolved.encode("utf-8"))
241-
244+
ensure_writable(p.target)
242245

243246
def collectFilesAndDirs(obj, out):
244247
# type: (Union[Dict[Text, Any], List[Dict[Text, Any]]], List[Dict[Text, Any]]) -> None

0 commit comments

Comments
 (0)