Skip to content

Commit 777679f

Browse files
committed
build: enhance patch application system for squid versions
Refactor the patch application logic to support hierarchical patch selection based on major, minor, and patch version components. The new system: - Parses full version string into components (major.minor.patch) - Searches patches in version-specific directories (vX/Y/Z) - Implements priority-based patch selection with numeric prefixes - Maintains backward compatibility with existing patch structure - Adds proper error handling and logging for patch application
1 parent 4ebeed4 commit 777679f

1 file changed

Lines changed: 43 additions & 8 deletions

File tree

Dockerfile

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,51 @@ RUN shopt -s extglob && \
3434
COPY patch /src/patch/
3535

3636
RUN SQUID_MAJOR_VERSION="${SQUID_VERSION%%.*}" && \
37-
PATCH_DIR="/src/patch/v${SQUID_MAJOR_VERSION}" && \
38-
if [[ -d "$PATCH_DIR" ]]; then \
39-
echo "Applying patches from $PATCH_DIR" && \
37+
SQUID_REST="${SQUID_VERSION#${SQUID_MAJOR_VERSION}}" && \
38+
SQUID_REST="${SQUID_REST#.}" && \
39+
IFS='.' read -r SQUID_MINOR_VERSION SQUID_PATCH_VERSION _extra <<< "$SQUID_REST" && \
40+
PATCH_BASE_DIR="/src/patch/v${SQUID_MAJOR_VERSION}" && \
41+
if [[ -d "$PATCH_BASE_DIR" ]]; then \
42+
echo "Searching patches under $PATCH_BASE_DIR" && \
4043
shopt -s nullglob && \
41-
for patch_file in "$PATCH_DIR"/*.patch; do \
42-
echo "Applying patch: $(basename "$patch_file")" \
43-
&& patch -p1 --verbose --forward --batch < "$patch_file" || { echo "Failed to apply patch: $(basename "$patch_file")"; exit 1; }; \
44-
done; \
44+
declare -A selected_patches=() && \
45+
collect_patches() { \
46+
local dir="$1"; \
47+
[[ -d "$dir" ]] || return 0; \
48+
for patch_file in "$dir"/*.patch; do \
49+
local base filename priority; \
50+
base="$(basename "$patch_file")"; \
51+
if [[ "$base" =~ ^([0-9]+)[[:space:]_](.+)$ ]]; then \
52+
priority="${BASH_REMATCH[1]}"; \
53+
filename="${BASH_REMATCH[2]}"; \
54+
else \
55+
priority="0"; \
56+
filename="$base"; \
57+
fi; \
58+
if [[ -z "${selected_patches[$filename]}" ]]; then \
59+
selected_patches["$filename"]="${priority}\t${filename}\t${patch_file}"; \
60+
fi; \
61+
done; \
62+
}; \
63+
if [[ -n "$SQUID_MINOR_VERSION" && -n "$SQUID_PATCH_VERSION" ]]; then \
64+
collect_patches "$PATCH_BASE_DIR/$SQUID_MINOR_VERSION/$SQUID_PATCH_VERSION"; \
65+
fi; \
66+
if [[ -n "$SQUID_MINOR_VERSION" ]]; then \
67+
collect_patches "$PATCH_BASE_DIR/$SQUID_MINOR_VERSION"; \
68+
fi; \
69+
collect_patches "$PATCH_BASE_DIR"; \
70+
if [[ ${#selected_patches[@]} -gt 0 ]]; then \
71+
printf "%b\n" "${selected_patches[@]}" \
72+
| sort -rn -k1,1 -k2,2 \
73+
| while IFS=$'\t' read -r priority filename patch_file; do \
74+
echo "Applying patch: $(basename "$patch_file")"; \
75+
patch -p1 --forward --batch < "$patch_file" || { echo "Failed to apply patch: $(basename "$patch_file")"; exit 1; }; \
76+
done; \
77+
else \
78+
echo "No patches found under $PATCH_BASE_DIR. Skipping."; \
79+
fi; \
4580
else \
46-
echo "No version-specific patches found for v${SQUID_MAJOR_VERSION} (missing $PATCH_DIR). Skipping."; \
81+
echo "No version-specific patches found for v${SQUID_MAJOR_VERSION} (missing $PATCH_BASE_DIR). Skipping."; \
4782
fi
4883

4984

0 commit comments

Comments
 (0)