diff --git a/CLAUDE.md b/CLAUDE.md index 56fa072..86bc960 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -105,6 +105,10 @@ Two independent apps that talk over HTTP: scanners would drift. `is_boot_volume()` compares **st_dev against `/`**, not the name, because macOS lists the startup disk in `/Volumes` next to real removable media and `Macintosh HD` is only its default name. + `is_os_housekeeping()` names what an OS writes into a folder by itself + (`.Spotlight-V100`, `.Trashes`, `._*`, `System Volume Information`, …), so + the export's "is this folder empty?" check does not refuse a stick's root + just because a Mac has mounted it once. - `adapters/traktor/` — everything that knows NML exists. - `store.py` (`TraktorStore`) — the retained native model: owns the parsed dataclass NML, applies every edit, renders + saves. See "Write path". diff --git a/backend/konduktor/core/places.py b/backend/konduktor/core/places.py index 180154d..65cf798 100644 --- a/backend/konduktor/core/places.py +++ b/backend/konduktor/core/places.py @@ -31,6 +31,34 @@ import platformdirs log = logging.getLogger(__name__) +#: Entries an OS writes into a volume or folder BY ITSELF — on mount, on +#: indexing, or when Finder/Explorer merely browses it. They say nothing about +#: whether a person keeps things there, so "is this folder empty?" must not +#: count them: a freshly formatted stick mounted once on a Mac is not empty to +#: `iterdir()`, and treating it as occupied made its root unexportable. +#: Compared case-insensitively — Windows' names are, and FAT/exFAT sticks are. +OS_HOUSEKEEPING = frozenset( + name.lower() + for name in ( + # macOS + ".Spotlight-V100", ".fseventsd", ".Trashes", ".TemporaryItems", + ".DocumentRevisions-V100", ".DS_Store", ".apdisk", + ".com.apple.timemachine.donotpresent", + # Windows + "System Volume Information", "$RECYCLE.BIN", "desktop.ini", "Thumbs.db", + ) +) + + +def is_os_housekeeping(name: str) -> bool: + """Whether a directory entry is the OS's bookkeeping rather than the user's. + + `._*` are AppleDouble files: macOS writes one beside every file it touches + on a volume that cannot hold extended attributes (FAT, exFAT). + """ + return name.lower() in OS_HOUSEKEEPING or name.startswith("._") + + def mount_points() -> list[Path]: """Every mounted volume's root directory, for this OS. diff --git a/backend/konduktor/exporter.py b/backend/konduktor/exporter.py index 46df5c8..50056f2 100644 --- a/backend/konduktor/exporter.py +++ b/backend/konduktor/exporter.py @@ -44,6 +44,7 @@ from pathlib import Path from . import exports from .core.export import ExportPayload, ExportPlaylist, ExportTrack, for_platform from .core.pathmap import common_dir_prefix +from .core.places import is_os_housekeeping from .importer import SPACE_HEADROOM, copy_file, free_bytes from .jobs import JobHandle @@ -123,6 +124,8 @@ def destination_blocked(destination: Path) -> str | None: A folder that does not exist yet, or is empty, or carries our manifest, is fine. Anything else is REFUSED — not confirmed — because an export clears its destination and Konduktor must never delete what it did not write. + "Empty" ignores what the OS writes by itself (`.Spotlight-V100`, `.Trashes`, + …), or a stick's root would be refused the moment it was first mounted. """ destination = Path(destination) try: @@ -132,7 +135,8 @@ def destination_blocked(destination: Path) -> str | None: return BLOCKED_OCCUPIED if is_ours(destination): return None - return BLOCKED_OCCUPIED if any(destination.iterdir()) else None + occupied = any(not is_os_housekeeping(p.name) for p in destination.iterdir()) + return BLOCKED_OCCUPIED if occupied else None except OSError: return BLOCKED_OCCUPIED @@ -213,13 +217,19 @@ def plan(adapter, export_set) -> ExportPlan: resolved = exports.resolve(adapter, export_set) tracks = [t for t in (adapter.track(i) for i in resolved.track_ids) if t is not None] + # The source is the adapter's `audio_path`, never `Track.filepath`: that is + # a DISPLAY path, which on Traktor omits the volume and ignores the active + # path mapping — so every track off the boot volume (or on a remapped + # Windows drive) read as missing and the export was "empty". + sources = {t.id: adapter.audio_path(t.id) for t in tracks} + # Mirror relative to the deepest shared folder, so the export carries the # user's structure without carrying their home directory. - present = [t.filepath for t in tracks if t.filepath] + present = [str(p) for p in sources.values() if p] root = common_dir_prefix(present) if present else "" for track in tracks: - source = Path(track.filepath) if track.filepath else None + source = sources[track.id] exists = False size = 0 try: diff --git a/backend/test_export.py b/backend/test_export.py index 6a544aa..63bc289 100644 --- a/backend/test_export.py +++ b/backend/test_export.py @@ -288,6 +288,18 @@ empty.mkdir() check("an empty folder is allowed", exporter.destination_blocked(empty) is None) check("a folder that does not exist yet is allowed", exporter.destination_blocked(empty / "nested" / "deeper") is None) +# A stick's root after its first mount on a Mac: not empty to iterdir(), but +# nothing in it is the user's. +stick = Path(tempfile.mkdtemp()) / "STICK" +for d in (".Spotlight-V100", ".fseventsd", ".Trashes", "System Volume Information"): + (stick / d).mkdir(parents=True) +for f in (".DS_Store", "._Track.mp3", "Thumbs.db"): + (stick / f).write_bytes(b"") +check("OS housekeeping does not make a folder occupied", + exporter.destination_blocked(stick) is None) +(stick / "My Set.mp3").write_bytes(b"") +check("but one file of the user's still does", + exporter.destination_blocked(stick) == exporter.BLOCKED_OCCUPIED) print("== cancelling rolls back, leaving an empty folder ==") fresh = Path(tempfile.mkdtemp()) / "Cancelled" @@ -334,5 +346,25 @@ check("it is reported", len([t for t in partial.tracks if t.missing]) == 1) check("the rest still export", len(partial.exportable) == len(built.exportable) - 1) check("and it is not blocking", partial.blocked is None) +print("== the source is where the ADAPTER resolves it, not the display path ==") +# The bug: a collection on a drive (or a Windows collection with an X: → /Volumes +# mapping) exported "nothing", because the plan read `Track.filepath` — a display +# path without the volume or the active mapping — and called every track missing. +import shutil # noqa: E402 +from konduktor.core.pathmap import PathMapping # noqa: E402 + +moved_root = Path(tempfile.mkdtemp()) / "Elsewhere" +for sub in ("House", "Techno"): + shutil.copytree(lib_root / sub, moved_root / sub) + shutil.rmtree(lib_root / sub) +ad.set_path_mapping(PathMapping.make(str(lib_root), str(moved_root))) +remapped = exporter.plan(ad, exports.get(LIB, eset.id)) +check("every surviving track is found through the mapping", + len(remapped.exportable) == len(partial.exportable), + f"{len(remapped.exportable)} of {len(partial.exportable)}") +check("and it is copied from the mapped location", + all(str(t.source_path).startswith(str(moved_root)) for t in remapped.exportable)) +ad.set_path_mapping(PathMapping()) + print("\n" + ("❌ FAILED" if failed else "✅ PASSED")) raise SystemExit(1 if failed else 0) diff --git a/frontend/src/components/ExportRunDialog.tsx b/frontend/src/components/ExportRunDialog.tsx index d563f62..07e7ea9 100644 --- a/frontend/src/components/ExportRunDialog.tsx +++ b/frontend/src/components/ExportRunDialog.tsx @@ -169,11 +169,20 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) { one of its own. Edit the export and choose somewhere else. )} - {blocked === 'nothing_to_export' && ( + {blocked === 'nothing_to_export' && p && p.tracks === 0 && (