fix: add pathexists for paths.js to check symlink

This commit is contained in:
Fazri Gading
2026-01-26 12:09:48 +08:00
committed by GitHub
parent 20faf36b37
commit 94d4586b97

View File

@@ -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 });