mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-06 00:16:02 +01:00
Fix incorrect subpath checks
This commit is contained in:
parent
49403771c9
commit
976ae502bb
@ -6,7 +6,7 @@ const LibraryScanner = require('./scanner/LibraryScanner')
|
|||||||
const Task = require('./objects/Task')
|
const Task = require('./objects/Task')
|
||||||
const TaskManager = require('./managers/TaskManager')
|
const TaskManager = require('./managers/TaskManager')
|
||||||
|
|
||||||
const { filePathToPOSIX } = require('./utils/fileUtils')
|
const { filePathToPOSIX, isSameOrSubPath } = require('./utils/fileUtils')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef PendingFileUpdate
|
* @typedef PendingFileUpdate
|
||||||
@ -183,7 +183,7 @@ class FolderWatcher extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get file folder
|
// Get file folder
|
||||||
const folder = libwatcher.folders.find(fold => path.startsWith(filePathToPOSIX(fold.fullPath)))
|
const folder = libwatcher.folders.find(fold => isSameOrSubPath(fold.fullPath, path))
|
||||||
if (!folder) {
|
if (!folder) {
|
||||||
Logger.error(`[Watcher] New file folder not found in library "${libwatcher.name}" with path "${path}"`)
|
Logger.error(`[Watcher] New file folder not found in library "${libwatcher.name}" with path "${path}"`)
|
||||||
return
|
return
|
||||||
@ -233,7 +233,7 @@ class FolderWatcher extends EventEmitter {
|
|||||||
|
|
||||||
checkShouldIgnorePath(path) {
|
checkShouldIgnorePath(path) {
|
||||||
return !!this.ignoreDirs.find(dirpath => {
|
return !!this.ignoreDirs.find(dirpath => {
|
||||||
return filePathToPOSIX(path).startsWith(dirpath)
|
return isSameOrSubPath(dirpath, path)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,18 @@ const filePathToPOSIX = (path) => {
|
|||||||
}
|
}
|
||||||
module.exports.filePathToPOSIX = filePathToPOSIX
|
module.exports.filePathToPOSIX = filePathToPOSIX
|
||||||
|
|
||||||
|
function isSameOrSubPath(parentPath, childPath) {
|
||||||
|
parentPath = filePathToPOSIX(parentPath)
|
||||||
|
childPath = filePathToPOSIX(childPath)
|
||||||
|
if (parentPath === childPath) return true
|
||||||
|
const relativePath = Path.relative(parentPath, childPath)
|
||||||
|
return (
|
||||||
|
relativePath === '' // Same path (e.g. parentPath = '/a/b/', childPath = '/a/b')
|
||||||
|
|| !relativePath.startsWith('..') && !Path.isAbsolute(relativePath) // Sub path
|
||||||
|
)
|
||||||
|
}
|
||||||
|
module.exports.isSameOrSubPath = isSameOrSubPath
|
||||||
|
|
||||||
async function getFileStat(path) {
|
async function getFileStat(path) {
|
||||||
try {
|
try {
|
||||||
var stat = await fs.stat(path)
|
var stat = await fs.stat(path)
|
||||||
|
Loading…
Reference in New Issue
Block a user