The library is going live as the canonical store, synced to a second machine via Syncthing. Track locations were stored absolute and only remapped at import, so on a second machine (where Syncthing mounts the folder at a different path) every location would break. - lintunes/paths.py: to_relative/to_absolute. Locations are stored relative to the data dir and resolved back on load, applied only at the json_storage boundary (save_tracks/load_library). Track.location stays absolute in memory, so the player, tagging, and art code are unchanged. The data dir and the music move together inside one synced tree, so paths resolve wherever it's mounted — no per-machine music_root config. Absolute paths in older library.json files still load (back-compat). - tests/test_round15.py: helper round-trips, back-compat, and a machine-2 scenario (save under root A, load the copied tree under root B). - TASKS.md/tasks-done.md: mark the data-dir move + real import done; log the benign exit-time Qt/FFmpeg teardown segfault. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
"""Portable track paths.
|
|
|
|
Track locations are kept **absolute** in memory (the player, tagging, and art code
|
|
all expect real paths), but on disk they are stored **relative to the data dir**.
|
|
The data dir and the music live inside one Syncthing-shared tree and move together,
|
|
so a relative path resolves correctly on every machine no matter where the tree is
|
|
mounted — no per-machine ``music_root`` config is needed at load time.
|
|
"""
|
|
|
|
import os
|
|
|
|
|
|
def to_relative(location: str, data_dir) -> str:
|
|
"""Convert an absolute track location to a path relative to ``data_dir``.
|
|
|
|
Empty or already-relative paths pass through unchanged. A file outside the
|
|
synced tree yields a ``..``-chain that still resolves on this machine (it
|
|
isn't synced, so it can't play on another machine regardless).
|
|
"""
|
|
if not location or not os.path.isabs(location):
|
|
return location
|
|
return os.path.relpath(location, str(data_dir))
|
|
|
|
|
|
def to_absolute(stored: str, data_dir) -> str:
|
|
"""Resolve a stored (data-dir-relative) path back to an absolute local path.
|
|
|
|
Absolute stored paths pass through unchanged, so libraries written before
|
|
portable paths (plain absolute locations) still load.
|
|
"""
|
|
if not stored or os.path.isabs(stored):
|
|
return stored
|
|
return os.path.normpath(os.path.join(str(data_dir), stored))
|