fix(openfleet): keep the settings file's exact mode across a rewrite (#240)

writeSettings created its temp file with the original mode, but the create
mode is filtered through the umask, so a rewrite could leave the settings
file with fewer permission bits than it had. It now chmods the temp file to
the mode outright before the rename.

Found and fixed by a moshcode work agent (fleet sweep); verify:
npx vitest run ./src/hooks-install.test.ts (packages/openfleet).

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Anthony Ettinger 2026-10-17 05:14:50 -07:00 • committed by GitHub
parent ef35139f04
commit 5c0e38a5c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,7 +15,7 @@
* command is marker enough.
*/
import { mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
import { chmodSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { dirname, join } from "node:path";
import type { Env } from "./store.js";
@ -117,6 +117,9 @@ export function writeSettings(file: string, data: Json, mode: number): void {
// would otherwise leave it truncated.
const tmp = `${file}.logicsrc-${process.pid}`;
writeFileSync(tmp, `${JSON.stringify(data, null, 2)}\n`, { mode });
// The create mode is filtered through the umask; set it outright so the
// file keeps exactly the mode it had.
chmodSync(tmp, mode);
renameSync(tmp, file);
}