global-app-skill 0.1.0 → 0.1.1
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.
- package/package.json +1 -1
- package/src/resources.mjs +20 -4
package/package.json
CHANGED
package/src/resources.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { lstat, mkdir, mkdtemp, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
4
5
|
import { gunzipSync } from 'node:zlib';
|
|
5
6
|
import { FEED, MAX_BYTES, MODES, sha256, validateManifest, validateMode } from './protocol.mjs';
|
|
6
7
|
|
|
@@ -81,10 +82,25 @@ export async function resolveContext({ mode, feed = FEED, cacheDir, progress = (
|
|
|
81
82
|
await writeFile(target, file.content, { flag: 'wx' });
|
|
82
83
|
}
|
|
83
84
|
await writeFile(path.join(staging, 'manifest.json'), JSON.stringify(manifest));
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
const lock = path.join(releases, `.${manifest.resourceHash}.lock`);
|
|
86
|
+
const deadline = Date.now() + 5000;
|
|
87
|
+
for (;;) {
|
|
88
|
+
try { await mkdir(lock); break; }
|
|
89
|
+
catch (error) {
|
|
90
|
+
if (error.code !== 'EEXIST') throw error;
|
|
91
|
+
if (Date.now() >= deadline) throw new Error(`Snapshot publication is locked: ${lock}; retry after the other updater finishes. Remove a stale lock only when no updater is running.`);
|
|
92
|
+
await delay(50);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
// Recheck under the lock so a concurrent resolver's completed snapshot
|
|
97
|
+
// cannot be deleted after an earlier ENOENT integrity check.
|
|
98
|
+
if (!(await validSnapshot(resourceRoot, manifest.resourceHash))) {
|
|
99
|
+
await rm(resourceRoot, { recursive: true, force: true });
|
|
100
|
+
await rename(staging, resourceRoot);
|
|
101
|
+
}
|
|
102
|
+
} finally {
|
|
103
|
+
await rm(lock, { recursive: true, force: true });
|
|
88
104
|
}
|
|
89
105
|
updated = true;
|
|
90
106
|
} finally { await rm(staging, { recursive: true, force: true }); }
|