Skip to content

Commit b4b7732

Browse files
author
Alex
committed
Direct write config
1 parent 1da42ef commit b4b7732

1 file changed

Lines changed: 3 additions & 11 deletions

File tree

server/config/Config.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,15 @@ class Config {
7575
// Don't overwrite the configuration if we failed during the initialization.
7676
try {
7777
if (!this._isInitialized) return;
78-
// Atomic write: write to temp then rename so we don't end up with truncated JSON
79-
const tmpPath = this.cfgPath + '.tmp';
80-
const data = JSON.stringify(this._cfg, undefined, 2);
8178
try {
82-
fs.writeFileSync(tmpPath, data, { encoding: 'utf8' });
83-
fs.renameSync(tmpPath, this.cfgPath);
79+
fs.writeFileSync(this.cfgPath, JSON.stringify(this._cfg, undefined, 2), { encoding: 'utf8' });
8480
console.log(`Updated configuration file`);
85-
} catch (e) {
81+
} catch (e:any) {
8682
if (e && (e.code === 'EACCES' || e.code === 'EROFS')) {
8783
console.error(`Configuration file not writable (${e.code}). Further config writes will be skipped. Mount a writable volume or adjust permissions for ${this.cfgPath}.`);
88-
// Prevent future attempts to spam errors
89-
this._isInitialized = false;
90-
try { if (fs.existsSync(tmpPath)) fs.unlinkSync(tmpPath); } catch { /* ignore */ }
84+
this._isInitialized = false; // suppress future attempts
9185
return;
9286
}
93-
// Clean up temp file if rename failed
94-
try { if (fs.existsSync(tmpPath)) fs.unlinkSync(tmpPath); } catch { /* ignore */ }
9587
throw e;
9688
}
9789
}

0 commit comments

Comments
 (0)