fix: scope claude doctor runtime checks

This commit is contained in:
Peter Steinberger
2026-04-29 05:44:36 +01:00
parent b3a8c7146b
commit 9023b120a1
5 changed files with 312 additions and 97 deletions

View File

@@ -25,18 +25,31 @@ function readOptionalUtf8(filePath) {
return fs.readFileSync(filePath, "utf8");
}
function removePathIfExists(targetPath) {
for (let attempt = 0; ; attempt += 1) {
function removePathIfExists(targetPath, options = {}) {
const retryDelays = options.retryTransient ? TEMP_REMOVE_RETRY_DELAYS_MS : [];
for (let attempt = 0; attempt <= retryDelays.length; attempt += 1) {
try {
fs.rmSync(targetPath, { recursive: true, force: true });
return;
return true;
} catch (error) {
if (!isTransientTempRemoveError(error) || attempt >= TEMP_REMOVE_RETRY_DELAYS_MS.length) {
if (!isTransientTempRemoveError(error)) {
throw error;
}
sleepSync(TEMP_REMOVE_RETRY_DELAYS_MS[attempt]);
const delay = retryDelays[attempt];
if (delay === undefined) {
if (options.ignoreTransient) {
return false;
}
throw error;
}
sleepSync(delay);
}
}
return true;
}
function removeOwnedTempPathBestEffort(targetPath) {
return removePathIfExists(targetPath, { retryTransient: true, ignoreTransient: true });
}
function isTransientTempRemoveError(error) {
@@ -102,7 +115,7 @@ function replaceDirAtomically(targetPath, sourcePath) {
targetParentDir,
`.openclaw-runtime-deps-backup-${sanitizeTempPrefixSegment(path.basename(targetPath))}-`,
);
removePathIfExists(backupPath);
removePathIfExists(backupPath, { retryTransient: true });
let movedExistingTarget = false;
try {
@@ -112,7 +125,7 @@ function replaceDirAtomically(targetPath, sourcePath) {
movedExistingTarget = true;
}
fs.renameSync(sourcePath, targetPath);
removePathIfExists(backupPath);
removeOwnedTempPathBestEffort(backupPath);
} catch (error) {
if (movedExistingTarget && !fs.existsSync(targetPath) && fs.existsSync(backupPath)) {
fs.renameSync(backupPath, targetPath);
@@ -138,7 +151,7 @@ function writeJsonAtomically(targetPath, value) {
});
fs.renameSync(tempPath, targetPath);
} finally {
removePathIfExists(tempDir);
removeOwnedTempPathBestEffort(tempDir);
}
}
@@ -1024,21 +1037,7 @@ function removeStaleRuntimeDepsTempDirs(pluginDir) {
if (!shouldRemoveRuntimeDepsTempDir(targetPath)) {
continue;
}
for (let attempt = 0; attempt <= TEMP_REMOVE_RETRY_DELAYS_MS.length; attempt += 1) {
try {
removePathIfExists(targetPath);
break;
} catch (error) {
if (!isTransientTempRemoveError(error)) {
throw error;
}
const delay = TEMP_REMOVE_RETRY_DELAYS_MS[attempt];
if (delay === undefined) {
break;
}
sleepSync(delay);
}
}
removeOwnedTempPathBestEffort(targetPath);
}
}
}
@@ -1134,7 +1133,7 @@ function stageInstalledRootRuntimeDeps(params) {
});
return true;
} finally {
removePathIfExists(path.dirname(stagedNodeModulesDir));
removeOwnedTempPathBestEffort(path.dirname(stagedNodeModulesDir));
}
}
@@ -1226,7 +1225,7 @@ function installPluginRuntimeDeps(params) {
generatedAt: new Date().toISOString(),
});
} finally {
removePathIfExists(tempInstallDir);
removeOwnedTempPathBestEffort(tempInstallDir);
}
}