From 0ed2a236705b57368c3abf54bfeb21a9cf31e556 Mon Sep 17 00:00:00 2001 From: apkallum Date: Wed, 22 Jul 2020 17:41:43 -0400 Subject: [PATCH 1/3] ensure correct permissions for output folder --- archivebox/index/__init__.py | 3 +++ archivebox/main.py | 3 ++- archivebox/system.py | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/archivebox/index/__init__.py b/archivebox/index/__init__.py index 89a84f1e..6617864b 100644 --- a/archivebox/index/__init__.py +++ b/archivebox/index/__init__.py @@ -26,6 +26,7 @@ from ..config import ( URL_BLACKLIST_PTN, ANSI, stderr, + OUTPUT_PERMISSIONS ) from ..logging_util import ( TimedProgress, @@ -232,6 +233,8 @@ def write_main_index(links: List[Link], out_dir: str=OUTPUT_DIR, finished: bool= with timed_index_update(os.path.join(out_dir, SQL_INDEX_FILENAME)): write_sql_main_index(links, out_dir=out_dir) + os.chmod(os.path.join(out_dir, SQL_INDEX_FILENAME), int(OUTPUT_PERMISSIONS, base=8)) # set here because we don't write it with atomic writes + with timed_index_update(os.path.join(out_dir, JSON_INDEX_FILENAME)): write_json_main_index(links, out_dir=out_dir) diff --git a/archivebox/main.py b/archivebox/main.py index 18f40b97..2c492ee2 100644 --- a/archivebox/main.py +++ b/archivebox/main.py @@ -87,6 +87,7 @@ from .config import ( CONFIG, USER_CONFIG, get_real_name, + OUTPUT_PERMISSIONS ) from .logging_util import ( TERM_WIDTH, @@ -240,8 +241,8 @@ def run(subcommand: str, @enforce_types def init(force: bool=False, out_dir: str=OUTPUT_DIR) -> None: """Initialize a new ArchiveBox collection in the current directory""" + os.umask(0o777 - int(OUTPUT_PERMISSIONS, base=8)) os.makedirs(out_dir, exist_ok=True) - is_empty = not len(set(os.listdir(out_dir)) - ALLOWED_IN_OUTPUT_DIR) existing_index = os.path.exists(os.path.join(out_dir, JSON_INDEX_FILENAME)) diff --git a/archivebox/system.py b/archivebox/system.py index d6206557..a9b3758b 100644 --- a/archivebox/system.py +++ b/archivebox/system.py @@ -43,7 +43,7 @@ def atomic_write(path: Union[Path, str], contents: Union[dict, str, bytes], over dump(contents, f, indent=4, sort_keys=True, cls=ExtendedEncoder) elif isinstance(contents, (bytes, str)): f.write(contents) - + os.chmod(path, int(OUTPUT_PERMISSIONS, base=8)) @enforce_types def chmod_file(path: str, cwd: str='.', permissions: str=OUTPUT_PERMISSIONS) -> None: From 1b944303d048ea03882d612fb0a7bf985df0af3d Mon Sep 17 00:00:00 2001 From: apkallum Date: Thu, 23 Jul 2020 11:06:43 -0400 Subject: [PATCH 2/3] test: test output permissions --- tests/test_init.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_init.py b/tests/test_init.py index 6a15612a..0b2832c3 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -6,6 +6,8 @@ import subprocess from pathlib import Path import json +from archivebox.config import OUTPUT_PERMISSIONS + from .fixtures import * def test_init(tmp_path, process): @@ -43,3 +45,9 @@ def test_add_link_support_stdin(tmp_path, process): output_json = json.load(f) assert "Example Domain" == output_json['history']['title'][0]['output'] +def test_correct_permissions_output_folder(tmp_path, process): + index_files = ['index.json', 'index.html', 'index.sqlite3', 'archive'] + for file in index_files: + file_path = tmp_path / file + assert oct(file_path.stat().st_mode)[-3:] == OUTPUT_PERMISSIONS + From b854884c568be51273b7d9a2cb3f902d2a2d4985 Mon Sep 17 00:00:00 2001 From: apkallum Date: Thu, 23 Jul 2020 11:50:42 -0400 Subject: [PATCH 3/3] move umask to init/__config__ --- archivebox/config/__init__.py | 2 ++ archivebox/main.py | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/archivebox/config/__init__.py b/archivebox/config/__init__.py index e1a99c99..140769db 100644 --- a/archivebox/config/__init__.py +++ b/archivebox/config/__init__.py @@ -864,3 +864,5 @@ def setup_django(out_dir: str=None, check_db=False, config: ConfigDict=CONFIG) - f'No database file {SQL_INDEX_FILENAME} found in OUTPUT_DIR: {config["OUTPUT_DIR"]}') except KeyboardInterrupt: raise SystemExit(2) + +os.umask(0o777 - int(OUTPUT_PERMISSIONS, base=8)) diff --git a/archivebox/main.py b/archivebox/main.py index 2c492ee2..cd6c7492 100644 --- a/archivebox/main.py +++ b/archivebox/main.py @@ -87,7 +87,6 @@ from .config import ( CONFIG, USER_CONFIG, get_real_name, - OUTPUT_PERMISSIONS ) from .logging_util import ( TERM_WIDTH, @@ -241,7 +240,6 @@ def run(subcommand: str, @enforce_types def init(force: bool=False, out_dir: str=OUTPUT_DIR) -> None: """Initialize a new ArchiveBox collection in the current directory""" - os.umask(0o777 - int(OUTPUT_PERMISSIONS, base=8)) os.makedirs(out_dir, exist_ok=True) is_empty = not len(set(os.listdir(out_dir)) - ALLOWED_IN_OUTPUT_DIR) existing_index = os.path.exists(os.path.join(out_dir, JSON_INDEX_FILENAME))