Files
music-mirror/tests/test_check_fat32.py
T
Emma Thorpe 3141f7ca87
Build and publish container / build (pull_request) Successful in 2m18s
feat: name the mirror so a FAT32 device will take it, and copy album art
Two changes for playing the mirror on a Rockbox iPod, where the device is FAT32
and Rockbox reads a plain directory tree rather than a database.

--fat32-safe names mirror files acceptably: the reserved characters and control
characters become underscores, trailing dots and spaces are stripped because
FAT eats them silently and the name then round-trips as a different one, and a
component left empty becomes an underscore. Names differing only in case are
detected as collisions, since two files here are one file there and the second
would silently overwrite the first. "Kick Out the Epic Motherf**ker" is a real
example from a real library, and without this it simply never arrives.

Off by default. It renames files, and that should be a decision rather than a
surprise on somebody's next pass.

Turning it on does not re-encode anything. Every track whose name held a
reserved character changes path, and encoding those again would be hours of
work producing files that already exist byte for byte, so the run moves them
instead and logs each one. Prune then finds nothing left behind.

Album art is now also copied into the mirror as cover.jpg beside the tracks.
Rockbox searches the filesystem for art -- cover.jpg, folder.jpg and the rest,
in the track's directory or its parent -- and that search never looks at the
picture embedded in the tag, so a mirror that only embeds art displays none of
it on the device. Embedding continues for the Apple firmware; both are now
satisfied. A cover whose tracks have all been pruned is removed too, or its
directory would never look empty and never go.

Adds tools/check_fat32.py, which reports unacceptable paths before a copy
rather than during one: rsync reports them too, but scattered through fifty
thousand files where they are easy to lose. It exits non-zero so it can gate a
script.

The README documents the rsync invocation, including why --modify-window=2 is
required against FAT and why Rhythmbox must be kept out of the transfer --
rb_ipod_helpers_is_ipod() reads access-protocols from media-player-info and
returns true on the USB id alone, without looking at the filesystem, so
removing iPod_Control changes nothing.
2026-08-25 10:29:55 +01:00

65 lines
1.8 KiB
Python

import subprocess
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "tools"))
import check_fat32 # noqa: E402
def problems(name):
return check_fat32.problems_with(Path(name))
def test_a_reserved_character_is_a_problem():
assert any("reserved" in p for p in problems("Album/Motherf**ker.mp3"))
def test_a_trailing_dot_or_space_is_a_problem():
"""FAT eats them silently, so the name round-trips as a different name."""
assert any("trailing" in p for p in problems("Trailing Dot./x.mp3"))
assert any("trailing" in p for p in problems("Space /x.mp3"))
def test_an_ordinary_name_is_fine():
assert problems("Artist/Album/01 Fine Track.mp3") == []
def test_accents_are_fine():
assert problems("Mötley Crüe/Album/Track.mp3") == []
def test_an_over_long_path_is_a_problem():
deep = "/".join("d" * 40 for _ in range(10)) + "/track.mp3"
assert any("path of" in p for p in problems(deep))
def test_case_collisions_are_reported(tmp_path):
album = tmp_path / "Album"
album.mkdir()
(album / "Song.mp3").write_bytes(b"x")
(album / "SONG.mp3").write_bytes(b"x")
completed = subprocess.run(
[sys.executable, str(Path(check_fat32.__file__)), str(tmp_path)],
capture_output=True,
text=True,
)
assert completed.returncode == 1
assert "collides case-insensitively" in completed.stdout
def test_a_clean_tree_exits_zero(tmp_path):
(tmp_path / "Album").mkdir()
(tmp_path / "Album" / "Fine.mp3").write_bytes(b"x")
completed = subprocess.run(
[sys.executable, str(Path(check_fat32.__file__)), str(tmp_path)],
capture_output=True,
text=True,
)
assert completed.returncode == 0
assert "0 problems" in completed.stderr