fix: skip creating a directory in the container when it already exists

This commit is contained in:
James Murdza 2024-09-15 10:46:01 -07:00
parent 2f88ff6d58
commit 585dcb469e

View File

@ -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 sandboxFiles = await getSandboxFiles(data.sandboxId);
const containerFiles = containers[data.sandboxId].files;
const promises = sandboxFiles.fileData.map(async (file) => { const promises = sandboxFiles.fileData.map(async (file) => {
const filePath = path.join(dirName, file.id);
try { try {
await containers[data.sandboxId].files.makeDir( const filePath = path.join(dirName, file.id);
path.dirname(filePath) const parentDirectory = path.dirname(filePath);
); if (!containerFiles.exists(parentDirectory)) {
await containerFiles.makeDir(parentDirectory);
}
await containerFiles.write(filePath, file.data);
} catch (e: any) { } 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); await Promise.all(promises);