mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
fix: clean up temp file if renameSync fails in writeFileAtomic
Co-Authored-By: mantra <mantra@stack-auth.com>
This commit is contained in:
parent
dc37e13515
commit
992ea13316
@ -98,7 +98,12 @@ function writeFileAtomic(configFilePath: string, content: string): void {
|
||||
mkdirSync(dir, { recursive: true });
|
||||
const tempPath = path.join(dir, `.stack.config.${Math.random().toString(36).slice(2)}.tmp`);
|
||||
writeFileSync(tempPath, content, "utf-8");
|
||||
renameSync(tempPath, configFilePath);
|
||||
try {
|
||||
renameSync(tempPath, configFilePath);
|
||||
} catch (error) {
|
||||
try { rmSync(tempPath); } catch { /* best-effort cleanup */ }
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function renderConfigObjectToFile(configFilePath: string, config: Config): void {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user