toolcrib 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/lib/zip.js +21 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcrib",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Bootstrap the toolcrib UI toolkit into your project",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/lib/zip.js CHANGED
@@ -32,10 +32,28 @@ export function powerShellQuote(value) {
32
32
  export async function extractZip(zipBuffer, targetDir) {
33
33
  await fsp.mkdir(targetDir, { recursive: true });
34
34
 
35
- const tmpZipPath = path.join(os.tmpdir(), `toolcrib-${Date.now()}.zip`);
36
- await fsp.writeFile(tmpZipPath, zipBuffer);
35
+ // A bare `Date.now()`-keyed filename collides under real concurrent use:
36
+ // commands/merge.js (old + new release) and `init --with-tests` (core +
37
+ // tests release) both fetch two releases via Promise.allSettled, and each
38
+ // independently calls extractZip() — two calls landing in the same
39
+ // millisecond used to share one tmpZipPath, so one call's write/unlink
40
+ // could clobber or delete the file out from under the other's still-
41
+ // running Expand-Archive/unzip, silently corrupting one extraction (both
42
+ // ending up with identical content) or crashing outright. Found for real
43
+ // running a v0.14.0->v0.15.0 `merge` simulation before the v0.15.0 release
44
+ // (see issue #488). fsp.mkdtemp gives each call its own directory, the
45
+ // same pattern lib/release.js's fetchRelease/fetchTestsRelease already
46
+ // use for their own tempDirs — no shared path between concurrent calls.
47
+ const tmpDir = await fsp.mkdtemp(path.join(os.tmpdir(), 'toolcrib-zip-'));
48
+ const tmpZipPath = path.join(tmpDir, 'archive.zip');
37
49
 
38
50
  try {
51
+ // Inside the try, not before it — caught in review (Gemini, PR #489):
52
+ // a write failure here (disk full, permissions) used to abort before
53
+ // the try/finally even started, leaking tmpDir the same way the
54
+ // pre-fix code leaked on every concurrent collision.
55
+ await fsp.writeFile(tmpZipPath, zipBuffer);
56
+
39
57
  if (process.platform === 'win32') {
40
58
  // PowerShell's Expand-Archive ships on all modern Windows installs.
41
59
  //
@@ -60,7 +78,7 @@ export async function extractZip(zipBuffer, targetDir) {
60
78
  await execFileAsync('unzip', ['-o', '-q', tmpZipPath, '-d', targetDir]);
61
79
  }
62
80
  } finally {
63
- await fsp.unlink(tmpZipPath).catch(() => {});
81
+ await fsp.rm(tmpDir, { recursive: true, force: true }).catch(() => {});
64
82
  }
65
83
  }
66
84