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

Function concatFilesBestEffort

src/node/services/workspaceService.ts:976–1012  ·  view source on GitHub ↗

* Concatenate source files (skipping missing ones) into destPath. * Returns false when no source exists or on write failure.

(params: {
  srcPaths: string[];
  destPath: string;
  logContext: Record<string, unknown>;
})

Source from the content-addressed store, hash-verified

974 * Returns false when no source exists or on write failure.
975 */
976async function concatFilesBestEffort(params: {
977 srcPaths: string[];
978 destPath: string;
979 logContext: Record<string, unknown>;
980}): Promise<boolean> {
981 const chunks: Buffer[] = [];
982 for (const srcPath of params.srcPaths) {
983 try {
984 chunks.push(await fsPromises.readFile(srcPath));
985 } catch (error: unknown) {
986 if (!isErrnoWithCode(error, "ENOENT")) {
987 log.error("Failed to read session artifact file for concatenation", {
988 ...params.logContext,
989 srcPath,
990 error: getErrorMessage(error),
991 });
992 }
993 }
994 }
995
996 if (chunks.length === 0) {
997 return false;
998 }
999
1000 try {
1001 await fsPromises.mkdir(path.dirname(params.destPath), { recursive: true });
1002 await fsPromises.writeFile(params.destPath, Buffer.concat(chunks));
1003 return true;
1004 } catch (error: unknown) {
1005 log.error("Failed to write concatenated session artifact file", {
1006 ...params.logContext,
1007 destPath: params.destPath,
1008 error: getErrorMessage(error),
1009 });
1010 return false;
1011 }
1012}
1013
1014async function copyDirIfMissingBestEffort(params: {
1015 srcDir: string;

Calls 5

isErrnoWithCodeFunction · 0.90
getErrorMessageFunction · 0.90
pushMethod · 0.65
readFileMethod · 0.65
writeFileMethod · 0.65

Tested by

no test coverage detected