mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-04-05 23:37:58 +10:00
switch .is_dir and .exists for os.access to avoid PermissionError on startup
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
__package__ = 'archivebox.misc'
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
from rich import print
|
||||
@@ -14,7 +15,7 @@ from rich import print
|
||||
def check_data_folder() -> None:
|
||||
from archivebox import DATA_DIR, ARCHIVE_DIR
|
||||
|
||||
archive_dir_exists = ARCHIVE_DIR.exists()
|
||||
archive_dir_exists = os.access(ARCHIVE_DIR, os.R_OK) and ARCHIVE_DIR.is_dir()
|
||||
if not archive_dir_exists:
|
||||
print('[red][X] No archivebox index found in the current directory.[/red]', file=sys.stderr)
|
||||
print(f' {DATA_DIR}', file=sys.stderr)
|
||||
|
||||
@@ -114,7 +114,7 @@ def chmod_file(path: str, cwd: str='') -> None:
|
||||
"""chmod -R <permissions> <cwd>/<path>"""
|
||||
|
||||
root = Path(cwd or os.getcwd()) / path
|
||||
if not root.exists():
|
||||
if not os.access(root, os.R_OK):
|
||||
raise Exception('Failed to chmod: {} does not exist (did the previous step fail?)'.format(path))
|
||||
|
||||
if not root.is_dir():
|
||||
@@ -132,6 +132,9 @@ def chmod_file(path: str, cwd: str='') -> None:
|
||||
@enforce_types
|
||||
def copy_and_overwrite(from_path: Union[str, Path], to_path: Union[str, Path]):
|
||||
"""copy a given file or directory to a given path, overwriting the destination"""
|
||||
|
||||
assert os.access(from_path, os.R_OK)
|
||||
|
||||
if Path(from_path).is_dir():
|
||||
shutil.rmtree(to_path, ignore_errors=True)
|
||||
shutil.copytree(from_path, to_path)
|
||||
|
||||
Reference in New Issue
Block a user