fix(settings): clean up orphaned temp files and harden atomic writes

This commit is contained in:
Bohdan Triapitsyn
2026-08-22 11:55:38 +03:00
parent 735a9463ca
commit fcbe2c0414
8 changed files with 142 additions and 25 deletions
@@ -536,8 +536,13 @@ export const createProjectConfigRuntime = (deps) => {
};
await fsPromises.mkdir(parentDirectory, { recursive: true });
await fsPromises.writeFile(temporaryPath, JSON.stringify(merged, null, 2), 'utf8');
await fsPromises.rename(temporaryPath, filePath);
try {
await fsPromises.writeFile(temporaryPath, JSON.stringify(merged, null, 2), 'utf8');
await fsPromises.rename(temporaryPath, filePath);
} catch (error) {
await fsPromises.rm(temporaryPath, { force: true }).catch(() => {});
throw error;
}
};
const withProjectWriteLock = async (projectID, mutate) => {