From 8b1cef69443e0eca8a2ab000309f6e690bef9408 Mon Sep 17 00:00:00 2001 From: Kirill Kodanev Date: Mon, 15 Sep 2025 20:54:04 +0300 Subject: [PATCH] Fix race in tmpfile --- scripts/generate-configs.sh | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/scripts/generate-configs.sh b/scripts/generate-configs.sh index 47a2d9a..e82cfad 100644 --- a/scripts/generate-configs.sh +++ b/scripts/generate-configs.sh @@ -84,25 +84,28 @@ query_api() { dbg " -> API attempt #$attempt for $domain" tmpfile=$(mktemp) - TEMP_FILES+=("$tmpfile") - http_code=$(curl -sS --compressed \ - -m 10 --connect-timeout 5 \ - --retry 2 --retry-connrefused \ - -H 'Accept: application/json' \ - -w '%{http_code}' \ - -o "$tmpfile" \ - "${API_URL}${domain}" 2>>"$DEBUG_LOG" || true) + curl -sS --compressed \ + -m 10 --connect-timeout 5 \ + --retry 2 --retry-connrefused \ + -H 'Accept: application/json' \ + -w '%{http_code}' \ + -o "$tmpfile" \ + "${API_URL}${domain}" 2>>"$DEBUG_LOG" || true + http_code=$(tail -n1 "$tmpfile") body=$(cat "$tmpfile") preview="$(printf '%s' "$body" | tr '\n' ' ' | cut -c1-400)" dbg " -> HTTP=$http_code, preview=${preview}" if [ "$http_code" = "200" ] && jq -e . "$tmpfile" >/dev/null 2>&1; then - echo "$tmpfile" # возвращаем путь к tmp json файлу + cat "$tmpfile" # вернём тело JSON напрямую + rm -f "$tmpfile" return 0 fi + rm -f "$tmpfile" + if [ "$attempt" -ge "$max_attempts" ]; then ERRORS["$domain"]="http_${http_code}_or_invalid_json" dbg " -> Failed after $attempt attempts, preview=${preview}" @@ -116,6 +119,7 @@ query_api() { done } + if [ ! -f "$INPUT_FILE" ]; then err "Input file not found: $INPUT_FILE" exit 3