mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 14:34:32 +00:00
fix(update): harden global updates
This commit is contained in:
@@ -11,6 +11,7 @@ export type CommandRunner = (
|
||||
|
||||
const PRIMARY_PACKAGE_NAME = "openclaw";
|
||||
const ALL_PACKAGE_NAMES = [PRIMARY_PACKAGE_NAME] as const;
|
||||
const GLOBAL_RENAME_PREFIX = ".";
|
||||
|
||||
async function pathExists(targetPath: string): Promise<boolean> {
|
||||
try {
|
||||
@@ -142,3 +143,39 @@ export function globalInstallArgs(manager: GlobalInstallManager, spec: string):
|
||||
}
|
||||
return ["npm", "i", "-g", spec];
|
||||
}
|
||||
|
||||
export async function cleanupGlobalRenameDirs(params: {
|
||||
globalRoot: string;
|
||||
packageName: string;
|
||||
}): Promise<{ removed: string[] }> {
|
||||
const removed: string[] = [];
|
||||
const root = params.globalRoot.trim();
|
||||
const name = params.packageName.trim();
|
||||
if (!root || !name) {
|
||||
return { removed };
|
||||
}
|
||||
const prefix = `${GLOBAL_RENAME_PREFIX}${name}-`;
|
||||
let entries: string[] = [];
|
||||
try {
|
||||
entries = await fs.readdir(root);
|
||||
} catch {
|
||||
return { removed };
|
||||
}
|
||||
for (const entry of entries) {
|
||||
if (!entry.startsWith(prefix)) {
|
||||
continue;
|
||||
}
|
||||
const target = path.join(root, entry);
|
||||
try {
|
||||
const stat = await fs.lstat(target);
|
||||
if (!stat.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
await fs.rm(target, { recursive: true, force: true });
|
||||
removed.push(entry);
|
||||
} catch {
|
||||
// ignore cleanup failures
|
||||
}
|
||||
}
|
||||
return { removed };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user