[PR #2773] [MERGED] Fix library files inconsistencies #3800

Closed
opened 2026-04-25 00:17:07 +02:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/advplyr/audiobookshelf/pull/2773
Author: @mikiher
Created: 3/20/2024
Status: Merged
Merged: 3/23/2024
Merged by: @advplyr

Base: masterHead: fix-library-files-inconsistencies


📝 Commits (4)

  • 9511122 Fix LibraryItem and Media file update logic for library scans
  • 1bee082 Update libraryFolderID correctly in scanFolderUpdates
  • 68276fe Fix handling of file moves from root folder to sub folder and back
  • f827aa9 Update library scanner findLibraryItemByItemToFileInoMatch query to iterate through json objects comparing inodes

📊 Changes

7 files changed (+180 additions, -32 deletions)

View changed files

📝 server/Logger.js (+1 -1)
📝 server/models/LibraryItem.js (+6 -4)
📝 server/scanner/BookScanner.js (+30 -2)
📝 server/scanner/LibraryItemScanData.js (+43 -6)
📝 server/scanner/LibraryItemScanner.js (+7 -6)
📝 server/scanner/LibraryScanner.js (+77 -11)
📝 server/scanner/PodcastScanner.js (+16 -2)

📄 Description

Fixes #2686

After some further investigation, it looks like the code already covers Audio files media updates for modified files, so what I ended up doing was the following:

  • Refactored library files properties in LibraryItemScanData
  • Used the refactored properties above in BookScanner and PodcastScanner to update media with modified ebook/cover library files
  • Fixed another related bug in which libraryFolderId in LibraryItem was also not properly updated when books were moved between different library folders within the same library

To test this, I did a lot of moving of directries between different folders (with audio/ebooks/covers) in the same library ) with watcher on and off (and running library scans when watcher was off). Now everything seems to be working without crashes or errors, and the database records look fine after each move. I'd like to write unit tests, but the code is so complicated that I need to wrap my head around how to do it properly.

Also, I still need to write a db migration script to fix existing corrup records, but I think it's important to check in the logic fixes first because of the nasty crashes and corruptions the current code can potentially create.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/advplyr/audiobookshelf/pull/2773 **Author:** [@mikiher](https://github.com/mikiher) **Created:** 3/20/2024 **Status:** ✅ Merged **Merged:** 3/23/2024 **Merged by:** [@advplyr](https://github.com/advplyr) **Base:** `master` ← **Head:** `fix-library-files-inconsistencies` --- ### 📝 Commits (4) - [`9511122`](https://github.com/advplyr/audiobookshelf/commit/9511122bae10ae67dd2299961e35ea2e82c8f284) Fix LibraryItem and Media file update logic for library scans - [`1bee082`](https://github.com/advplyr/audiobookshelf/commit/1bee0827200d95d2cf7839bff99b46cf21dc5ac6) Update libraryFolderID correctly in scanFolderUpdates - [`68276fe`](https://github.com/advplyr/audiobookshelf/commit/68276fe30ba4397e1d293e855e8740f4efb93453) Fix handling of file moves from root folder to sub folder and back - [`f827aa9`](https://github.com/advplyr/audiobookshelf/commit/f827aa97f8d74aead118387f2e8cd608cad26393) Update library scanner findLibraryItemByItemToFileInoMatch query to iterate through json objects comparing inodes ### 📊 Changes **7 files changed** (+180 additions, -32 deletions) <details> <summary>View changed files</summary> 📝 `server/Logger.js` (+1 -1) 📝 `server/models/LibraryItem.js` (+6 -4) 📝 `server/scanner/BookScanner.js` (+30 -2) 📝 `server/scanner/LibraryItemScanData.js` (+43 -6) 📝 `server/scanner/LibraryItemScanner.js` (+7 -6) 📝 `server/scanner/LibraryScanner.js` (+77 -11) 📝 `server/scanner/PodcastScanner.js` (+16 -2) </details> ### 📄 Description Fixes #2686 After some further investigation, it looks like the code already covers Audio files media updates for modified files, so what I ended up doing was the following: - Refactored library files properties in LibraryItemScanData - Used the refactored properties above in BookScanner and PodcastScanner to update media with modified ebook/cover library files - Fixed another related bug in which libraryFolderId in LibraryItem was also not properly updated when books were moved between different library folders within the same library To test this, I did a lot of moving of directries between different folders (with audio/ebooks/covers) in the same library ) with watcher on and off (and running library scans when watcher was off). Now everything seems to be working without crashes or errors, and the database records look fine after each move. I'd like to write unit tests, but the code is so complicated that I need to wrap my head around how to do it properly. Also, I still need to write a db migration script to fix existing corrup records, but I think it's important to check in the logic fixes first because of the nasty crashes and corruptions the current code can potentially create. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2026-04-25 00:17:07 +02:00
adam closed this issue 2026-04-25 00:17:07 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#3800