mirror of
https://github.com/openclaw/openclaw.git
synced 2026-10-04 02:00:10 +00:00
31 lines
953 B
JavaScript
31 lines
953 B
JavaScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
|
|
export function assertRealPathInside(parentPath, childPath, label) {
|
|
const parentRealPath = fs.realpathSync(parentPath);
|
|
const childRealPath = fs.realpathSync(childPath);
|
|
if (
|
|
childRealPath !== parentRealPath &&
|
|
!childRealPath.startsWith(`${parentRealPath}${path.sep}`)
|
|
) {
|
|
throw new Error(`${label} resolved outside ${parentPath}: ${childRealPath}`);
|
|
}
|
|
}
|
|
|
|
export function resolveHomePath(value) {
|
|
if (value === "~") {
|
|
return process.env.HOME;
|
|
}
|
|
if (value?.startsWith("~/") || value?.startsWith("~\\")) {
|
|
return path.join(process.env.HOME, value.slice(2));
|
|
}
|
|
return value;
|
|
}
|
|
|
|
export function resolveOpenClawStateDir() {
|
|
return process.env.OPENCLAW_STATE_DIR || path.join(process.env.HOME, ".openclaw");
|
|
}
|
|
|
|
export function resolveOpenClawConfigPath() {
|
|
return process.env.OPENCLAW_CONFIG_PATH || path.join(resolveOpenClawStateDir(), "openclaw.json");
|
|
}
|