Browse Source

Permissions would be set even if user didn't set any

Windows developers like me shouldn't do permissions stuff..
tags/3.0.2RC1
Safihre 5 years ago
parent
commit
84f4d453d2
  1. 13
      sabnzbd/filesystem.py
  2. 9
      tests/test_filesystem.py

13
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:

9
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

Loading…
Cancel
Save