Commit bfb22d41 authored by Joe Lyons's avatar Joe Lyons 🚴
Browse files

Merge branch '14-fix-umask-issues' into 'master'

Resolve "Fix umask issues"

Closes #14

See merge request ynic-public/yias!8
parents 257b1b6c 769c44b9
Pipeline #1354 passed with stage
in 15 minutes and 1 second
image: debian:buster
- apt -qq update && apt -qq install -y python3-numpy python3-dicom python3-nibabel python3-pytest python3-pytest-cov dcm2niix git
......@@ -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