Skip to content

Keep untracked sidecars with audiobooks when renaming folders - #305

Draft
Yoldark34 wants to merge 2 commits into
Chaptarr:developfrom
Yoldark34:fix/rename-carry-audiobook-sidecars
Draft

Yoldark34 wants to merge 2 commits into
Chaptarr:developfrom
Yoldark34:fix/rename-carry-audiobook-sidecars

Conversation

@Yoldark34

Copy link
Copy Markdown

Description

Renaming moved audiobook files one by one and only carried the sidecars Chaptarr tracks in MetadataFiles. Untracked ones (AudioBookShelf cover.jpg / metadata.json, .opf, desc.txt…) were left in the old folder, and a library watcher saw a new folder fill up file by file: AudioBookShelf created a new item and wrote its own sidecars there before Chaptarr moved the tracked ones, which then failed with File already exists.

RenameBookFileService now groups the audiobook files of a rename by source folder. When every file of a folder goes to the same new folder:

  • Folder move: if the destination doesn't exist and the source has no subfolders, the folder is moved in one step (Directory.Move). Everything in it follows, and watchers see a single rename. A file whose own name also changes is then renamed inside the new folder by the usual mover.
  • Sidecars first: otherwise the non-media files are moved into the destination before the audio files, never overwriting an existing file.

The relocation is skipped (old behaviour) when:

  • the files are split across destinations;
  • another known book file (an ebook, a file not in the rename) lives in or below the folder;
  • the media files on disk don't match the files being moved exactly (untracked audio would be carried along silently);
  • the folder is the author folder;
  • it's a case-only change, or one folder is nested in the other;
  • the plan involves ebook replicas.

If the folder move throws (e.g. cross-device), it logs a warning and falls back to moving files one by one.

MetadataService and ExtraFileManager now re-point a tracked file that a folder move already carried (old path missing, new path present) instead of failing to move it.

Audiobook plans are computed before the loop, which is safe because they only depend on naming; ebook plans are still computed in the loop, after the audiobook moves are recorded in the batch context.

Fixes #304

Database Migration

NO

How was this tested?

  • New tests in RenameBookFileServiceFixture, with an in-memory disk fake:
    • the folder is moved as a whole and its sidecars follow;
    • a renamed file inside a moved folder is still renamed;
    • sidecars are moved before the audio, with no overwrite;
    • the folder is left alone when a file stays behind, when it holds untracked media, or when the files split across destinations;
    • the code falls back to file-by-file moves when the folder move fails.
  • New test in MetadataServiceSidecarOverwriteFixture: tracked metadata already carried by a folder move is re-pointed, not moved.
  • Full Chaptarr.Core.Test run: 3051/3051 passing (Linux, .NET 10 SDK container).
  • Deployed the patched Chaptarr.Core.dll over robertlordhood/chaptarr:0.9.965 (Docker, library on an rclone/pCloud mount, AudioBookShelf watching the same folders). Both instances start cleanly, and the rename preview and API work as before.

🤖 Generated with Claude Code

Yoldark34 and others added 2 commits October 10, 2026 20:30
Renaming moved audiobook files one by one and only carried the sidecars
Chaptarr tracks. Untracked ones (AudioBookShelf cover.jpg/metadata.json,
.opf, desc.txt...) stayed in the old folder, and a library watcher saw a
new folder fill up file by file: AudioBookShelf created a new item and
wrote its own sidecars there before Chaptarr moved the tracked ones,
which then failed with "File already exists".

When every audiobook file of a folder goes to the same new folder and
nothing else lives there, the folder is now moved in one step. If the
destination already exists, the sidecars are moved ahead of the audio
files, never overwriting an existing file. Tracked metadata and extra
files that a folder move already carried are re-pointed instead of
failing to move.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Extras are renamed after the book file (e.g. "<book file>.jpg"). After a
folder move, the tracked file sits in the new folder under its old name,
so looking only for the new name failed with FileNotFoundException and
left the extra's stored path stale. Look for the carried file under its
old name and rename it in place when needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Renaming audiobook folders leaves untracked sidecars behind and races AudioBookShelf's watcher

1 participant