refactor(commands): dedupe cleanup path resolution

This commit is contained in:
Peter Steinberger
2026-02-15 17:09:12 +00:00
parent da2fde7b6f
commit 3ce0e80f57
4 changed files with 57 additions and 13 deletions

View File

@@ -29,6 +29,23 @@ export function collectWorkspaceDirs(cfg: OpenClawConfig | undefined): string[]
return [...dirs];
}
export function buildCleanupPlan(params: {
cfg: OpenClawConfig | undefined;
stateDir: string;
configPath: string;
oauthDir: string;
}): {
configInsideState: boolean;
oauthInsideState: boolean;
workspaceDirs: string[];
} {
return {
configInsideState: isPathWithin(params.configPath, params.stateDir),
oauthInsideState: isPathWithin(params.oauthDir, params.stateDir),
workspaceDirs: collectWorkspaceDirs(params.cfg),
};
}
export function isPathWithin(child: string, parent: string): boolean {
const relative = path.relative(parent, child);
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));