diff --git a/git-ai/src/commands/InitCommand.ts b/git-ai/src/commands/InitCommand.ts index a382f83..23398e1 100644 --- a/git-ai/src/commands/InitCommand.ts +++ b/git-ai/src/commands/InitCommand.ts @@ -37,12 +37,12 @@ function atomicWriteFileSync(filePath: string, content: string): void { const tempPath = path.join(dir, `.tmp-${process.pid}-${Date.now()}`); const fd = fs.openSync(tempPath, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY, 0o600); try { - fs.writeFileSync(fd, content); - fs.fsyncSync(fd); - } finally { - fs.closeSync(fd); - } - try { + try { + fs.writeFileSync(fd, content); + fs.fsyncSync(fd); + } finally { + fs.closeSync(fd); + } fs.renameSync(tempPath, filePath); } catch (error) { try { fs.unlinkSync(tempPath); } catch { /* best-effort cleanup */ } diff --git a/git-ai/src/services/ConfigService.ts b/git-ai/src/services/ConfigService.ts index 62095cd..a2de320 100644 --- a/git-ai/src/services/ConfigService.ts +++ b/git-ai/src/services/ConfigService.ts @@ -59,12 +59,12 @@ export class ConfigService { const tempPath = path.join(path.dirname(configPath), `.tmp-${process.pid}-${Date.now()}`); const fd = fs.openSync(tempPath, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY, 0o600); try { - fs.writeFileSync(fd, JSON.stringify(validated, null, 2)); - fs.fsyncSync(fd); - } finally { - fs.closeSync(fd); - } - try { + try { + fs.writeFileSync(fd, JSON.stringify(validated, null, 2)); + fs.fsyncSync(fd); + } finally { + fs.closeSync(fd); + } fs.renameSync(tempPath, configPath); } catch (error) { try { fs.unlinkSync(tempPath); } catch { /* best-effort cleanup */ }