mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Fixed bug related to exporting with path remapping
This commit is contained in:
1 parent
8c875cb6cd
commit
a3747e887b
5 files changed
+87
-4
No files matched your search
@@ -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".
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
@@ -169,11 +169,20 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
|
||||
one of its own. Edit the export and choose somewhere else.
|
||||
</div>
|
||||
)}
|
||||
{blocked === 'nothing_to_export' && (
|
||||
{blocked === 'nothing_to_export' && p && p.tracks === 0 && (
|
||||
<div className="rounded well px-3 py-2 text-xs text-muted">
|
||||
There’s nothing to export yet — add some tracks or a playlist.
|
||||
</div>
|
||||
)}
|
||||
{/* Tracks exist but none of their audio does: saying "nothing to
|
||||
export" here sends the user looking in the wrong place. */}
|
||||
{blocked === 'nothing_to_export' && p && p.tracks > 0 && (
|
||||
<div className="rounded well px-3 py-2 text-xs text-pink">
|
||||
None of the {p.tracks} track{p.tracks === 1 ? '' : 's'} can be exported — their
|
||||
audio files are not on this disk:
|
||||
<div className="mt-1 text-faint">{p.missing.slice(0, 4).join(', ')}</div>
|
||||
</div>
|
||||
)}
|
||||
{blocked === 'unsupported_target' && (
|
||||
<div className="rounded border border-pink/40 bg-well px-3 py-2 text-xs text-pink">
|
||||
Konduktor can’t write that kind of library yet.
|
||||
|
||||
Reference in new issue
Block a user