Limiting maximum title length in Archive files.

This commit is contained in:
Roland 2022-02-02 20:48:43 -07:00
parent 7b1c07f076
commit 01bfe4de97
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
2 changed files with 7 additions and 3 deletions

View file

@ -78,6 +78,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]
prefix = f'{dt}_{title}'
singlefile_path = directory / f'{prefix}.html'
readability_path = directory / f'{prefix}.readability.html'
@ -407,6 +408,8 @@ def migrate_archive_files():
with archive_files.readability_json.open() as fh:
title = escape_file_name(json.load(fh).get('title') or 'NA')
title = title[:50]
dt = archive_strftime(dt)
prefix = f'{dt}_{title}'
singlefile_path = domain_directory / f'{prefix}.html'

View file

@ -490,7 +490,7 @@ def test_migrate_archive_files(test_session, archive_directory, archive_factory)
# Archive6
(example_org_directory / '2000-01-01 00:00:00.000000.html').touch()
path = example_org_directory / '2000-01-01 00:00:00.000000.readability.json'
path.write_text(json.dumps({'title': 'invalid#*: title'}))
path.write_text(json.dumps({'title': 'A' * 500})) # Really long file name.
# Migration forms a plan, then performs it.
plan = lib.migrate_archive_files()
@ -510,9 +510,10 @@ def test_migrate_archive_files(test_session, archive_directory, archive_factory)
(pathlib.Path('example.com/2021-10-05 16:20:10.346823.readability.json'),
pathlib.Path('example.com/2021-10-05-16-20-10_my title.readability.json')),
(pathlib.Path('example.org/2000-01-01 00:00:00.000000.html'),
pathlib.Path('example.org/2000-01-01-00-00-00_invalid# title.html')),
pathlib.Path('example.org/2000-01-01-00-00-00_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.html')),
(pathlib.Path('example.org/2000-01-01 00:00:00.000000.readability.json'),
pathlib.Path('example.org/2000-01-01-00-00-00_invalid# title.readability.json')),
pathlib.Path(
'example.org/2000-01-01-00-00-00_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.readability.json')),
]
# New Archive files still exist.
assert all(i.is_file() for i in archive1.my_paths())