MCPcopy
hub / github.com/coder/mux / validateProjectPath

Function validateProjectPath

src/node/utils/pathUtils.ts:61–93  ·  view source on GitHub ↗
(inputPath: string)

Source from the content-addressed store, hash-verified

59 * // => { valid: false, error: "Path does not exist: /home/user/nonexistent" }
60 */
61export async function validateProjectPath(inputPath: string): Promise<PathValidationResult> {
62 // Expand tilde if present
63 const expandedPath = expandTilde(inputPath);
64
65 // Normalize to resolve any .. or . in the path, then strip trailing slashes
66 const normalizedPath = stripTrailingSlashes(path.normalize(expandedPath));
67
68 // Check if path exists
69 try {
70 const stats = await fs.stat(normalizedPath);
71
72 // Check if it's a directory
73 if (!stats.isDirectory()) {
74 return {
75 valid: false,
76 error: `Path is not a directory: ${normalizedPath}`,
77 };
78 }
79 } catch (err) {
80 if ((err as NodeJS.ErrnoException).code === "ENOENT") {
81 return {
82 valid: false,
83 error: `Path does not exist: ${normalizedPath}`,
84 };
85 }
86 throw err;
87 }
88
89 return {
90 valid: true,
91 expandedPath: normalizedPath,
92 };
93}
94
95/**
96 * Check if a path is a git repository

Callers 5

initializeProjectDirectFunction · 0.90
pathUtils.test.tsFile · 0.90
listBranchesMethod · 0.90
gitInitMethod · 0.90
getFileCompletionsMethod · 0.90

Calls 3

expandTildeFunction · 0.70
stripTrailingSlashesFunction · 0.70
statMethod · 0.65

Tested by

no test coverage detected