mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-17 13:00:48 +00:00
38 lines
833 B
TypeScript
38 lines
833 B
TypeScript
import fs from "node:fs";
|
|
import fsPromises from "node:fs/promises";
|
|
|
|
const LSOF_CANDIDATES =
|
|
process.platform === "darwin"
|
|
? ["/usr/sbin/lsof", "/usr/bin/lsof"]
|
|
: ["/usr/bin/lsof", "/usr/sbin/lsof"];
|
|
|
|
async function canExecute(path: string): Promise<boolean> {
|
|
try {
|
|
await fsPromises.access(path, fs.constants.X_OK);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export async function resolveLsofCommand(): Promise<string> {
|
|
for (const candidate of LSOF_CANDIDATES) {
|
|
if (await canExecute(candidate)) {
|
|
return candidate;
|
|
}
|
|
}
|
|
return "lsof";
|
|
}
|
|
|
|
export function resolveLsofCommandSync(): string {
|
|
for (const candidate of LSOF_CANDIDATES) {
|
|
try {
|
|
fs.accessSync(candidate, fs.constants.X_OK);
|
|
return candidate;
|
|
} catch {
|
|
// keep trying
|
|
}
|
|
}
|
|
return "lsof";
|
|
}
|