Increasing archive file name character limit.

This commit is contained in:
Roland 2023-02-27 14:42:58 -07:00
parent 1d97f0e3a6
commit b373992fed
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
2 changed files with 16 additions and 1 deletions

View file

@ -70,6 +70,9 @@ def get_domain_directory(url: str) -> pathlib.Path:
return directory
MAXIMUM_ARCHIVE_FILE_CHARACTER_LENGTH = 200
def get_new_archive_files(url: str, title: Optional[str]) -> ArchiveFiles:
"""Create a list of archive files using a shared name schema. Raise an error if any of them exist."""
directory = get_domain_directory(url)
@ -77,7 +80,7 @@ def get_new_archive_files(url: str, title: Optional[str]) -> ArchiveFiles:
dt = archive_strftime(now())
title = escape_file_name(title or 'NA')
title = title[:50]
title = title[:MAXIMUM_ARCHIVE_FILE_CHARACTER_LENGTH]
prefix = f'{dt}_{title}'
singlefile_path = directory / f'{prefix}.html'
readability_path = directory / f'{prefix}.readability.html'

View file

@ -298,6 +298,18 @@ async def test_get_title_from_html(test_session, fake_now):
assert archive.title is None
@skip_circleci
def test_get_new_archive_files_length(fake_now):
"""Archive titles are truncated to fit file system length limit. (255-character limit for most file systems)"""
fake_now(datetime(2001, 1, 1))
archive_files = get_new_archive_files('https://example.com', 'a' * 500)
assert len(str(archive_files.singlefile.name)) == 225
assert len(str(archive_files.readability.name)) == 237
assert len(str(archive_files.readability_txt.name)) == 236
assert len(str(archive_files.readability_json.name)) == 237
assert len(str(archive_files.screenshot.name)) == 224
@skip_circleci
def test_get_new_archive_files(fake_now):
"""Archive files have a specific format so they are sorted by datetime, and are near each other."""