Skip to content

pdb: keep USB file names apart when the caps make them collide - #156

Merged
vynulldev merged 2 commits into
vynulldev:mainfrom
WOLFI3654:usb-filename-collisions
Nov 21, 2026
Merged

vynulldev merged 2 commits into
vynulldev:mainfrom
WOLFI3654:usb-filename-collisions

Conversation

@WOLFI3654

@WOLFI3654 WOLFI3654 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What & why

PrepareUSBLayout caps a file name at 48 characters, or less to keep
the whole path within 126, but never checked whether the capped path
was already taken in the export. Two tracks whose names share their
first 44 characters landed on one path, as did names that differ only
in case, which FAT32 folds together. The second copy overwrote the
first, and both PDB rows played it.

Exporting an S3RL pack, "S3RL & Synthwulf - Everybody Wants to be a
DJ [Wav File].wav" and its "(S3RL hard mix) [Wav File].wav" both
became ".../S3RL & Synthwulf - Everybody Wants to be a D.wav", and
picking the plain version on the deck played the hard mix.

The export now remembers the paths it has handed out, compared in
lower case as FAT does, and gives a later colliding name " (2)",
" (3)" and so on before its extension, shortening the base to stay
within the same cap: the hard mix becomes ".../S3RL & Synthwulf -
Everybody Wants to be (2).wav". Names that don't collide are
unchanged.

TestPrepareUSBLayoutKeepsCollidingNamesApart lays out both cases and
checks that every row gets its own path and plays its own file. On
main both pairs share a path, and the plain mix's row plays the hard
mix.

Hardware testing

  • Tested on: not yet. Opened as a draft until it has been checked on a CDJ-2000.

Checklist

  • go build ./..., go vet ./..., and go test ./... pass (except nfs/TestMP3SizePredicted, which fails on main too with ffmpeg 9.0.2, whose FLAC encoder rejects the test fixture: "invalid block size: 1")
  • 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

🤖 Generated with Claude Code

PrepareUSBLayout caps a file name at 48 characters, or less to keep
the whole path within 126, but never checked whether the capped path
was already taken in the export. Two tracks whose names share their
first 44 characters landed on one path, as did names that differ only
in case, which FAT32 folds together. The second copy overwrote the
first, and both PDB rows played it.

Exporting an S3RL pack, "S3RL & Synthwulf - Everybody Wants to be a
DJ [Wav File].wav" and its "(S3RL hard mix) [Wav File].wav" both
became ".../S3RL & Synthwulf - Everybody Wants to be a D.wav", and
picking the plain version on the deck played the hard mix.

The export now remembers the paths it has handed out, compared in
lower case as FAT does, and gives a later colliding name " (2)",
" (3)" and so on before its extension, shortening the base to stay
within the same cap: the hard mix becomes ".../S3RL & Synthwulf -
Everybody Wants to be (2).wav". Names that don't collide are
unchanged.

TestPrepareUSBLayoutKeepsCollidingNamesApart lays out both cases and
checks that every row gets its own path and plays its own file. On
main both pairs share a path, and the plain mix's row plays the hard
mix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@WOLFI3654
WOLFI3654 marked this pull request as ready for review November 2, 2026 16:17
Copilot AI balanced review requested due to automatic review settings November 2, 2026 16:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@vynulldev vynulldev added the bug Something isn't working label Nov 2, 2026

@vynulldev vynulldev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding this bug and pushing the PR! Just had a couple quick requests before merging:

Comment thread pdb/writer.go Resolved
Comment thread pdb/writer.go Resolved
vynulldev added a commit that referenced this pull request Nov 4, 2026
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

Copy link
Copy Markdown
Owner

Hey @WOLFI3654 I'd like to do a release this week and I'd love to get this fix into it! I can go ahead and push a new PR with your patch + the requested changes and credit you with co-author if that's easier. Let me know otherwise, thanks!

@WOLFI3654

Copy link
Copy Markdown
Contributor Author

Hey @WOLFI3654 I'd like to do a release this week and I'd love to get this fix into it! I can go ahead and push a new PR with your patch + the requested changes and credit you with co-author if that's easier. Let me know otherwise, thanks!

oh thought i did. will do shortly :)

Follow-up to the review. rekordbox 7 names a colliding file "-1", "-2"
and so on before its extension ("Same Name.mp3", "Same Name-1.mp3"),
the base shortened so the whole name stays within the cap, so the
export now does the same instead of " (2)". The track exported first
keeps the plain name, as in rekordbox.

Cutting a name to its cap now stops at the start of a character, so a
cut never splits a multi-byte one into invalid UTF-8. TruncateFilename
cut by bytes too and shares the fix.

The test uses made-up names, and adds the same name from two folders,
a third long name ("-2") and cuts through an "é".
@vynulldev
vynulldev merged commit fc211e7 into vynulldev:main Nov 21, 2026
1 check passed
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.

3 participants