mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-14 15:59:38 +00:00
Merge pull request #2245 from mikiher/watcher-fixes
Fix incorrect subpath checks in server/watcher.js
This commit is contained in:
commit
0ee6336b02
2 changed files with 22 additions and 3 deletions
|
|
@ -19,6 +19,25 @@ const filePathToPOSIX = (path) => {
|
|||
}
|
||||
module.exports.filePathToPOSIX = filePathToPOSIX
|
||||
|
||||
/**
|
||||
* Check path is a child of or equal to another path
|
||||
*
|
||||
* @param {string} parentPath
|
||||
* @param {string} childPath
|
||||
* @returns {boolean}
|
||||
*/
|
||||
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) {
|
||||
try {
|
||||
var stat = await fs.stat(path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue