MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / getDirectoryForPath

Function getDirectoryForPath

source code/utils/path.ts:111–127  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

109 * @returns The directory path
110 */
111export function getDirectoryForPath(path: string): string {
112 const absolutePath = expandPath(path)
113 // SECURITY: Skip filesystem operations for UNC paths to prevent NTLM credential leaks.
114 if (absolutePath.startsWith('\\\\') || absolutePath.startsWith('//')) {
115 return dirname(absolutePath)
116 }
117 try {
118 const stats = getFsImplementation().statSync(absolutePath)
119 if (stats.isDirectory()) {
120 return absolutePath
121 }
122 } catch {
123 // Path doesn't exist or can't be accessed
124 }
125 // If it's not a directory or doesn't exist, return the parent directory
126 return dirname(absolutePath)
127}
128
129/**
130 * Checks if a path contains directory traversal patterns that navigate to parent directories.

Callers 5

createPathCheckerFunction · 0.85
getFilePermissionOptionsFunction · 0.85
generateSuggestionsFunction · 0.85

Calls 2

expandPathFunction · 0.85
getFsImplementationFunction · 0.85

Tested by

no test coverage detected