Skip to content

Commit c4fb1fe

Browse files
committed
fix(cloud-connection): stage the ledger adoption copy without mkdtempSync, so main's scratch scan reads green again
The #30217 adoption step created its staging directory with mkdtempSync under dirname(this.dir), a base resolved at run time. The dispatch-gates self-test holds every mkdtempSync site to a base its source scan can read, so the `Lint · PM dispatch-gates` lane has been red on main since #30351. The staging directory is now an exclusive, non-recursive mkdirSync of a randomly named sibling: still unique, still renamed into place, still removed on failure. Claude-Session: https://claude.ai/code/session_01Utp6CZ9g1bEV7DPMneGKAx Co-authored-by: Claude <noreply@anthropic.com>
1 parent f506b79 commit c4fb1fe

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@objectstack/cloud-connection': patch
3+
---
4+
5+
Clause-②: no
6+
Metadata-protocol: none
7+
8+
The one-time copy of the working-directory install ledger into its `OS_HOME` location (#30217) now creates its staging directory with an exclusive `mkdirSync` of a randomly named sibling instead of `mkdtempSync`. Behaviour is unchanged: the copy still lands in a unique sibling of the ledger directory, is renamed into place, and is removed if the copy fails. This repairs the red `main` build (#30467), where the repository's in-tree scratch scan could not read the `mkdtempSync` base.

‎packages/cloud-connection/src/local-manifest-source.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
* the same ledger without going through HTTP.
3131
*/
3232

33+
import { randomBytes } from 'node:crypto';
3334
import {
34-
copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, renameSync, rmSync, unlinkSync,
35-
writeFileSync,
35+
copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, unlinkSync, writeFileSync,
3636
} from 'node:fs';
3737
import { homedir } from 'node:os';
3838
import { basename, dirname, join, resolve } from 'node:path';
@@ -330,7 +330,14 @@ export class LocalManifestSource {
330330
const files = readdirSync(from).filter((name) => name.endsWith('.json'));
331331
if (files.length === 0) return null;
332332
mkdirSync(dirname(this.dir), { recursive: true });
333-
const staging = mkdtempSync(join(dirname(this.dir), `.${basename(this.dir)}.adopting-`));
333+
// A unique sibling, created exclusively: a non-recursive mkdirSync
334+
// throws EEXIST rather than reuse a directory that is already there,
335+
// which is the guarantee mkdtempSync gave. mkdtempSync is not used
336+
// because the repo's in-tree scratch scan holds every mkdtempSync to a
337+
// base it can read from source, and this base is the ledger location
338+
// resolved at run time.
339+
const staging = join(dirname(this.dir), `.${basename(this.dir)}.adopting-${randomBytes(6).toString('hex')}`);
340+
mkdirSync(staging);
334341
try {
335342
for (const name of files) copyFileSync(join(from, name), join(staging, name));
336343
renameSync(staging, this.dir);

0 commit comments

Comments
 (0)