From 2db4c448d4938dc9dd4a0c30bba142bc6d9fb463 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Tue, 17 Feb 2026 02:05:54 -0600 Subject: [PATCH] refactor(patch): optimize patch application command generation - Streamlined the command generation for applying patches by removing unnecessary checks for enabled status within the loop. - Consolidated patch retrieval and filtering logic to enhance clarity and maintainability. - Improved directory handling for file paths to ensure proper creation before applying patches, enhancing robustness. --- packages/server/src/services/patch.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/server/src/services/patch.ts b/packages/server/src/services/patch.ts index f14a6b082..fd6b29a2d 100644 --- a/packages/server/src/services/patch.ts +++ b/packages/server/src/services/patch.ts @@ -125,24 +125,19 @@ export const generateApplyPatchesCommand = async ({ const basePath = type === "compose" ? COMPOSE_PATH : APPLICATIONS_PATH; const codePath = join(basePath, entity.appName, "code"); - const patches = (await findPatchesByEntityId(id, type)).filter( - (p) => p.enabled, - ); + const resultPatches = await findPatchesByEntityId(id, type); - if (patches.length === 0) { - return ""; - } + const patches = resultPatches.filter((p) => p.enabled); let command = `echo "Applying ${patches.length} patch(es)...";`; for (const p of patches) { - if (!p.enabled) { - continue; - } const filePath = join(codePath, p.filePath); command += ` -rm -f ${filePath}; -echo "${encodeBase64(p.content)}" | base64 -d > ${filePath}; +file="${filePath}" +dir="$(dirname "$file")" +mkdir -p "$dir" +echo "${encodeBase64(p.content)}" | base64 -d > "$file" `; }