From 3a8fad57e6104872b3c63217632dd737f0a09ce3 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Thu, 27 Aug 2026 10:49:15 -0600 Subject: [PATCH] fix: mkdir parent dir before writing file mount updates Fixes #5152. updateFileMount wrote directly to the target path without ensuring its parent directory existed, and silently swallowed errors instead of surfacing them. If the path already existed as a directory (e.g. Docker pre-creating a bind mount target), the write silently failed and left an empty directory instead of the file. --- packages/server/src/services/mount.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/server/src/services/mount.ts b/packages/server/src/services/mount.ts index 26e5fc613..f85e2b2d8 100644 --- a/packages/server/src/services/mount.ts +++ b/packages/server/src/services/mount.ts @@ -262,18 +262,28 @@ export const updateFileMount = async (mountId: string) => { if (!mount || !mount.filePath) return; const basePath = await getBaseFilesPath(mountId); const fullPath = path.join(basePath, mount.filePath); + const directory = path.dirname(fullPath); try { const serverId = await getServerId(mount); const encodedContent = encodeBase64(mount.content || ""); - const command = `echo "${encodedContent}" | base64 -d > ${quote([fullPath])}`; + const command = ` + mkdir -p ${quote([directory])}; + if [ -d ${quote([fullPath])} ]; then rm -rf ${quote([fullPath])}; fi; + echo "${encodedContent}" | base64 -d > ${quote([fullPath])}; + `; if (serverId) { await execAsyncRemote(serverId, command); } else { await execAsync(command); } - } catch { - console.log("Error updating file mount"); + } catch (error) { + console.log(`Error updating the file mount: ${error}`); + throw new TRPCError({ + code: "BAD_REQUEST", + message: `Error updating the mount ${error instanceof Error ? error.message : error}`, + cause: error, + }); } };