fix(qmd): write index.yml atomically
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ced6d8f119
commit
abface2293
3 files changed
+23
-10
No files matched your search
@@ -54,14 +54,19 @@ export function readJson(path, fallback) {
|
||||
}
|
||||
}
|
||||
|
||||
// The state directory lives in the user profile; mode 0600 restricts the token on POSIX.
|
||||
export function writePrivateJson(path, value) {
|
||||
// Readers never see a half-written file: write a temp file next to the target, then rename it.
|
||||
export function writeTextAtomic(path, text, options = {}) {
|
||||
mkdirSync(dirname(path), { recursive: true });
|
||||
const temporary = `${path}.${process.pid}.tmp`;
|
||||
writeFileSync(temporary, JSON.stringify(value, null, 2) + '\n', { mode: 0o600 });
|
||||
writeFileSync(temporary, text, options);
|
||||
renameSync(temporary, path);
|
||||
}
|
||||
|
||||
// The state directory lives in the user profile; mode 0600 restricts the token on POSIX.
|
||||
export function writePrivateJson(path, value) {
|
||||
writeTextAtomic(path, JSON.stringify(value, null, 2) + '\n', { mode: 0o600 });
|
||||
}
|
||||
|
||||
let cachedPackageDir;
|
||||
|
||||
export function qmdPackageDir() {
|
||||
|
||||
Reference in new issue
Block a user