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

Function ensureDir

src/node/runtime/RemoteRuntime.ts:473–495  ·  view source on GitHub ↗

* Ensure a directory exists (mkdir -p semantics).

(dirPath: string, abortSignal?: AbortSignal)

Source from the content-addressed store, hash-verified

471 * Ensure a directory exists (mkdir -p semantics).
472 */
473 async ensureDir(dirPath: string, abortSignal?: AbortSignal): Promise<void> {
474 const stream = await this.exec(`mkdir -p ${this.quoteForRemote(dirPath)}`, {
475 cwd: "/",
476 timeout: 10,
477 abortSignal,
478 });
479
480 await stream.stdin.close();
481
482 const [stdout, stderr, exitCode] = await Promise.all([
483 streamToString(stream.stdout),
484 streamToString(stream.stderr),
485 stream.exitCode,
486 ]);
487
488 if (exitCode !== 0) {
489 const extra = stderr.trim() || stdout.trim();
490 throw new RuntimeError(
491 `Failed to create directory ${dirPath}: exit code ${exitCode}${extra ? `: ${extra}` : ""}`,
492 "file_io"
493 );
494 }
495 }
496
497 /**
498 * Get file statistics via exec.

Callers

nothing calls this directly

Calls 4

streamToStringFunction · 0.90
execMethod · 0.65
closeMethod · 0.65
quoteForRemoteMethod · 0.45

Tested by

no test coverage detected