MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / isSubdir

Function isSubdir

common/src/util/file.ts:322–335  ·  view source on GitHub ↗
(fromPath: string, toPath: string)

Source from the content-addressed store, hash-verified

320 * Returns true if the `toPath` is a subdirectory of `fromPath`.
321 */
322export function isSubdir(fromPath: string, toPath: string) {
323 const resolvedFrom = path.resolve(fromPath)
324 const resolvedTo = path.resolve(toPath)
325
326 if (process.platform === 'win32') {
327 const fromDrive = path.parse(resolvedFrom).root.toLowerCase()
328 const toDrive = path.parse(resolvedTo).root.toLowerCase()
329 if (fromDrive !== toDrive) {
330 return false
331 }
332 }
333
334 return !path.relative(resolvedFrom, resolvedTo).startsWith('..')
335}
336
337export function isValidProjectRoot(dir: string): boolean {
338 return !isSubdir(dir, os.homedir())

Callers 1

isValidProjectRootFunction · 0.85

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected