Skip to content

Commit 3a8fad5

Browse files
committed
fix: mkdir parent dir before writing file mount updates
Fixes Dokploy#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.
1 parent 203cddb commit 3a8fad5

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

‎packages/server/src/services/mount.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,28 @@ export const updateFileMount = async (mountId: string) => {
262262
if (!mount || !mount.filePath) return;
263263
const basePath = await getBaseFilesPath(mountId);
264264
const fullPath = path.join(basePath, mount.filePath);
265+
const directory = path.dirname(fullPath);
265266

266267
try {
267268
const serverId = await getServerId(mount);
268269
const encodedContent = encodeBase64(mount.content || "");
269-
const command = `echo "${encodedContent}" | base64 -d > ${quote([fullPath])}`;
270+
const command = `
271+
mkdir -p ${quote([directory])};
272+
if [ -d ${quote([fullPath])} ]; then rm -rf ${quote([fullPath])}; fi;
273+
echo "${encodedContent}" | base64 -d > ${quote([fullPath])};
274+
`;
270275
if (serverId) {
271276
await execAsyncRemote(serverId, command);
272277
} else {
273278
await execAsync(command);
274279
}
275-
} catch {
276-
console.log("Error updating file mount");
280+
} catch (error) {
281+
console.log(`Error updating the file mount: ${error}`);
282+
throw new TRPCError({
283+
code: "BAD_REQUEST",
284+
message: `Error updating the mount ${error instanceof Error ? error.message : error}`,
285+
cause: error,
286+
});
277287
}
278288
};
279289

0 commit comments

Comments
 (0)