Skip to content

export: keep tracks already on the stick where they are - #168

Merged
vynulldev merged 1 commit into
mainfrom
export-keep-on-stick
Nov 4, 2026
Merged

vynulldev merged 1 commit into
mainfrom
export-keep-on-stick

Conversation

@vynulldev

Copy link
Copy Markdown
Owner

What & why

A merge export lays out every track again: it computes the track's stick path from its tags, copies the file there, and matches the track to the stick's existing rows by that path. Two things go wrong:

We tested rekordbox 7 on the same case. It also names colliding files first come, first served, but a re-export changes nothing: tracks already on the stick keep their files, names and IDs, and the new playlist points at them.

Changes:

  • keepOnStick runs before the layout in a merge export. A track whose source has the same bytes as a file the stick already holds keeps that file's path. The merge then reuses that row's ID, as it already does for a matching path, and the file isn't copied again. Only the remaining tracks are laid out and copied.
  • Matching is by content, so it works on any stick, rekordbox's included (rekordbox copies files byte for byte). Files must have the same size, then the same first and last 64 KiB. A file is matched to one track at most.
  • Re-encoded tracks never match, because the stick holds the re-encode rather than the source. They're laid out as before.

Checked end to end through the export API (throwaway servers in a loopback-only network namespace, two real MP3s, reading each stick's PDB and the file each row points at):

before after
Export [A, B], edit A's artist, merge-export [A, B] main: 3 rows, 3 audio files (A copied twice, under both artists) branch: 2 rows, 2 files; A keeps its file and ID, and its row takes the new artist
Colliding names: export [A, B], then merge-export [B, A] main with #156: rows 1 and 2 swap, and "First Export" plays B, A branch with #156: nothing moves; "First Export" still plays A, B, and "Second Export" plays B, A

Tests (export/onstick_test.go):

  • after an artist edit, a merge export keeps both tracks already on the stick at their files and IDs, lays out only the new one, ends with three tracks rather than four, and leaves the first playlist intact;
  • a different file with the same name and size isn't taken for the stick's file, and neither is a track the export re-encodes;
  • sameEnds compares both ends, and handles a file shorter than 64 KiB.

Not in this PR: naming new tracks around the names already on the stick. That's collision handling, which #156 is reworking. Once #156 lands, its collision check can also count the stick's existing names.

Build, vet, all tests and the race detector on the export and pdb packages pass, and deadcode reports what it does on main. The end-to-end suite passes. Conformance against main is unchanged: 3,091/4,250 exact on both, nothing gained or lost.

Hardware testing

  • Tested on: CDJ-2000NXS2

Checklist

  • go build ./..., go vet ./..., and go test ./... pass
  • gofmt -l . is clean
  • New source files carry an SPDX header (GPL-3.0-or-later)
  • Tested on real hardware (deck + firmware noted above), or this change doesn't affect deck behaviour
  • I agree my contribution is licensed under the project's GPLv3

A merge export laid out every track again, computing its stick path
from its tags, and matched it to the stick's rows by that path. A
track whose artist or album had changed since it was exported got a
new folder: it was copied a second time and added as a second row,
while the stick's playlists kept the old copy. And with colliding
file names kept apart (#156), a re-export in another order would swap
the two tracks' files and IDs, changing the stick's playlists.

rekordbox keeps a track already on the stick at its file and ID when
it is exported again. keepOnStick now does the same before the
layout: a track whose source has the same bytes as a file the stick
holds (the same size, then the same first and last 64 KiB) keeps that
file's path, so the merge reuses its row and ID and doesn't copy it
again. Only the other tracks are laid out. A track the export
re-encodes never matches, as the stick holds the re-encode.
@vynulldev vynulldev added the bug Something isn't working label Nov 4, 2026
@vynulldev
vynulldev merged commit 83905c2 into main Nov 4, 2026
1 check passed
@vynulldev
vynulldev deleted the export-keep-on-stick branch November 4, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant