fix: set project file permissions so that they belong to the terminal user

This commit is contained in:
James Murdza 2024-06-15 21:00:43 -04:00
parent e7dd3238df
commit cfed8a225e

View File

@ -138,12 +138,20 @@ io.on("connection", async (socket) => {
}
});
// Change the owner of the project directory to user
const fixPermissions = async () => {
await containers[data.sandboxId].process.startAndWait(
`sudo chown -R user "${path.join(dirName, "projects", data.sandboxId)}"`
);
}
const sandboxFiles = await getSandboxFiles(data.sandboxId);
sandboxFiles.fileData.forEach(async (file) => {
const filePath = path.join(dirName, file.id);
await containers[data.sandboxId].filesystem.makeDir(path.dirname(filePath));
await containers[data.sandboxId].filesystem.write(filePath, file.data);
});
fixPermissions();
socket.emit("loaded", sandboxFiles.files);
@ -177,6 +185,7 @@ io.on("connection", async (socket) => {
file.data = body;
await containers[data.sandboxId].filesystem.write(path.join(dirName, file.id), body);
fixPermissions();
await saveFile(fileId, body);
} catch (e) {
io.emit("rateLimit", "Rate limited: file saving. Please slow down.");
@ -195,6 +204,7 @@ io.on("connection", async (socket) => {
path.join(dirName, fileId),
path.join(dirName, newFileId)
)
fixPermissions();
file.id = newFileId;
@ -221,6 +231,7 @@ io.on("connection", async (socket) => {
const id = `projects/${data.sandboxId}/${name}`;
await containers[data.sandboxId].filesystem.write(path.join(dirName, id), "");
fixPermissions();
sandboxFiles.files.push({
id,
@ -273,6 +284,7 @@ io.on("connection", async (socket) => {
path.join(dirName, fileId),
path.join(dirName, newFileId)
)
fixPermissions();
await renameFile(fileId, newFileId, file.data);
} catch (e) {
io.emit("rateLimit", "Rate limited: file renaming. Please slow down.");