|
30 | 30 | * the same ledger without going through HTTP. |
31 | 31 | */ |
32 | 32 |
|
| 33 | +import { randomBytes } from 'node:crypto'; |
33 | 34 | import { |
34 | | - copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, renameSync, rmSync, unlinkSync, |
35 | | - writeFileSync, |
| 35 | + copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, unlinkSync, writeFileSync, |
36 | 36 | } from 'node:fs'; |
37 | 37 | import { homedir } from 'node:os'; |
38 | 38 | import { basename, dirname, join, resolve } from 'node:path'; |
@@ -330,7 +330,14 @@ export class LocalManifestSource { |
330 | 330 | const files = readdirSync(from).filter((name) => name.endsWith('.json')); |
331 | 331 | if (files.length === 0) return null; |
332 | 332 | 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); |
334 | 341 | try { |
335 | 342 | for (const name of files) copyFileSync(join(from, name), join(staging, name)); |
336 | 343 | renameSync(staging, this.dir); |
|
0 commit comments