mirror of
https://git.sanhost.net/sanasol/hytale-f2p
synced 2026-02-26 09:21:48 -03:00
fix: add pathexists for paths.js to check symlink
This commit is contained in:
@@ -181,17 +181,27 @@ async function getModsPath(customInstallPath = null) {
|
|||||||
if (!fs.existsSync(modsPath)) {
|
if (!fs.existsSync(modsPath)) {
|
||||||
// Check for broken symlink to avoid EEXIST/EPERM on mkdir
|
// Check for broken symlink to avoid EEXIST/EPERM on mkdir
|
||||||
let isBrokenLink = false;
|
let isBrokenLink = false;
|
||||||
|
let pathExists = false;
|
||||||
try {
|
try {
|
||||||
const stats = fs.lstatSync(modsPath);
|
const stats = fs.lstatSync(modsPath);
|
||||||
if (stats.isSymbolicLink()) isBrokenLink = true;
|
pathExists = true;
|
||||||
} catch (e) { /* ignore */ }
|
if (stats.isSymbolicLink()) {
|
||||||
|
// Check if target exists
|
||||||
|
try {
|
||||||
|
fs.statSync(modsPath);
|
||||||
|
} catch {
|
||||||
|
isBrokenLink = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) { /* path doesn't exist at all */ }
|
||||||
|
|
||||||
if (!isBrokenLink) {
|
if (!isBrokenLink) {
|
||||||
fs.unlinkSync(modsPath); // Remove broken symlink
|
fs.unlinkSync(modsPath); // Remove broken symlink
|
||||||
}
|
}
|
||||||
// Ensure the Mods directory exists
|
if (!pathExists || isBrokenLink) {
|
||||||
fs.mkdirSync(modsPath, { recursive: true });
|
fs.mkdirSync(modsPath, { recursive: true });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!fs.existsSync(disabledModsPath)) {
|
if (!fs.existsSync(disabledModsPath)) {
|
||||||
fs.mkdirSync(disabledModsPath, { recursive: true });
|
fs.mkdirSync(disabledModsPath, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user