mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 09:01:10 +00:00
refactor(sandbox): share container-path utils and tighten fs bridge tests
This commit is contained in:
15
src/agents/sandbox/path-utils.ts
Normal file
15
src/agents/sandbox/path-utils.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import path from "node:path";
|
||||
|
||||
export function normalizeContainerPath(value: string): string {
|
||||
const normalized = path.posix.normalize(value);
|
||||
return normalized === "." ? "/" : normalized;
|
||||
}
|
||||
|
||||
export function isPathInsideContainerRoot(root: string, target: string): boolean {
|
||||
const normalizedRoot = normalizeContainerPath(root);
|
||||
const normalizedTarget = normalizeContainerPath(target);
|
||||
if (normalizedRoot === "/") {
|
||||
return true;
|
||||
}
|
||||
return normalizedTarget === normalizedRoot || normalizedTarget.startsWith(`${normalizedRoot}/`);
|
||||
}
|
||||
Reference in New Issue
Block a user