fix: remove playlists left behind by the switch to .m3u8
Build and publish container / build (pull_request) Successful in 3m40s

Every playlist appeared twice on the device. Pruning is driven by a record of
what was written last time, deliberately, so that a playlist put in that
directory by hand is never touched. But the record cannot reach back before it
existed: the .m3u files were written by a version that kept none, so when the
extension changed there was nothing to prune them by, and rsync carried both
copies across.

A file with the same name as one being written now, under an extension this
tool used to write, is removed as well. That is narrow enough to match only its
own leavings -- a hand-made playlist has a name this tool never produces, so it
survives whatever its extension, and there is a test for that alongside the one
for the duplicate.
This commit is contained in:
Emma Thorpe
2026-08-26 18:06:47 +01:00
parent 43d04bf311
commit 8644184caa
2 changed files with 51 additions and 1 deletions
+32
View File
@@ -1504,3 +1504,35 @@ def test_the_old_m3u_playlists_are_pruned_after_the_rename(tmp_path):
music_curator.prune_playlists(directory, ["screamo.m3u8"], store)
assert not (directory / "screamo.m3u").exists()
def test_a_playlist_under_a_superseded_extension_is_removed(tmp_path):
"""Switching from .m3u to .m3u8 left every playlist on the device twice.
The old files predated the record of what had been written, so there was
nothing to prune them by."""
api, source, mirror = playlist_library(tmp_path)
store = store_at(tmp_path)
directory = mirror / "_playlists"
directory.mkdir(parents=True, exist_ok=True)
(directory / "screamo.m3u").write_text("#EXTM3U\n")
(directory / "screamo.m3u8").write_text("#EXTM3U\n")
# No record at all, as on the first run after the rename.
music_curator.prune_playlists(directory, ["screamo.m3u8"], store)
assert not (directory / "screamo.m3u").exists()
assert (directory / "screamo.m3u8").is_file()
def test_an_unrelated_m3u_is_still_left_alone(tmp_path):
"""Only a name this run is writing anyway is matched, so a playlist made by
hand survives whatever its extension."""
api, source, mirror = playlist_library(tmp_path)
store = store_at(tmp_path)
directory = mirror / "_playlists"
directory.mkdir(parents=True, exist_ok=True)
(directory / "lyras-own-mix.m3u").write_text("#EXTM3U\n")
music_curator.prune_playlists(directory, ["screamo.m3u8"], store)
assert (directory / "lyras-own-mix.m3u").is_file()