mirror of
https://github.com/amiayweb/Hytale-F2P.git
synced 2026-02-26 18:41:58 -03:00
fix: add pathexists for paths.js to check symlink
This commit is contained in:
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user