Skip to content

Commit 7bfd771

Browse files
tiborsimkotetron
authored andcommitted
Use default mask in os.makedirs() (#1081) (#1082)
* Amends `os.makedirs()` calls to use the default mask value (`0o777`) so that temporary directories and files created by `cwltool` would better respect the umask settings from the original environment. For example, the parent environment might use umask 002 to make sure that all directories and files are created with group-write permissions. Signed-off-by: Tibor Simko <[email protected]>
1 parent 0d1fb3f commit 7bfd771

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

cwltool/docker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def add_writable_directory_volume(self,
259259
self.append_volume(runtime, new_dir, volume.target,
260260
writable=True)
261261
elif not os.path.exists(host_outdir_tgt):
262-
os.makedirs(host_outdir_tgt, 0o0755)
262+
os.makedirs(host_outdir_tgt)
263263
else:
264264
if self.inplace_update:
265265
self.append_volume(runtime, volume.resolved, volume.target,

cwltool/job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def create_file_and_add_volume(self,
533533
contents = volume.resolved
534534
dirname = os.path.dirname(host_outdir_tgt or new_file)
535535
if not os.path.exists(dirname):
536-
os.makedirs(dirname, 0o0755)
536+
os.makedirs(dirname)
537537
with open(host_outdir_tgt or new_file, "wb") as file_literal:
538538
file_literal.write(contents.encode("utf-8"))
539539
if not host_outdir_tgt:

cwltool/process.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def stage_files(pathmapper, # type: PathMapper
225225
if not entry.staged:
226226
continue
227227
if not os.path.exists(os.path.dirname(entry.target)):
228-
os.makedirs(os.path.dirname(entry.target), 0o0755)
228+
os.makedirs(os.path.dirname(entry.target))
229229
if entry.type in ("File", "Directory") and os.path.exists(entry.resolved):
230230
if symlink: # Use symlink func if allowed
231231
if onWindows():
@@ -242,13 +242,13 @@ def stage_files(pathmapper, # type: PathMapper
242242
stage_func(entry.resolved, entry.target)
243243
elif entry.type == "Directory" and not os.path.exists(entry.target) \
244244
and entry.resolved.startswith("_:"):
245-
os.makedirs(entry.target, 0o0755)
245+
os.makedirs(entry.target)
246246
elif entry.type == "WritableFile" and not ignore_writable:
247247
shutil.copy(entry.resolved, entry.target)
248248
ensure_writable(entry.target)
249249
elif entry.type == "WritableDirectory" and not ignore_writable:
250250
if entry.resolved.startswith("_:"):
251-
os.makedirs(entry.target, 0o0755)
251+
os.makedirs(entry.target)
252252
else:
253253
shutil.copytree(entry.resolved, entry.target)
254254
ensure_writable(entry.target)

cwltool/singularity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def add_writable_directory_volume(self,
226226
new_dir = os.path.join(
227227
tempfile.mkdtemp(prefix=tmp_prefix, dir=tmp_dir),
228228
os.path.basename(volume.resolved))
229-
os.makedirs(new_dir, 0o0755)
229+
os.makedirs(new_dir)
230230
else:
231231
if host_outdir_tgt is not None:
232232
# workaround for lack of overlapping mounts in Singularity

tests/test_examples.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import logging
33
import os
4+
import stat
45
import sys
56
from io import BytesIO, StringIO
67
import pytest
@@ -792,10 +793,15 @@ class TestSecondaryFiles():
792793
def test_secondary_files(self):
793794
test_file = "secondary-files.cwl"
794795
test_job_file = "secondary-files-job.yml"
795-
error_code, _, stderr = get_main_output(
796-
["--enable-dev",
797-
get_data(os.path.join("tests", test_file)),
798-
get_data(os.path.join("tests", test_job_file))])
796+
try:
797+
old_umask = os.umask(stat.S_IWOTH) # test run with umask 002
798+
error_code, _, stderr = get_main_output(
799+
["--enable-dev",
800+
get_data(os.path.join("tests", test_file)),
801+
get_data(os.path.join("tests", test_job_file))])
802+
finally:
803+
assert stat.S_IMODE(os.stat('lsout').st_mode) == 436 # 664 in octal, '-rw-rw-r--'
804+
os.umask(old_umask) # revert back to original umask
799805
assert "completed success" in stderr
800806
assert error_code == 0
801807

0 commit comments

Comments
 (0)