From fc8433ad8bc20282d1e620be1d853efc496fdf0c Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Wed, 21 Jan 2026 16:19:58 +0100 Subject: [PATCH] fix(tools): use codeload directly for tags with special chars (@/) Skip failed github.com attempt entirely for scoped tags like @papra/docker@26.0.0 --- misc/tools.func | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/misc/tools.func b/misc/tools.func index 0696c0d9c..f730fd523 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -1768,26 +1768,30 @@ function fetch_and_deploy_gh_release() { ### Tarball Mode ### if [[ "$mode" == "tarball" || "$mode" == "source" ]]; then - # GitHub API's tarball_url/zipball_url can return HTTP 300 Multiple Choices - # when a branch and tag share the same name. Use explicit refs/tags/ URL instead. - # URL-encode special characters in tag names (@ and /) - local encoded_tag_name="${tag_name//@/%40}" - encoded_tag_name="${encoded_tag_name//\//%2F}" - local direct_tarball_url="https://github.com/$repo/archive/refs/tags/$encoded_tag_name.tar.gz" filename="${app_lc}-${version}.tar.gz" + local download_success=false - # Try primary URL first, fallback to codeload.github.com for complex tag names - if ! curl $download_timeout -fsSL -o "$tmpdir/$filename" "$direct_tarball_url" 2>/dev/null; then - # Remove partial/corrupt file from failed attempt before retry - rm -f "$tmpdir/$filename" - # Fallback: codeload.github.com - only encode @ not / in tag names + # For tags with special characters (@, /), use codeload.github.com directly + # as github.com/archive/refs/tags/ doesn't handle them well + if [[ "$tag_name" =~ [@/] ]]; then + # codeload.github.com - only encode @ not / in tag names local codeload_encoded="${tag_name//@/%40}" local codeload_url="https://codeload.github.com/$repo/tar.gz/refs/tags/$codeload_encoded" - curl $download_timeout -fsSL -o "$tmpdir/$filename" "$codeload_url" || { - msg_error "Download failed: $direct_tarball_url (and fallback $codeload_url)" - rm -rf "$tmpdir" - return 1 - } + if curl $download_timeout -fsSL -o "$tmpdir/$filename" "$codeload_url"; then + download_success=true + fi + else + # Standard tags: use github.com/archive/refs/tags/ + local direct_tarball_url="https://github.com/$repo/archive/refs/tags/${tag_name}.tar.gz" + if curl $download_timeout -fsSL -o "$tmpdir/$filename" "$direct_tarball_url"; then + download_success=true + fi + fi + + if [[ "$download_success" != "true" ]]; then + msg_error "Download failed for $app ($tag_name)" + rm -rf "$tmpdir" + return 1 fi mkdir -p "$target"