Commit b40a5feb authored by Mark Hymers's avatar Mark Hymers
Browse files

Fix makedirs_chmod to work properly

Signed-off-by: Mark Hymers's avatarMark Hymers <>
parent 257b1b6c
Pipeline #1351 failed with stage
in 9 seconds
......@@ -36,16 +36,18 @@ class TestMakedirsChmod:
tmpdir = str(tmpdir)
# Force umask to 0o777 to check that this works
very_orig_umask = umask(0o777)
# Force umask to 0o022 to check that this works
very_orig_umask = umask(0o022)
# Test creating a directory
makedirs_chmod(join(tmpdir, 'test1'), 0o755)
makedirs_chmod(join(tmpdir, 'test1', 'test2'), 0o757)
assert(isdir(join(tmpdir, 'test1')))
assert((stat(join(tmpdir, 'test1')).st_mode & 0o777) == 0o755)
assert(isdir(join(tmpdir, 'test1', 'test2')))
assert((stat(join(tmpdir, 'test1')).st_mode & 0o777) == 0o757)
assert((stat(join(tmpdir, 'test1', 'test2')).st_mode & 0o777) == 0o757)
# Check that the umask was restored
assert(umask(0o777) == 0o777)
assert(umask(0o022) == 0o022)
# Put back umask
......@@ -20,10 +20,10 @@ __all__.append('sanitise_string')
def ynic_fixup_studydesc(studydesc):
# Remove the e+DIGIT thing which GE does when modifying DICOM
# headers
studydesc = compile('^[eE][+-]\d+').sub('', studydesc)
studydesc = compile(r'^[eE][+-]\d+').sub('', studydesc)
# Remove the anonymisation flag and colon from our project name
g = compile('^([CcPp]\d+)[Aa]?:?(.*)').search(studydesc)
g = compile(r'^([CcPp]\d+)[Aa]?:?(.*)').search(studydesc)
if g:
grps = g.groups()
studydesc = grps[0]
......@@ -34,15 +34,16 @@ def ynic_fixup_studydesc(studydesc):
def makedirs_chmod(name, mode=0o777, exist_ok=False):
def makedirs_chmod(name, mode=0o755, exist_ok=False):
Equivalent to using os.makedirs but ensuring that umask is ignored if the
mode of the directory is set
original_umask = umask(0)
# Set the umask so that the intermediate directories are the
# same as the final directory
original_umask = umask(0o777 - mode)
return makedirs(name, mode, exist_ok)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment