MCPcopy Create free account
hub / github.com/apache/maka / pathWithinRoot

Function pathWithinRoot

packages/core/src/absolute-path.ts:26–44  ·  view source on GitHub ↗
(path: string, root: string)

Source from the content-addressed store, hash-verified

24}
25
26export function pathWithinRoot(path: string, root: string): boolean {
27 const normalizedPath = comparablePath(path);
28 const normalizedRoot = comparablePath(root);
29 if (
30 !normalizedPath ||
31 !normalizedRoot ||
32 !isNormalizedAbsolutePath(normalizedPath) ||
33 !isNormalizedAbsolutePath(normalizedRoot) ||
34 isWindowsDrivePath(path) !== isWindowsDrivePath(root)
35 ) {
36 return false;
37 }
38 if (normalizedRoot === '/') return normalizedPath.startsWith('/');
39 const separator = isWindowsDrivePath(root) ? '\\' : '/';
40 const subtreePrefix = normalizedRoot.endsWith(separator)
41 ? normalizedRoot
42 : `${normalizedRoot}${separator}`;
43 return normalizedPath === normalizedRoot || normalizedPath.startsWith(subtreePrefix);
44}
45
46export function samePath(a: string, b: string): boolean {
47 if (isWindowsDrivePath(a) !== isWindowsDrivePath(b)) return false;

Callers 11

permissionCoversFunction · 0.85
profileContainsExpansionFunction · 0.85
pathCoveredByRootFunction · 0.85
entryCoversFunction · 0.85
entryMatchesPathFunction · 0.85
relativeSegmentsFunction · 0.85

Calls 3

comparablePathFunction · 0.85
isNormalizedAbsolutePathFunction · 0.85
isWindowsDrivePathFunction · 0.85

Tested by

no test coverage detected