From 45f817589c3219a513f73fd823131b0c1f5747df Mon Sep 17 00:00:00 2001 From: moilanik Date: Sun, 14 Jun 2026 08:35:43 +0300 Subject: [PATCH] fix(retention): fix branch cache and deduplication bugs - Convert BRANCH_CACHE from string to associative array - Add SEEN_REPORTS deduplication to prevent processing duplicate reports - Initialize BRANCH_COUNTS associative array before use - Fixes main branch reports being incorrectly deleted --- git-pages/files/retention-cleanup.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/git-pages/files/retention-cleanup.sh b/git-pages/files/retention-cleanup.sh index 11b9f27..6f9aece 100644 --- a/git-pages/files/retention-cleanup.sh +++ b/git-pages/files/retention-cleanup.sh @@ -13,7 +13,7 @@ curl_with_host() { [ -f "$CONFIG" ] || { echo "ERROR: config missing: $CONFIG" >&2; exit 1; } -BRANCH_CACHE="" +declare -A BRANCH_CACHE branch_exists() { local owner="$1" repo="$2" branch="$3" key="${owner}/${repo}/${branch}" local status @@ -21,7 +21,7 @@ branch_exists() { [ -z "$GITEA_API_URL" ] && return 0 [ -z "$GITEA_TOKEN" ] && return 0 - if grep -q "^${key}$" <<< "$BRANCH_CACHE" 2>/dev/null; then + if [ "${BRANCH_CACHE[$key]:-}" = "1" ]; then return 0 fi @@ -30,7 +30,7 @@ branch_exists() { "${GITEA_API_URL}/api/v1/repos/${owner}/${repo}/branches/${branch}" 2>/dev/null || echo "000") if [ "$status" = "200" ]; then - BRANCH_CACHE="${BRANCH_CACHE}${key}"$'\n' + BRANCH_CACHE[$key]=1 return 0 fi return 1 @@ -79,9 +79,15 @@ fi echo "" echo "=== Phase 1: collect reports ===" +declare -A SEEN_REPORTS declare -a REPORTS while IFS= read -r meta_path; do report_dir=$(dirname "$meta_path") + + # Skip duplicates - same report dir already processed + [ -z "${SEEN_REPORTS[$report_dir]:-}" ] || continue + SEEN_REPORTS[$report_dir]=1 + parse_path "$report_dir" meta_content=$(curl_with_host "${PAGES_URL}/${meta_path}" 2>/dev/null || true) [ -n "$meta_content" ] || { echo " WARN: could not fetch $meta_path"; continue; } @@ -121,6 +127,7 @@ done echo "" echo "=== Phase 3: apply retention rules to remaining reports ===" +declare -A BRANCH_COUNTS if [ "${#KEEP[@]}" -gt 0 ]; then IFS=$'\n' for entry in $(printf '%s\n' "${KEEP[@]}" | sort -t'|' -k4,4 -k5,5rn); do