Copilot commented on code in PR #13669:
URL: https://github.com/apache/gluten/pull/13669#discussion_r4646934676
##########
build/mvn:
##########
@@ -60,51 +110,51 @@ install_mvn() {
echo "Maven ${VERSION} not found locally. Downloading..." >&2
# Create download directory
- mkdir -p "${MVN_DOWNLOAD_DIR}"
+ mkdir -p "${MVN_DOWNLOAD_DIR}" || exit 1
local MVN_TAR="${MVN_DOWNLOAD_DIR}/apache-maven-${VERSION}-bin.tar.gz"
+ local MVN_SHA512="${MVN_TAR}.sha512"
+ local
DISTRIBUTION_PATH="maven/maven-${VERSION%%.*}/${VERSION}/binaries/apache-maven-${VERSION}-bin.tar.gz"
+ local SOURCE DOWNLOAD_URL CHECKSUM_URL VERIFIED=false
+
+ for SOURCE in https://dlcdn.apache.org
https://archive.apache.org/dist; do
+ DOWNLOAD_URL="${SOURCE}/${DISTRIBUTION_PATH}"
+ CHECKSUM_URL="${DOWNLOAD_URL}.sha512"
+ if [ "$SOURCE" = https://dlcdn.apache.org ]; then
+
CHECKSUM_URL="https://downloads.apache.org/${DISTRIBUTION_PATH}.sha512"
+ fi
- if [ ! -f "${MVN_TAR}" ]; then
- # Use Maven Central repository for download
- local
DOWNLOAD_URL="https://repo1.maven.org/maven2/org/apache/maven/apache-maven/${VERSION}/apache-maven-${VERSION}-bin.tar.gz"
-
- echo "Downloading Maven ${VERSION} from Maven Central..." >&2
echo "URL: ${DOWNLOAD_URL}" >&2
-
- if command -v curl > /dev/null 2>&1; then
- curl -f -L --retry 3 --retry-delay 3 \
- --connect-timeout 30 --max-time 600 \
- -o "${MVN_TAR}" "${DOWNLOAD_URL}" || {
- echo "ERROR: Failed to download Maven from
${DOWNLOAD_URL}" >&2
- rm -f "${MVN_TAR}"
- exit 1
- }
- elif command -v wget > /dev/null 2>&1; then
- wget --tries=3 --waitretry=3 \
- --connect-timeout=30 --read-timeout=600 \
- -O "${MVN_TAR}" "${DOWNLOAD_URL}" || {
- echo "ERROR: Failed to download Maven from
${DOWNLOAD_URL}" >&2
- rm -f "${MVN_TAR}"
+ if { [ -f "$MVN_TAR" ] || download_mvn "$DOWNLOAD_URL" "$MVN_TAR";
} &&
+ download_mvn "$CHECKSUM_URL" "$MVN_SHA512"; then
+ if ! verify_mvn "$MVN_TAR" "$MVN_SHA512"; then
+ rm -f "$MVN_TAR" "$MVN_SHA512"
exit 1
- }
- else
- echo "ERROR: Neither curl nor wget found. Please install one
of them or install Maven manually." >&2
- exit 1
+ fi
+ VERIFIED=true
+ break
fi
- echo "Download completed successfully" >&2
+ rm -f "$MVN_TAR" "$MVN_SHA512"
Review Comment:
When `$MVN_TAR` is already cached, a checksum-download failure causes the
script to delete the cached tarball (line 138) and then re-download it from the
fallback source on the next loop iteration. This defeats caching and adds
unnecessary network/CI time. Prefer keeping an existing `$MVN_TAR` while trying
alternate sources for the checksum, and only deleting the tarball if it was
downloaded in the current attempt (e.g., by downloading to a temp file and
moving into place on success).
##########
build/mvn:
##########
@@ -27,6 +27,56 @@ MVN_DOWNLOAD_DIR="${DOWNLOAD_DIR}/.mvn"
# Global variable for Maven binary path
MVN_BIN=""
+download_mvn() {
+ local URL="$1" DESTINATION="$2"
+ if command -v curl > /dev/null 2>&1; then
+ if curl -f -L --retry 3 --retry-delay 3 \
+ --connect-timeout 30 --max-time 600 \
+ -o "$DESTINATION" "$URL"; then
+ return 0
+ fi
+ elif command -v wget > /dev/null 2>&1; then
+ if wget --tries=3 --waitretry=3 \
+ --connect-timeout=30 --read-timeout=600 \
+ -O "$DESTINATION" "$URL"; then
+ return 0
+ fi
+ else
+ echo "ERROR: Neither curl nor wget found. Please install one of them
or install Maven manually." >&2
+ return 1
+ fi
+
+ echo "ERROR: Failed to download Maven from ${URL}" >&2
+ rm -f "$DESTINATION"
+ return 1
+}
+
+verify_mvn() {
+ local ARCHIVE="$1" CHECKSUM_FILE="$2" CHECKSUM
+ local SHA512
+ if command -v sha512sum > /dev/null 2>&1; then
+ SHA512=(sha512sum)
+ elif command -v shasum > /dev/null 2>&1; then
+ SHA512=(shasum -a 512)
+ else
+ echo "ERROR: Neither sha512sum nor shasum found. Install one to verify
the Maven distribution." >&2
+ return 1
+ fi
+
+ # Apache publishes a bare SHA-512 digest, not a checksum-tool manifest.
+ if ! CHECKSUM=$(tr -d '[:space:]' < "$CHECKSUM_FILE") ||
+ ! [[ "$CHECKSUM" =~ ^[0-9a-fA-F]{128}$ ]]; then
Review Comment:
Checksum parsing only accepts a “bare digest” with all whitespace removed.
If Apache ever serves checksum files in the common “<digest><spaces><filename>”
format (or adds leading/trailing text), this will hard-fail downloads. Consider
supporting both formats by extracting the first 128-hex token from the checksum
file (and still rejecting anything malformed), rather than requiring the entire
file content to be exactly 128 hex characters.
##########
build/mvn:
##########
@@ -27,6 +27,56 @@ MVN_DOWNLOAD_DIR="${DOWNLOAD_DIR}/.mvn"
# Global variable for Maven binary path
MVN_BIN=""
+download_mvn() {
+ local URL="$1" DESTINATION="$2"
+ if command -v curl > /dev/null 2>&1; then
+ if curl -f -L --retry 3 --retry-delay 3 \
+ --connect-timeout 30 --max-time 600 \
+ -o "$DESTINATION" "$URL"; then
+ return 0
+ fi
+ elif command -v wget > /dev/null 2>&1; then
+ if wget --tries=3 --waitretry=3 \
+ --connect-timeout=30 --read-timeout=600 \
+ -O "$DESTINATION" "$URL"; then
+ return 0
+ fi
+ else
+ echo "ERROR: Neither curl nor wget found. Please install one of them
or install Maven manually." >&2
+ return 1
+ fi
+
+ echo "ERROR: Failed to download Maven from ${URL}" >&2
+ rm -f "$DESTINATION"
+ return 1
+}
+
+verify_mvn() {
+ local ARCHIVE="$1" CHECKSUM_FILE="$2" CHECKSUM
+ local SHA512
+ if command -v sha512sum > /dev/null 2>&1; then
+ SHA512=(sha512sum)
+ elif command -v shasum > /dev/null 2>&1; then
+ SHA512=(shasum -a 512)
+ else
+ echo "ERROR: Neither sha512sum nor shasum found. Install one to verify
the Maven distribution." >&2
+ return 1
+ fi
+
+ # Apache publishes a bare SHA-512 digest, not a checksum-tool manifest.
+ if ! CHECKSUM=$(tr -d '[:space:]' < "$CHECKSUM_FILE") ||
+ ! [[ "$CHECKSUM" =~ ^[0-9a-fA-F]{128}$ ]]; then
+ echo "ERROR: Invalid SHA-512 checksum in ${CHECKSUM_FILE}" >&2
+ return 1
+ fi
+ # Keep checkout paths out of the line-based checksum manifest.
+ if ! printf '%s %s\n' "$CHECKSUM" "${ARCHIVE##*/}" |
+ (cd "${ARCHIVE%/*}" && "${SHA512[@]}" -c -) >&2; then
Review Comment:
"${ARCHIVE%/*}"` breaks when `ARCHIVE` has no `/` (it expands to the full
filename, causing `cd` to fail). Use a safer directory derivation (e.g.,
`dirname -- "$ARCHIVE"`), or treat the “no slash” case as `.` so verification
works regardless of where the archive path points.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]