Fix scanner isInvalid flag and recursive path symlink bug

This commit is contained in:
Tiberiu Ichim 2026-02-22 19:59:19 +02:00
parent ed48fd8558
commit d8c89f2b8e
6 changed files with 78 additions and 9 deletions

View file

@ -404,9 +404,15 @@ class BookScanner {
existingLibraryItem.isMissing = true
libraryItemUpdated = true
}
} else if (existingLibraryItem.isMissing) {
libraryScan.addLog(LogLevel.INFO, `Book "${bookMetadata.title}" was missing but now has media files. Setting library item as NOT missing`)
existingLibraryItem.isMissing = false
} else if (existingLibraryItem.isMissing || existingLibraryItem.isInvalid) {
if (existingLibraryItem.isMissing) {
libraryScan.addLog(LogLevel.INFO, `Book "${bookMetadata.title}" was missing but now has media files. Setting library item as NOT missing`)
existingLibraryItem.isMissing = false
}
if (existingLibraryItem.isInvalid) {
libraryScan.addLog(LogLevel.INFO, `Book "${bookMetadata.title}" was invalid but now has media files. Setting library item as NOT invalid`)
existingLibraryItem.isInvalid = false
}
libraryItemUpdated = true
}

View file

@ -211,9 +211,10 @@ class LibraryItemScanData {
existingLibraryItem.ctime = this.ctimeMs
this.hasChanges = true
}
if (existingLibraryItem.isMissing) {
libraryScan.addLog(LogLevel.DEBUG, `Library item "${existingLibraryItem.relPath}" was missing but now found`)
if (existingLibraryItem.isMissing || existingLibraryItem.isInvalid) {
libraryScan.addLog(LogLevel.DEBUG, `Library item "${existingLibraryItem.relPath}" was missing or invalid but now found`)
existingLibraryItem.isMissing = false
existingLibraryItem.isInvalid = false
this.hasChanges = true
}

View file

@ -239,6 +239,18 @@ class PodcastScanner {
libraryItemUpdated = true
}
if (existingLibraryItem.isMissing || existingLibraryItem.isInvalid) {
if (existingLibraryItem.isMissing) {
libraryScan.addLog(LogLevel.INFO, `Podcast "${podcastMetadata.title}" was missing but is now found. Setting library item as NOT missing`)
existingLibraryItem.isMissing = false
}
if (existingLibraryItem.isInvalid) {
libraryScan.addLog(LogLevel.INFO, `Podcast "${podcastMetadata.title}" was invalid but is now found. Setting library item as NOT invalid`)
existingLibraryItem.isInvalid = false
}
libraryItemUpdated = true
}
// Save Podcast changes to db
if (hasMediaChanges) {
await media.save()

View file

@ -192,6 +192,15 @@ module.exports.recurseFiles = async (path, relPathToReplace = null) => {
relPathToReplace = path
}
// Handle symlinked directories by using the real path for string replacements
let realPathToReplace = relPathToReplace
try {
realPathToReplace = await fs.realpath(relPathToReplace)
realPathToReplace = filePathToPOSIX(realPathToReplace)
if (!realPathToReplace.endsWith('/')) realPathToReplace += '/'
} catch (err) {}
const options = {
mode: rra.LIST,
recursive: true,
@ -219,7 +228,7 @@ module.exports.recurseFiles = async (path, relPathToReplace = null) => {
item.fullname = filePathToPOSIX(item.fullname)
item.path = filePathToPOSIX(item.path)
const relpath = item.fullname.replace(relPathToReplace, '')
const relpath = item.fullname.replace(realPathToReplace, '')
let reldirname = Path.dirname(relpath)
if (reldirname === '.') reldirname = ''
const dirname = Path.dirname(item.fullname)
@ -249,11 +258,11 @@ module.exports.recurseFiles = async (path, relPathToReplace = null) => {
return true
})
.map((item) => {
var isInRoot = item.path + '/' === relPathToReplace
var isInRoot = item.path + '/' === realPathToReplace
return {
name: item.name,
path: item.fullname.replace(relPathToReplace, ''),
reldirpath: isInRoot ? '' : item.path.replace(relPathToReplace, ''),
path: item.fullname.replace(realPathToReplace, ''),
reldirpath: isInRoot ? '' : item.path.replace(realPathToReplace, ''),
fullpath: item.fullname,
extension: item.extension,
deep: item.deep