From b8b2ee6972883a19cbae955ccf37221abd892f59 Mon Sep 17 00:00:00 2001 From: songtianlun Date: Fri, 3 Jan 2025 17:27:59 +0800 Subject: [PATCH] fix: correct jq syntax for updating stats - Adjusted the jq command for adding values to arrays to use the correct syntax for accessing keys. - Updated the jq command for updating numeric values to use the `--argjson` option for proper type handling. These changes ensure that the script correctly updates the statistics file without errors, improving the reliability of the data handling. --- mirror.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mirror.sh b/mirror.sh index a99eeeb..5bba847 100644 --- a/mirror.sh +++ b/mirror.sh @@ -38,12 +38,12 @@ update_stats() { if [ "$type" = "array" ]; then # 添加到数组 - jq --arg key "$key" --arg value "$value" \ - ".details[$key] += [\$value]" "$STATS_FILE" > "$STATS_FILE.tmp" + jq --arg value "$value" \ + ".details.$key += [\$value]" "$STATS_FILE" > "$STATS_FILE.tmp" else # 更新数值 - jq --arg key "$key" --arg value "$value" \ - ".[$key] = ($value | tonumber)" "$STATS_FILE" > "$STATS_FILE.tmp" + jq --arg key "$key" --argjson value "$value" \ + ".$key = \$value" "$STATS_FILE" > "$STATS_FILE.tmp" fi mv "$STATS_FILE.tmp" "$STATS_FILE" }