Download src/server/services/filesystemAccessRoots.ts from chenbhao/codev: direct link, hf CLI and curl.
- Browser
- Download file 956 Bytes
-
https://huggingface.co/chenbhao/codev/resolve/afbc7edaae4e6bb0102ba024b49ce8be89d2264c/src/server/services/filesystemAccessRoots.ts
- Command line
-
hf download hf://chenbhao/codev@afbc7edaae4e6bb0102ba024b49ce8be89d2264c/src/server/services/filesystemAccessRoots.ts
-
curl -L -o filesystemAccessRoots.ts https://huggingface.co/chenbhao/codev/resolve/afbc7edaae4e6bb0102ba024b49ce8be89d2264c/src/server/services/filesystemAccessRoots.ts
956 Bytes
| import * as path from 'node:path' | |
| const registeredRoots = new Set<string>() | |
| function normalizeComparablePath(filePath: string): string { | |
| const resolved = path.resolve(filePath) | |
| return process.platform === 'win32' ? resolved.toLowerCase() : resolved | |
| } | |
| function isWithinRoot(targetPath: string, rootPath: string): boolean { | |
| const target = normalizeComparablePath(targetPath) | |
| const root = normalizeComparablePath(rootPath) | |
| return target === root || target.startsWith(`${root}${path.sep}`) | |
| } | |
| export function registerFilesystemAccessRoot(rootPath: string | null | undefined): void { | |
| if (!rootPath) return | |
| registeredRoots.add(path.resolve(rootPath)) | |
| } | |
| export function isWithinRegisteredFilesystemRoot(targetPath: string): boolean { | |
| for (const rootPath of registeredRoots) { | |
| if (isWithinRoot(targetPath, rootPath)) return true | |
| } | |
| return false | |
| } | |
| export function clearFilesystemAccessRootsForTests(): void { | |
| registeredRoots.clear() | |
| } | |