mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 08:10:21 +00:00
refactor(exec): dedupe executable candidate resolution
This commit is contained in:
@@ -3,8 +3,10 @@ import path from "node:path";
|
||||
import { matchesExecAllowlistPattern } from "./exec-allowlist-pattern.js";
|
||||
import type { ExecAllowlistEntry } from "./exec-approvals.js";
|
||||
import { resolveExecWrapperTrustPlan } from "./exec-wrapper-trust-plan.js";
|
||||
import { resolveExecutablePath as resolveExecutableCandidatePath } from "./executable-path.js";
|
||||
import { expandHomePrefix } from "./home-dir.js";
|
||||
import {
|
||||
resolveExecutablePath as resolveExecutableCandidatePath,
|
||||
resolveExecutablePathCandidate,
|
||||
} from "./executable-path.js";
|
||||
|
||||
export type ExecutableResolution = {
|
||||
rawExecutable: string;
|
||||
@@ -45,10 +47,6 @@ function parseFirstToken(command: string): string | null {
|
||||
return match ? match[0] : null;
|
||||
}
|
||||
|
||||
function isDriveLessWindowsRootedPath(value: string): boolean {
|
||||
return process.platform === "win32" && /^:[\\/]/.test(value);
|
||||
}
|
||||
|
||||
function tryResolveRealpath(filePath: string | undefined): string | undefined {
|
||||
if (!filePath) {
|
||||
return undefined;
|
||||
@@ -179,18 +177,10 @@ function resolveExecutableCandidatePathFromResolution(
|
||||
if (!raw) {
|
||||
return undefined;
|
||||
}
|
||||
const expanded = raw.startsWith("~") ? expandHomePrefix(raw) : raw;
|
||||
if (isDriveLessWindowsRootedPath(expanded)) {
|
||||
return undefined;
|
||||
}
|
||||
if (!expanded.includes("/") && !expanded.includes("\\")) {
|
||||
return undefined;
|
||||
}
|
||||
if (path.isAbsolute(expanded)) {
|
||||
return expanded;
|
||||
}
|
||||
const base = cwd && cwd.trim() ? cwd.trim() : process.cwd();
|
||||
return path.resolve(base, expanded);
|
||||
return resolveExecutablePathCandidate(raw, {
|
||||
cwd,
|
||||
requirePathSeparator: true,
|
||||
});
|
||||
}
|
||||
|
||||
export function resolveExecutionTargetResolution(
|
||||
|
||||
Reference in New Issue
Block a user