MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getDirectoryForPath

Function getDirectoryForPath

src/utils/path.ts:109–125  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

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