1
0
mirror of https://github.com/pirate/ArchiveBox.git synced 2025-09-02 19:02:37 +02:00

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
22 changed files with 119 additions and 97 deletions

View File

@@ -149,12 +149,13 @@ def save_text_as_source(raw_text: str, filename: str='{ts}-stdin.txt', out_dir:
referenced_texts = ''
for entry in raw_text.split():
try:
if Path(entry).exists():
referenced_texts += Path(entry).read_text()
except Exception as err:
print(err)
# dont attempt to read local files from the text, security risk:
# for entry in raw_text.split():
# try:
# if Path(entry).exists():
# referenced_texts += Path(entry).read_text()
# except Exception as err:
# print(err)
atomic_write(source_path, raw_text + '\n' + referenced_texts)
log_source_saved(source_file=source_path)

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