From b925dbcc952cb0271582f8d24f9c0090a8cdb52b Mon Sep 17 00:00:00 2001 From: advplyr Date: Thu, 19 May 2022 19:00:34 -0500 Subject: [PATCH] Fix:Updating library folder paths will only set file permissions if it needed to create the folder #529 --- server/controllers/LibraryController.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/controllers/LibraryController.js b/server/controllers/LibraryController.js index e81081cf..02ed2629 100644 --- a/server/controllers/LibraryController.js +++ b/server/controllers/LibraryController.js @@ -86,13 +86,17 @@ class LibraryController { return f }) for (var path of newFolderPaths) { - var success = await fs.ensureDir(path).then(() => true).catch((error) => { - Logger.error(`[LibraryController] Failed to ensure folder dir "${path}"`, error) - return false - }) - if (!success) { - return res.status(400).send(`Invalid folder directory "${path}"`) - } else { + var pathExists = await fs.pathExists(path) + if (!pathExists) { + // Ensure dir will recursively create directories which might be preferred over mkdir + var success = await fs.ensureDir(path).then(() => true).catch((error) => { + Logger.error(`[LibraryController] Failed to ensure folder dir "${path}"`, error) + return false + }) + if (!success) { + return res.status(400).send(`Invalid folder directory "${path}"`) + } + // Set permissions on newly created path await filePerms.setDefault(path) } }