Skip to content

Commit

Permalink
Add logic to fall back to the cache on curl failure
Browse files Browse the repository at this point in the history
If a the fetch of the presigned URL fails try to use a cached version.
  • Loading branch information
felddy committed Feb 12, 2025
1 parent 5c37d27 commit 87f09f6
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ END_OF_LINE

if [[ "${presigned_url:-}" ]]; then
log "Downloading Foundry Virtual Tabletop release."
# Temporarily disable errexit for the curl command to capture its exit status
set +e
# Download release if newer than cached version.
# Filter out warnings about bad date formats if the file is missing.
curl ${CONTAINER_VERBOSE+--verbose} --fail --location \
Expand All @@ -165,10 +167,25 @@ END_OF_LINE
--output "${downloading_filename}" "${presigned_url}" 2>&1 \
| tr "\r" "\n" \
| sed --unbuffered '/^Warning: .* date/d'
curl_exit_code=$?
set -e

# Rename the download now that it is completed.
# If we had a cache hit, the file is already renamed.
mv "${downloading_filename}" "${release_filename}" > /dev/null 2>&1 || true
if [ ${curl_exit_code} -ne 0 ]; then
log_warn "Download from presigned URL failed with exit code ${curl_exit_code}."
# Remove any partially downloaded file
[ -f "${downloading_filename}" ] && rm -f "${downloading_filename}"

if [ -f "${release_filename}" ]; then
log "Falling back to existing cached release file: ${release_filename}"
else
log_error "No valid cached release file found. Unable to proceed with installation."
exit 1
fi
else
# Download succeeded so rename the file to the final name.
# If we had a cache hit, the file is already renamed.
mv "${downloading_filename}" "${release_filename}" > /dev/null 2>&1 || true
fi
fi

if [ -f "${release_filename}" ]; then
Expand Down

0 comments on commit 87f09f6

Please sign in to comment.