From c2d1a5758146bb8b82e6c1c8f087d29721fb6b12 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Tue, 1 Jun 2021 00:50:18 -0400 Subject: [PATCH] fix umask dir permissions --- archivebox/config.py | 3 ++- archivebox/system.py | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/archivebox/config.py b/archivebox/config.py index 32b90609..17b9960c 100644 --- a/archivebox/config.py +++ b/archivebox/config.py @@ -337,6 +337,7 @@ DYNAMIC_CONFIG_SCHEMA: ConfigDefaultDict = { 'COOKIES_FILE': {'default': lambda c: c['COOKIES_FILE'] and Path(c['COOKIES_FILE']).resolve()}, 'CHROME_USER_DATA_DIR': {'default': lambda c: find_chrome_data_dir() if c['CHROME_USER_DATA_DIR'] is None else (Path(c['CHROME_USER_DATA_DIR']).resolve() if c['CHROME_USER_DATA_DIR'] else None)}, # None means unset, so we autodetect it with find_chrome_Data_dir(), but emptystring '' means user manually set it to '', and we should store it as None 'URL_BLACKLIST_PTN': {'default': lambda c: c['URL_BLACKLIST'] and re.compile(c['URL_BLACKLIST'] or '', re.IGNORECASE | re.UNICODE | re.MULTILINE)}, + 'DIR_OUTPUT_PERMISSIONS': {'default': lambda c: c['OUTPUT_PERMISSIONS'].replace('6', '7').replace('4', '5')}, 'ARCHIVEBOX_BINARY': {'default': lambda c: sys.argv[0] or bin_path('archivebox')}, 'VERSION': {'default': lambda c: json.loads((Path(c['PACKAGE_DIR']) / 'package.json').read_text(encoding='utf-8').strip())['version']}, @@ -967,7 +968,7 @@ globals().update(CONFIG) # Set timezone to UTC and umask to OUTPUT_PERMISSIONS os.environ["TZ"] = 'UTC' -os.umask(0o777 - int(OUTPUT_PERMISSIONS, base=8)) # noqa: F821 +os.umask(0o777 - int(DIR_OUTPUT_PERMISSIONS, base=8)) # noqa: F821 # add ./node_modules/.bin to $PATH so we can use node scripts in extractors NODE_BIN_PATH = str((Path(CONFIG["OUTPUT_DIR"]).absolute() / 'node_modules' / '.bin')) diff --git a/archivebox/system.py b/archivebox/system.py index 09066fcf..347698f8 100644 --- a/archivebox/system.py +++ b/archivebox/system.py @@ -14,7 +14,7 @@ from crontab import CronTab from .vendor.atomicwrites import atomic_write as lib_atomic_write from .util import enforce_types, ExtendedEncoder -from .config import PYTHON_BINARY, OUTPUT_PERMISSIONS, ENFORCE_ATOMIC_WRITES +from .config import PYTHON_BINARY, OUTPUT_PERMISSIONS, DIR_OUTPUT_PERMISSIONS, ENFORCE_ATOMIC_WRITES @@ -109,7 +109,7 @@ def atomic_write(path: Union[Path, str], contents: Union[dict, str, bytes], over os.chmod(path, int(permissions, base=8)) @enforce_types -def chmod_file(path: str, cwd: str='.', permissions: str=OUTPUT_PERMISSIONS) -> None: +def chmod_file(path: str, cwd: str='.') -> None: """chmod -R /""" root = Path(cwd) / path @@ -123,10 +123,9 @@ def chmod_file(path: str, cwd: str='.', permissions: str=OUTPUT_PERMISSIONS) -> for subpath in Path(path).glob('**/*'): if subpath.is_dir(): # directories need execute permissions to be able to list contents - perms_with_x_allowed = permissions.replace('4', '5').replace('6', '7') - os.chmod(subpath, int(perms_with_x_allowed, base=8)) + os.chmod(subpath, int(DIR_OUTPUT_PERMISSIONS, base=8)) else: - os.chmod(subpath, int(permissions, base=8)) + os.chmod(subpath, int(OUTPUT_PERMISSIONS, base=8)) @enforce_types