gm-kilo 2.0.825 → 2.0.827
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/bin/bootstrap.js +21 -1
- package/package.json +1 -1
package/bin/bootstrap.js
CHANGED
|
@@ -229,6 +229,16 @@ async function downloadWithRetry(url, destPath) {
|
|
|
229
229
|
throw lastErr;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
+
function isLockStale(lockPath) {
|
|
233
|
+
try {
|
|
234
|
+
const st = fs.statSync(lockPath);
|
|
235
|
+
if (Date.now() - st.mtimeMs > LOCK_STALE_MS) return true;
|
|
236
|
+
const owner = parseInt(fs.readFileSync(lockPath, 'utf8').trim(), 10);
|
|
237
|
+
if (Number.isFinite(owner) && !pidAlive(owner)) return true;
|
|
238
|
+
} catch (_) { return true; }
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
|
|
232
242
|
function pruneOldVersions(root, keepVersion) {
|
|
233
243
|
try {
|
|
234
244
|
const entries = fs.readdirSync(root);
|
|
@@ -237,7 +247,8 @@ function pruneOldVersions(root, keepVersion) {
|
|
|
237
247
|
if (e === `v${keepVersion}`) continue;
|
|
238
248
|
const dir = path.join(root, e);
|
|
239
249
|
const lock = path.join(dir, '.lock');
|
|
240
|
-
if (fs.existsSync(lock)) continue;
|
|
250
|
+
if (fs.existsSync(lock) && !isLockStale(lock)) continue;
|
|
251
|
+
if (fs.existsSync(lock)) { try { fs.unlinkSync(lock); } catch (_) {} }
|
|
241
252
|
try {
|
|
242
253
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
243
254
|
log(`pruned ${dir}`);
|
|
@@ -279,6 +290,15 @@ async function bootstrap(opts) {
|
|
|
279
290
|
}
|
|
280
291
|
|
|
281
292
|
const tmpPath = `${finalPath}.partial`;
|
|
293
|
+
if (fs.existsSync(tmpPath)) {
|
|
294
|
+
try {
|
|
295
|
+
const st = fs.statSync(tmpPath);
|
|
296
|
+
if (Date.now() - st.mtimeMs > LOCK_STALE_MS) {
|
|
297
|
+
fs.unlinkSync(tmpPath);
|
|
298
|
+
log(`cleared stale partial: ${tmpPath}`);
|
|
299
|
+
}
|
|
300
|
+
} catch (_) {}
|
|
301
|
+
}
|
|
282
302
|
const url = `https://github.com/${RELEASE_REPO}/releases/download/v${version}/${binName}`;
|
|
283
303
|
await downloadWithRetry(url, tmpPath);
|
|
284
304
|
|