Skip to content

Commit

Permalink
Update libraryFolderID correctly in scanFolderUpdates
Browse files Browse the repository at this point in the history
  • Loading branch information
mikiher committed Mar 20, 2024
1 parent 9511122 commit 1bee082
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 6 additions & 5 deletions server/scanner/LibraryItemScanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@ class LibraryItemScanner {
* Scan single library item
*
* @param {string} libraryItemId
* @param {{relPath:string, path:string}} [renamedPaths] used by watcher when item folder was renamed
* @param {{relPath:string, path:string}} [updateLibraryItemDetails] used by watcher when item folder was renamed
* @returns {number} ScanResult
*/
async scanLibraryItem(libraryItemId, renamedPaths = null) {
async scanLibraryItem(libraryItemId, updateLibraryItemDetails = null) {
// TODO: Add task manager
const libraryItem = await Database.libraryItemModel.findByPk(libraryItemId)
if (!libraryItem) {
Logger.error(`[LibraryItemScanner] Library item not found "${libraryItemId}"`)
return ScanResult.NOTHING
}

const libraryFolderId = updateLibraryItemDetails?.libraryFolderId || libraryItem.libraryFolderId
const library = await Database.libraryModel.findByPk(libraryItem.libraryId, {
include: {
model: Database.libraryFolderModel,
where: {
id: libraryItem.libraryFolderId
id: libraryFolderId
}
}
})
Expand All @@ -51,9 +52,9 @@ class LibraryItemScanner {

const scanLogger = new ScanLogger()
scanLogger.verbose = true
scanLogger.setData('libraryItem', renamedPaths?.relPath || libraryItem.relPath)
scanLogger.setData('libraryItem', updateLibraryItemDetails?.relPath || libraryItem.relPath)

const libraryItemPath = renamedPaths?.path || fileUtils.filePathToPOSIX(libraryItem.path)
const libraryItemPath = updateLibraryItemDetails?.path || fileUtils.filePathToPOSIX(libraryItem.path)
const folder = library.libraryFolders[0]
const libraryItemScanData = await this.getLibraryItemScanData(libraryItemPath, library, folder, false)

Expand Down
9 changes: 5 additions & 4 deletions server/scanner/LibraryScanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ class LibraryScanner {
path: potentialChildDirs
})

let renamedPaths = {}
let updatedLibraryItemDetails = {}
if (!existingLibraryItem) {
const dirIno = await fileUtils.getIno(fullPath)
existingLibraryItem = await Database.libraryItemModel.findOneOld({
Expand All @@ -536,8 +536,9 @@ class LibraryScanner {
// Update library item paths for scan
existingLibraryItem.path = fullPath
existingLibraryItem.relPath = itemDir
renamedPaths.path = fullPath
renamedPaths.relPath = itemDir
updatedLibraryItemDetails.path = fullPath
updatedLibraryItemDetails.relPath = itemDir
updatedLibraryItemDetails.libraryFolderId = folder.id
}
}
if (existingLibraryItem) {
Expand All @@ -557,7 +558,7 @@ class LibraryScanner {

// Scan library item for updates
Logger.debug(`[LibraryScanner] Folder update for relative path "${itemDir}" is in library item "${existingLibraryItem.media.metadata.title}" - scan for updates`)
itemGroupingResults[itemDir] = await LibraryItemScanner.scanLibraryItem(existingLibraryItem.id, renamedPaths)
itemGroupingResults[itemDir] = await LibraryItemScanner.scanLibraryItem(existingLibraryItem.id, updatedLibraryItemDetails)
continue
} else if (library.settings.audiobooksOnly && !hasAudioFiles(fileUpdateGroup, itemDir)) {
Logger.debug(`[LibraryScanner] Folder update for relative path "${itemDir}" has no audio files`)
Expand Down

0 comments on commit 1bee082

Please sign in to comment.