From 585dcb469ec42a34d4427d57911dd70fee7a734a Mon Sep 17 00:00:00 2001 From: James Murdza Date: Sun, 15 Sep 2024 10:46:01 -0700 Subject: [PATCH] fix: skip creating a directory in the container when it already exists --- backend/server/src/index.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/backend/server/src/index.ts b/backend/server/src/index.ts index fe0690f..c635fbd 100644 --- a/backend/server/src/index.ts +++ b/backend/server/src/index.ts @@ -176,17 +176,20 @@ io.on("connection", async (socket) => { ); }; + // Copy all files from the project to the container const sandboxFiles = await getSandboxFiles(data.sandboxId); + const containerFiles = containers[data.sandboxId].files; const promises = sandboxFiles.fileData.map(async (file) => { - const filePath = path.join(dirName, file.id); try { - await containers[data.sandboxId].files.makeDir( - path.dirname(filePath) - ); + const filePath = path.join(dirName, file.id); + const parentDirectory = path.dirname(filePath); + if (!containerFiles.exists(parentDirectory)) { + await containerFiles.makeDir(parentDirectory); + } + await containerFiles.write(filePath, file.data); } catch (e: any) { - console.log("Failed to create directory: " + e); + console.log("Failed to create file: " + e); } - await containers[data.sandboxId].files.write(filePath, file.data); }); await Promise.all(promises);