fix: resolve cross-platform EPERM permissions errors

modManager.js:
- Switch from hardcoded 'junction' to dynamic symlink type based on OS (fixing Linux EPERM).
- Add retry logic for directory removal to handle file locking race conditions.
- Improve broken symlink detection during profile sync.

gameManager.js:
- Implement retry loop (3 attempts) for game directory removal in updateGameFiles to prevent EBUSY/EPERM errors on Windows.

paths.js:
- Prevent fs.mkdirSync failure in getModsPath by pre-checking for broken symbolic links.
This commit is contained in:
Fazri Gading
2026-01-26 08:19:13 +08:00
parent 4cd0539ce3
commit 615ee5cadc
3 changed files with 53 additions and 11 deletions

View File

@@ -179,8 +179,17 @@ async function getModsPath(customInstallPath = null) {
const profilesPath = path.join(userDataPath, 'Profiles');
if (!fs.existsSync(modsPath)) {
// Ensure the Mods directory exists
fs.mkdirSync(modsPath, { recursive: true });
// Check for broken symlink to avoid EEXIST/EPERM on mkdir
let isBrokenLink = false;
try {
const stats = fs.lstatSync(modsPath);
if (stats.isSymbolicLink()) isBrokenLink = true;
} catch (e) { /* ignore */ }
if (!isBrokenLink) {
// Ensure the Mods directory exists
fs.mkdirSync(modsPath, { recursive: true });
}
}
if (!fs.existsSync(disabledModsPath)) {
fs.mkdirSync(disabledModsPath, { recursive: true });