fix(scan): normalize paths when deduplicating audiobook file rows#662
Open
kevinheneveld wants to merge 1 commit into
Open
fix(scan): normalize paths when deduplicating audiobook file rows#662kevinheneveld wants to merge 1 commit into
kevinheneveld wants to merge 1 commit into
Conversation
ExistsAtPathAsync matched stored file rows by raw exact string, so a row left by an older scan under a bare/relative path (e.g. "Elantris.mp3") never matched the absolute path a current scan resolves for the same file. The scan then inserted a duplicate absolute-path row; the bare row resolved relative to the process working directory and 404'd on playback. Keep the exact match as a fast path and, only on a miss, resolve the book's rows to a canonical absolute form (anchoring relative paths on the audiobook BasePath) before comparing. A book has few file rows, so the fallback is cheap and never runs for the common all-absolute case. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
EfAudiobookFileRepository.ExistsAtPathAsyncdeduplicates stored file rows by raw exact-string match (f.Path == path). A row left by an older scan under a bare/relative path (e.g.Elantris.mp3) never string-matches the absolute path a current scan resolves for the same physical file, so the scan inserts a second absolute-path row.The result is two
AudiobookFilerows for one file:The detail page masks this because it reconstructs a display path from
BasePath, so the two rows look identical to the user.Fix
Keep the exact match as a fast path. Only when it misses, resolve the book's existing rows to a canonical absolute form — anchoring relative paths on the audiobook's
BasePathviaFileUtils.CombineWithOptionalBase+NormalizeStoredPath— and compare. The same file is then recognised regardless of stored path shape (legacy relative vs. absolute, separator/..differences), so a rescan no longer spawns a duplicate.A book has only a handful of file rows, so the fallback stays cheap and never runs for the common all-absolute case.
IsPathUsedByOtherAsync(the cross-book guard) is left as an exact match by design — a file lives under exactly one book's folder, and resolving every other book's relative paths would require each book'sBasePath.Tests
Adds
EfAudiobookFileRepository_ExistsAtPathTestscovering exact match, the bare-relative-vs-absolute regression, a non-matching path, and the empty-rows case.🤖 Generated with Claude Code