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

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 12:10:46 +00:00
parent ef35139f04
commit b887f56ac5

View file

@ -15,7 +15,7 @@
* command is marker enough. * 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 { homedir } from "node:os";
import { dirname, join } from "node:path"; import { dirname, join } from "node:path";
import type { Env } from "./store.js"; 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. // would otherwise leave it truncated.
const tmp = `${file}.logicsrc-${process.pid}`; const tmp = `${file}.logicsrc-${process.pid}`;
writeFileSync(tmp, `${JSON.stringify(data, null, 2)}\n`, { mode }); 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); renameSync(tmp, file);
} }