mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-22 07:56:18 -05:00
Remove Tags Directory links on path deletes; keep a valid poster's link
The file browser deletes by path (`lib.delete`), which unlinks the sources before any FileGroup is deleted, so its tagged files still left orphaned links. It now removes the links of the files it is about to delete, or of every FileGroup in a deleted directory. A poster is no longer unlinked from the Tags Directory unless it is actually removed: a valid JPEG that is not named .jpg is kept with its link, and a converted poster's links are removed only once the conversion succeeds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a20ef4893a
commit
55920e9d6b
5 changed files with 84 additions and 11 deletions
|
|
@ -214,21 +214,22 @@ def convert_or_generate_poster(video: Video) -> Tuple[Optional[pathlib.Path], Op
|
|||
old: pathlib.Path = video.poster_path
|
||||
new = old.with_suffix('.jpg')
|
||||
|
||||
if old != new:
|
||||
# The old poster is about to be removed; its Tags Directory link would be left as the only copy.
|
||||
video.file_group.unlink_tag_directory_links(old)
|
||||
|
||||
if old != new and new.exists():
|
||||
# Destination JPEG already exists (it may have the wrong format).
|
||||
video.file_group.unlink_tag_directory_links(old)
|
||||
old.unlink()
|
||||
old = new
|
||||
|
||||
if not is_valid_poster(old):
|
||||
# Poster is not valid, convert it and place it in the new location.
|
||||
# Poster is not valid, convert it and place it in the new location. Conversion removes `old`, so its
|
||||
# Tags Directory links are found now and removed only once the conversion succeeds.
|
||||
old_links = video.file_group.get_tag_directory_links(old) if old != new else []
|
||||
try:
|
||||
convert_image(old, new)
|
||||
if not new.is_file() or not new.stat().st_size:
|
||||
raise FileNotFoundError(f'Failed to convert poster: {new}')
|
||||
for link in old_links:
|
||||
link.unlink(missing_ok=True)
|
||||
logger.info(f'Converted invalid poster {repr(str(old))} to {repr(str(new))}')
|
||||
return new, None
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -610,3 +610,20 @@ async def test_convert_poster_removes_tags_directory_link(async_client, test_ses
|
|||
|
||||
assert new_poster.suffix == '.jpg'
|
||||
assert not webp_link.exists(), 'The converted poster left its link behind'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_valid_poster_keeps_tags_directory_link(async_client, test_session, test_directory, video_factory,
|
||||
tag_factory, await_switches):
|
||||
"""A valid JPEG poster that is not named .jpg is not converted, so its Tags Directory link is kept."""
|
||||
tag = await tag_factory()
|
||||
video = video_factory(with_video_file=True, with_poster_ext='jpeg', tag_names=[tag.name])
|
||||
test_session.commit()
|
||||
await await_switches()
|
||||
poster_link = test_directory / 'tags' / tag.name / video.poster_path.name
|
||||
assert poster_link.is_file()
|
||||
|
||||
lib.convert_or_generate_poster(video)
|
||||
|
||||
assert video.poster_path.is_file()
|
||||
assert poster_link.is_file() and poster_link.samefile(video.poster_path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue