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

Function findProjectDir

source code/utils/sessionStoragePortable.ts:356–382  ·  view source on GitHub ↗
(
  projectPath: string,
)

Source from the content-addressed store, hash-verified

354 * prefix-based scanning when the exact match doesn't exist.
355 */
356export async function findProjectDir(
357 projectPath: string,
358): Promise<string | undefined> {
359 const exact = getProjectDir(projectPath)
360 try {
361 await readdir(exact)
362 return exact
363 } catch {
364 // Exact match failed — for short paths this means no sessions exist.
365 // For long paths, try prefix matching to handle hash mismatches.
366 const sanitized = sanitizePath(projectPath)
367 if (sanitized.length <= MAX_SANITIZED_LENGTH) {
368 return undefined
369 }
370 const prefix = sanitized.slice(0, MAX_SANITIZED_LENGTH)
371 const projectsDir = getProjectsDir()
372 try {
373 const dirents = await readdir(projectsDir, { withFileTypes: true })
374 const match = dirents.find(
375 d => d.isDirectory() && d.name.startsWith(prefix + '-'),
376 )
377 return match ? join(projectsDir, match.name) : undefined
378 } catch {
379 return undefined
380 }
381 }
382}
383
384/**
385 * Resolve a sessionId to its on-disk JSONL file path.

Callers 2

gatherProjectCandidatesFunction · 0.85
resolveSessionFilePathFunction · 0.85

Calls 4

readdirFunction · 0.85
getProjectDirFunction · 0.70
sanitizePathFunction · 0.70
getProjectsDirFunction · 0.70

Tested by

no test coverage detected