

























@@ -25,18 +25,31 @@ function readOptionalUtf8(filePath) {
2525return fs.readFileSync(filePath, "utf8");
2626}
272728-function removePathIfExists(targetPath) {
29-for (let attempt = 0; ; attempt += 1) {
28+function removePathIfExists(targetPath, options = {}) {
29+const retryDelays = options.retryTransient ? TEMP_REMOVE_RETRY_DELAYS_MS : [];
30+for (let attempt = 0; attempt <= retryDelays.length; attempt += 1) {
3031try {
3132fs.rmSync(targetPath, { recursive: true, force: true });
32-return;
33+return true;
3334} catch (error) {
34-if (!isTransientTempRemoveError(error) || attempt >= TEMP_REMOVE_RETRY_DELAYS_MS.length) {
35+if (!isTransientTempRemoveError(error)) {
36+throw error;
37+}
38+const delay = retryDelays[attempt];
39+if (delay === undefined) {
40+if (options.ignoreTransient) {
41+return false;
42+}
3543throw error;
3644}
37-sleepSync(TEMP_REMOVE_RETRY_DELAYS_MS[attempt]);
45+sleepSync(delay);
3846}
3947}
48+return true;
49+}
50+51+function removeOwnedTempPathBestEffort(targetPath) {
52+return removePathIfExists(targetPath, { retryTransient: true, ignoreTransient: true });
4053}
41544255function isTransientTempRemoveError(error) {
@@ -102,7 +115,7 @@ function replaceDirAtomically(targetPath, sourcePath) {
102115targetParentDir,
103116`.openclaw-runtime-deps-backup-${sanitizeTempPrefixSegment(path.basename(targetPath))}-`,
104117);
105-removePathIfExists(backupPath);
118+removePathIfExists(backupPath, { retryTransient: true });
106119107120let movedExistingTarget = false;
108121try {
@@ -112,7 +125,7 @@ function replaceDirAtomically(targetPath, sourcePath) {
112125movedExistingTarget = true;
113126}
114127fs.renameSync(sourcePath, targetPath);
115-removePathIfExists(backupPath);
128+removeOwnedTempPathBestEffort(backupPath);
116129} catch (error) {
117130if (movedExistingTarget && !fs.existsSync(targetPath) && fs.existsSync(backupPath)) {
118131fs.renameSync(backupPath, targetPath);
@@ -138,7 +151,7 @@ function writeJsonAtomically(targetPath, value) {
138151});
139152fs.renameSync(tempPath, targetPath);
140153} finally {
141-removePathIfExists(tempDir);
154+removeOwnedTempPathBestEffort(tempDir);
142155}
143156}
144157@@ -1024,21 +1037,7 @@ function removeStaleRuntimeDepsTempDirs(pluginDir) {
10241037if (!shouldRemoveRuntimeDepsTempDir(targetPath)) {
10251038continue;
10261039}
1027-for (let attempt = 0; attempt <= TEMP_REMOVE_RETRY_DELAYS_MS.length; attempt += 1) {
1028-try {
1029-removePathIfExists(targetPath);
1030-break;
1031-} catch (error) {
1032-if (!isTransientTempRemoveError(error)) {
1033-throw error;
1034-}
1035-const delay = TEMP_REMOVE_RETRY_DELAYS_MS[attempt];
1036-if (delay === undefined) {
1037-break;
1038-}
1039-sleepSync(delay);
1040-}
1041-}
1040+removeOwnedTempPathBestEffort(targetPath);
10421041}
10431042}
10441043}
@@ -1134,7 +1133,7 @@ function stageInstalledRootRuntimeDeps(params) {
11341133});
11351134return true;
11361135} finally {
1137-removePathIfExists(path.dirname(stagedNodeModulesDir));
1136+removeOwnedTempPathBestEffort(path.dirname(stagedNodeModulesDir));
11381137}
11391138}
11401139@@ -1226,7 +1225,7 @@ function installPluginRuntimeDeps(params) {
12261225generatedAt: new Date().toISOString(),
12271226});
12281227} finally {
1229-removePathIfExists(tempInstallDir);
1228+removeOwnedTempPathBestEffort(tempInstallDir);
12301229}
12311230}
12321231此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。