From 84f4d453d20db2fa64efb841be63bcf89a29324f Mon Sep 17 00:00:00 2001 From: Safihre Date: Fri, 21 Aug 2020 15:04:46 +0200 Subject: [PATCH] Permissions would be set even if user didn't set any Windows developers like me shouldn't do permissions stuff.. --- sabnzbd/filesystem.py | 13 +++++-------- tests/test_filesystem.py | 9 ++++++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/sabnzbd/filesystem.py b/sabnzbd/filesystem.py index 4746d3c..fbbc003 100644 --- a/sabnzbd/filesystem.py +++ b/sabnzbd/filesystem.py @@ -561,13 +561,10 @@ def create_all_dirs(path, apply_umask=False): else: # We need to build the directory recursively so we can # apply permissions to only the newly created folders - # We cannot use os.makedirs() to do this as it ignores the mode - try: - # Try the user permissions setting - umask = int(sabnzbd.cfg.umask(), 8) | int("0700", 8) - except: - # Use default - umask = int("0700", 8) + # We cannot use os.makedirs() as it could ignore the mode + umask = sabnzbd.cfg.umask() + if umask: + umask = int(umask, 8) | int("0700", 8) # Build path from root path_part_combined = "/" @@ -578,7 +575,7 @@ def create_all_dirs(path, apply_umask=False): if not os.path.exists(path_part_combined): os.mkdir(path_part_combined) # Try to set permissions if desired, ignore failures - if apply_umask: + if umask and apply_umask: set_chmod(path_part_combined, umask, report=False) return path except OSError: diff --git a/tests/test_filesystem.py b/tests/test_filesystem.py index c84248c..fcb3b17 100644 --- a/tests/test_filesystem.py +++ b/tests/test_filesystem.py @@ -786,6 +786,13 @@ class TestCreateAllDirs(ffs.TestCase, PermissionCheckerHelper): with pytest.raises(OSError): self._permissions_runner("/test_base450", perms_base="0450") + @set_config({"umask": ""}) + def test_no_umask(self): + self._permissions_runner("/test_base_perm700", perms_base="0700") + self._permissions_runner("/test_base_perm750", perms_base="0750") + self._permissions_runner("/test_base_perm777", perms_base="0777") + self._permissions_runner("/test_base_perm600", perms_base="0600") + def _permissions_runner(self, test_base, perms_base="0700", apply_umask=True): # Create base directory and set the base permissions perms_base_int = int(perms_base, 8) @@ -799,7 +806,7 @@ class TestCreateAllDirs(ffs.TestCase, PermissionCheckerHelper): # If permissions needed to be set, verify the new folder has the # right permissions and verify the base didn't change - if apply_umask: + if apply_umask and cfg.umask(): perms_test_int = int(cfg.umask(), 8) | int("0700", 8) else: # Get the current umask, since os.mkdir masks that out