From 94d4586b97ae774190e50255a706dbc75278d133 Mon Sep 17 00:00:00 2001 From: Fazri Gading Date: Mon, 26 Jan 2026 12:09:48 +0800 Subject: [PATCH] fix: add pathexists for paths.js to check symlink --- backend/core/paths.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/backend/core/paths.js b/backend/core/paths.js index 147bc46..bd381b4 100644 --- a/backend/core/paths.js +++ b/backend/core/paths.js @@ -181,16 +181,26 @@ async function getModsPath(customInstallPath = null) { if (!fs.existsSync(modsPath)) { // Check for broken symlink to avoid EEXIST/EPERM on mkdir let isBrokenLink = false; + let pathExists = false; try { - const stats = fs.lstatSync(modsPath); - if (stats.isSymbolicLink()) isBrokenLink = true; - } catch (e) { /* ignore */ } + const stats = fs.lstatSync(modsPath); + pathExists = true; + if (stats.isSymbolicLink()) { + // Check if target exists + try { + fs.statSync(modsPath); + } catch { + isBrokenLink = true; + } + } + } catch (e) { /* path doesn't exist at all */ } if (!isBrokenLink) { fs.unlinkSync(modsPath); // Remove broken symlink } - // Ensure the Mods directory exists - fs.mkdirSync(modsPath, { recursive: true }); + if (!pathExists || isBrokenLink) { + fs.mkdirSync(modsPath, { recursive: true }); + } } if (!fs.existsSync(disabledModsPath)) { fs.mkdirSync(disabledModsPath, { recursive: true });