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

Function defaultIsPathAccessible

src/node/utils/main/resolveLocalPtyShell.ts:43–74  ·  view source on GitHub ↗

* Check whether a path-like shell candidate is a real executable file. * - Must be a regular file (rejects directories, symlink-to-dir, etc.) * - On POSIX: must have execute permission for the current user. * - On Windows: must have a recognized executable extension (PATHEXT-aware).

(shellPath: string)

Source from the content-addressed store, hash-verified

41 * - On Windows: must have a recognized executable extension (PATHEXT-aware).
42 */
43function defaultIsPathAccessible(shellPath: string): boolean {
44 try {
45 const stat = statSync(shellPath);
46 if (!stat.isFile()) {
47 return false;
48 }
49
50 if (process.platform !== "win32") {
51 // X_OK checks execute permission for the current user.
52 accessSync(shellPath, constants.X_OK);
53 return true;
54 }
55
56 // On Windows, executable status is determined by file extension.
57 const ext = path.win32.extname(shellPath).toLowerCase();
58 if (!ext) {
59 return false;
60 }
61
62 const pathExtEnv = process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD";
63 const allowedExts = new Set(
64 pathExtEnv
65 .split(";")
66 .map((candidateExt) => candidateExt.toLowerCase().trim())
67 .filter(Boolean)
68 );
69
70 return allowedExts.has(ext);
71 } catch {
72 return false;
73 }
74}
75
76function isPathLikeShell(command: string): boolean {
77 return command.includes("/") || command.includes("\\");

Callers

nothing calls this directly

Calls 1

hasMethod · 0.45

Tested by

no test coverage detected