git: 07702720e313 - main - Mk/fetch: stop passing `?dummy=/distname` in URLs

From: Mathieu Arnold <mat_at_FreeBSD.org>
Date: Wed, 07 Oct 2026 09:06:16 UTC
The branch main has been updated by mat:

URL: https://cgit.FreeBSD.org/ports/commit/?id=07702720e3134b1eacb5e237f5f2fa7ce7071365

commit 07702720e3134b1eacb5e237f5f2fa7ce7071365
Author:     Mathieu Arnold <mat@FreeBSD.org>
AuthorDate: 2026-09-14 13:23:09 +0000
Commit:     Mathieu Arnold <mat@FreeBSD.org>
CommitDate: 2026-10-07 08:59:19 +0000

    Mk/fetch: stop passing `?dummy=/distname` in URLs
    
    This helps upstream cdns with caching as they don't have to also cache
    the dummy url with the useless query string.
    
    Right now, fetch will be run as
    
    /usr/bin/fetch -Fpr  -S 9153588 https://codeload.github.com/stevedekorte/io/tar.gz/2017.09.06?dummy=/stevedekorte-io-2017.09.06_GH0.tar.gz
    
    The ?dummy=/stevedekorte-io-2017.09.06_GH0.tar.gz tricks fetch into
    saving the file as stevedekorte-io-2017.09.06_GH0.tar.gz.
    So this is changed to this, no more tricks:
    
    /usr/bin/fetch -Fpr  -S 9153588 -o stevedekorte-io-2017.09.06_GH0.tar.gz https://codeload.github.com/stevedekorte/io/tar.gz/2017.09.06
    
    For Rust crates, the ?dummy=/ part was not even used as we were already
    passing -o to the fetch command:
    
    /usr/bin/fetch -Fpr  -S 20907 -o rust/crates/zeroize-1.8.2.crate https://static.crates.io/crates/zeroize/zeroize-1.8.2.crate?dummy=/rust/crates/zeroize-1.8.2.crate
    
    it now runs:
    
    /usr/bin/fetch -Fpr  -S 20907 -o rust/crates/zeroize-1.8.2.crate https://static.crates.io/crates/zeroize/zeroize-1.8.2.crate
    
    PR:     298395
    Differential Revision:  https://reviews.freebsd.org/D59663
---
 Mk/Scripts/do-fetch.sh | 43 +++++++++++++++++++++++++++++++++----------
 1 file changed, 33 insertions(+), 10 deletions(-)

diff --git a/Mk/Scripts/do-fetch.sh b/Mk/Scripts/do-fetch.sh
index cb564a4b1303..b60f9906f97a 100644
--- a/Mk/Scripts/do-fetch.sh
+++ b/Mk/Scripts/do-fetch.sh
@@ -126,26 +126,52 @@ while IFS= read -r _file; do
 		sites_remaining=$((sites_remaining + 1))
 	done
 	for site in ${sites}; do
+		# This target only echoes the full URL, handle it first to simplify the rest
+		# of the loop.
+		if [ "${dp_TARGET}" = fetch-url-list-int ]; then
+			echo "${site}${file}"
+			continue
+		fi
+
 		sites_remaining=$((sites_remaining - 1))
 		CKSIZE=$(distinfo_data SIZE "${full_file}")
-		early_args=""
 		case ${file} in
 			*/*)
 				case ${dp_TARGET} in
 					fetch-list)
 						echo "mkdir -p \"${file%/*}\" && "
-						early_args="-o ${file}"
-						;;
-					fetch-url-list-int)
 						;;
 					*)
 						mkdir -p "${file%/*}"
-						early_args="-o ${file}"
 						;;
 				esac
 			;;
 		esac
-		args="${early_args:+${early_args} }${site}${file}"
+
+		# When the distname is not the last part of the final url, we append a
+		# `?dummy=/` so that the url ends up looking something like this:
+		# http://foo.bar/baz/1.0?dummy=/baz-1.0.tar.gz
+		#
+		# This tricks fetch into save the file which path really is "baz/1.0" as
+		# "baz-1.0.tar.gz" which is what the framework wants.  This is only "used"
+		# for the fetch-url-list-int which is used by `make fetch-url-list` which
+		# generates a long list of urls.
+		#
+		# When we are actually fetching, we always set `-o $file`, so we can remove
+		# the `?dummy=/`, and we don't need to append the distname.
+		case "${site}" in
+			*\?dummy=/)
+				url="${site%?dummy=/}"
+			;;
+			*\&dummy=/)
+				url="${site%&dummy=/}"
+			;;
+			*)
+				url="${site}${file}"
+			;;
+		esac
+		args="-o ${file} $url"
+
 		_fetch_cmd="${dp_FETCH_CMD} ${dp_FETCH_BEFORE_ARGS}"
 		if [ -z "${dp_DISABLE_SIZE}" -a -n "${CKSIZE}" ]; then
 			_fetch_cmd="${_fetch_cmd} -S ${CKSIZE}"
@@ -153,7 +179,7 @@ while IFS= read -r _file; do
 		_fetch_cmd="${_fetch_cmd} ${args} ${dp_FETCH_AFTER_ARGS}"
 		case ${dp_TARGET} in
 			do-fetch|makesum)
-				${dp_ECHO_MSG} "=> Attempting to fetch ${site}${file}"
+				${dp_ECHO_MSG} "=> Attempting to fetch ${url}"
 				if env -S "${dp_FETCH_ENV}" ${_fetch_cmd}; then
 					actual_size=$(stat -f %z "${file}")
 					if [ -n "${dp_DISABLE_SIZE}" ] || [ -z "${CKSIZE}" ] || [ "${actual_size}" -eq "${CKSIZE}" ]; then
@@ -170,9 +196,6 @@ while IFS= read -r _file; do
 			fetch-list)
 				echo -n "env $(escape "${_fetch_cmd}") || "
 				;;
-			fetch-url-list-int)
-				echo ${args}
-				;;
 		esac
 	done
 	case ${dp_TARGET} in