Fix watcher scanner detecting existing items

This commit is contained in:
advplyr 2023-09-06 15:43:59 -05:00
parent f02992dd4d
commit 934c0b9093
2 changed files with 19 additions and 4 deletions

View File

@ -448,10 +448,10 @@ class LibraryScanner {
const itemGroupingResults = {}
for (const itemDir in fileUpdateGroup) {
const fullPath = Path.posix.join(fileUtils.filePathToPOSIX(folder.path), itemDir)
const dirIno = await fileUtils.getIno(fullPath)
const itemDirParts = itemDir.split('/').slice(0, -1)
const potentialChildDirs = []
const potentialChildDirs = [fullPath]
for (let i = 0; i < itemDirParts.length; i++) {
potentialChildDirs.push(Path.posix.join(fileUtils.filePathToPOSIX(folder.path), itemDir.split('/').slice(0, -1 - i).join('/')))
}
@ -462,6 +462,7 @@ class LibraryScanner {
})
if (!existingLibraryItem) {
const dirIno = await fileUtils.getIno(fullPath)
existingLibraryItem = await Database.libraryItemModel.findOneOld({
ino: dirIno
})

View File

@ -86,10 +86,24 @@ function groupFilesIntoLibraryItemPaths(mediaType, paths) {
// Step 4: Add in non-media files if they fit into item group
if (nonMediaFilePaths.length) {
for (const nonMediaFilePath of nonMediaFilePaths) {
const pathDir = Path.dirname(nonMediaFilePath)
if (itemGroup[pathDir]) {
itemGroup[pathDir].push(nonMediaFilePath)
const filename = Path.basename(nonMediaFilePath)
const dirparts = pathDir.split('/')
const numparts = dirparts.length
let _path = ''
// Iterate over directories in path
for (let i = 0; i < numparts; i++) {
const dirpart = dirparts.shift()
_path = Path.posix.join(_path, dirpart)
if (itemGroup[_path]) { // Directory is a group
const relpath = Path.posix.join(dirparts.join('/'), filename)
itemGroup[_path].push(relpath)
} else if (!dirparts.length) {
itemGroup[_path] = [filename]
}
}
}
}