MCPcopy Index your code
hub / github.com/coder/mux / copyLocalFileToRuntime

Function copyLocalFileToRuntime

src/node/services/tools/task_apply_git_patch.ts:60–90  ·  view source on GitHub ↗
(params: {
  runtime: ToolConfiguration["runtime"];
  localPath: string;
  remotePath: string;
  abortSignal?: AbortSignal;
})

Source from the content-addressed store, hash-verified

58}
59
60async function copyLocalFileToRuntime(params: {
61 runtime: ToolConfiguration["runtime"];
62 localPath: string;
63 remotePath: string;
64 abortSignal?: AbortSignal;
65}): Promise<void> {
66 const writable = params.runtime.writeFile(params.remotePath, params.abortSignal);
67 const writer = writable.getWriter();
68
69 const fileHandle = await fsPromises.open(params.localPath, "r");
70 try {
71 const buffer = Buffer.alloc(64 * 1024);
72 while (true) {
73 const { bytesRead } = await fileHandle.read(buffer, 0, buffer.length, null);
74 if (bytesRead <= 0) break;
75 await writer.write(buffer.subarray(0, bytesRead));
76 }
77
78 await writer.close();
79 } catch (error) {
80 try {
81 await writer.abort(error);
82 } catch {
83 // The stream may already be errored; cleanup still proceeds in the caller's finally block.
84 }
85 writer.releaseLock();
86 throw error;
87 } finally {
88 await fileHandle.close();
89 }
90}
91
92function mergeNotes(...notes: Array<string | undefined>): string | undefined {
93 const parts = notes

Callers 1

applyProjectPatchFunction · 0.85

Calls 6

writeFileMethod · 0.65
writeMethod · 0.65
closeMethod · 0.65
abortMethod · 0.65
openMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected