switch .is_dir and .exists for os.access to avoid PermissionError on startup

This commit is contained in:
Nick Sweeting 2024-10-08 03:02:34 -07:00
parent c3dd0f22e5
commit de2ab43f7f
No known key found for this signature in database
22 changed files with 119 additions and 97 deletions

View file

@ -3,7 +3,6 @@ __description__ = 'Plain Text'
from typing import IO, Iterable
from datetime import datetime, timezone
from pathlib import Path
from ..index.schema import Link
from archivebox.misc.util import (
@ -22,19 +21,20 @@ def parse_generic_txt_export(text_file: IO[str], **_kwargs) -> Iterable[Link]:
if not line.strip():
continue
# if the line is a local file path that resolves, then we can archive it
try:
if Path(line).exists():
yield Link(
url=line,
timestamp=str(datetime.now(timezone.utc).timestamp()),
title=None,
tags=None,
sources=[text_file.name],
)
except (OSError, PermissionError):
# nvm, not a valid path...
pass
# # if the line is a local file path that resolves, then we can archive it
# if line.startswith('file://'):
# try:
# if Path(line).exists():
# yield Link(
# url=line,
# timestamp=str(datetime.now(timezone.utc).timestamp()),
# title=None,
# tags=None,
# sources=[text_file.name],
# )
# except (OSError, PermissionError):
# # nvm, not a valid path...
# pass
# otherwise look for anything that looks like a URL in the line
for url in find_all_urls(line):