mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-08 13:05:17 +00:00
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.
This commit is contained in:
@@ -125,24 +125,19 @@ export const generateApplyPatchesCommand = async ({
|
|||||||
const basePath = type === "compose" ? COMPOSE_PATH : APPLICATIONS_PATH;
|
const basePath = type === "compose" ? COMPOSE_PATH : APPLICATIONS_PATH;
|
||||||
const codePath = join(basePath, entity.appName, "code");
|
const codePath = join(basePath, entity.appName, "code");
|
||||||
|
|
||||||
const patches = (await findPatchesByEntityId(id, type)).filter(
|
const resultPatches = await findPatchesByEntityId(id, type);
|
||||||
(p) => p.enabled,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (patches.length === 0) {
|
const patches = resultPatches.filter((p) => p.enabled);
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
let command = `echo "Applying ${patches.length} patch(es)...";`;
|
let command = `echo "Applying ${patches.length} patch(es)...";`;
|
||||||
|
|
||||||
for (const p of patches) {
|
for (const p of patches) {
|
||||||
if (!p.enabled) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const filePath = join(codePath, p.filePath);
|
const filePath = join(codePath, p.filePath);
|
||||||
command += `
|
command += `
|
||||||
rm -f ${filePath};
|
file="${filePath}"
|
||||||
echo "${encodeBase64(p.content)}" | base64 -d > ${filePath};
|
dir="$(dirname "$file")"
|
||||||
|
mkdir -p "$dir"
|
||||||
|
echo "${encodeBase64(p.content)}" | base64 -d > "$file"
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user