Skip to content

Commit e187d66

Browse files
mldangeloclaude
andcommitted
fix(update): bypass GitHub raw CDN cache for self-update
The `crab update` command was reporting "Already up to date" even after a new version was merged, because raw.githubusercontent.com serves cached content (max-age=300). Add cache-busting via Cache-Control header and timestamp query param. Also validate the downloaded file contains a version string before replacing the binary. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5496807 commit e187d66

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/crabcode

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9308,10 +9308,17 @@ main() {
93089308
local install_dir=$(dirname "$(realpath "$0")")
93099309
local tmp_file="/tmp/crabcode-update-$$"
93109310

9311-
if curl -fsSL "https://raw.githubusercontent.com/promptfoo/crabcode/main/src/crabcode" -o "$tmp_file" 2>/dev/null; then
9312-
local new_version=$(grep '^VERSION=' "$tmp_file" | cut -d'"' -f2)
9311+
# Cache-bust to bypass GitHub raw CDN cache (max-age=300)
9312+
if curl -fsSL -H 'Cache-Control: no-cache' "https://raw.githubusercontent.com/promptfoo/crabcode/main/src/crabcode?t=$(date +%s)" -o "$tmp_file" 2>/dev/null; then
9313+
local new_version=$(grep '^VERSION=' "$tmp_file" | head -1 | cut -d'"' -f2)
93139314
local current_version="$VERSION"
93149315

9316+
if [ -z "$new_version" ]; then
9317+
error "Downloaded file is invalid (no version found)"
9318+
rm -f "$tmp_file"
9319+
exit 1
9320+
fi
9321+
93159322
if [ "$new_version" = "$current_version" ]; then
93169323
echo -e "${GREEN}Already up to date (v$VERSION)${NC}"
93179324
else

0 commit comments

Comments
 (0)