Skip to content

Conversation

@sergiodj
Copy link
Collaborator

Thanks to @polkorny for identifying a bug in our curl version
comparison algorithm!

Previously, we'd have problems when curl bumps to version 9.0+ because
our logic would wrongly try to match the minor version to "-ge 16",
which wouldn't work until curl 9.16 is released.

Polkorny gave the idea to compose the major and minor versions into
one single number without the dot, which allows us to perform quick
numerical comparisons.

Signed-off-by: Sergio Durigan Junior [email protected]
Reported-by: Matheus Polkorny [email protected]
Co-Authored-by: Matheus Polkorny [email protected]

@sergiodj sergiodj force-pushed the fix-version-comparison-curl branch from 3cc470a to 6b1e9d5 Compare November 14, 2025 04:04
Thanks to @polkorny for identifying a bug in our curl version
comparison algorithm!

Previously, we'd have problems when curl bumps to version 9.0+ because
our logic would wrongly try to match the minor version to "-ge 16",
which wouldn't work until curl 9.16 is released.

Fix by making stricter comparisons against major and minor curl
versions.

Signed-off-by: Sergio Durigan Junior <[email protected]>
Reported-by: Matheus Polkorny <[email protected]>
Co-Authored-by: Matheus Polkorny <[email protected]>
@sergiodj sergiodj force-pushed the fix-version-comparison-curl branch from 6b1e9d5 to d797a5c Compare November 14, 2025 04:05
@sergiodj sergiodj requested a review from samueloph November 14, 2025 04:26
@sergiodj
Copy link
Collaborator Author

Cc @polkorny

@vszakats
Copy link
Member

Here's a proposal that creates a '0123` (major-major-minor-minor) internally
zero-padded version number, resulting in shorter, easier to extend and IMO
easier to grok code. It also fixes handling <7 version inputs:

--- a/wcurl
+++ b/wcurl
@@ -205,28 +205,22 @@ exec_curl()
 
     # Store version to check if it supports --no-clobber, --parallel and --parallel-max-host.
     curl_version=$($CMD --version | cut -f2 -d' ' | head -n1)
-    curl_version_major=$(echo "$curl_version" | cut -f1 -d.)
-    curl_version_minor=$(echo "$curl_version" | cut -f2 -d.)
+    curl_version=$(printf '%02d%02d' "$(echo "$curl_version" | cut -f1 -d.)" "$(echo "$curl_version" | cut -f2 -d.)")
 
     CURL_NO_CLOBBER=""
     CURL_PARALLEL=""
-    # --no-clobber is only supported since 7.83.0.
-    # --parallel is only supported since 7.66.0.
-    # --parallel-max-host is only supported since 8.16.0.
-    if [ "${curl_version_major}" -ge 8 ]; then
-        CURL_NO_CLOBBER="--no-clobber"
+    if [ "${curl_version}" -ge 0766 ]; then
+        # --parallel is only supported since 7.66.0.
         CURL_PARALLEL="--parallel"
-        if [ "${curl_version_minor}" -ge 16 ]; then
-            CURL_PARALLEL="--parallel --parallel-max-host 5"
-        fi
-    elif [ "${curl_version_major}" -eq 7 ]; then
-        if [ "${curl_version_minor}" -ge 83 ]; then
-            CURL_NO_CLOBBER="--no-clobber"
-        fi
-        if [ "${curl_version_minor}" -ge 66 ]; then
-            CURL_PARALLEL="--parallel"
+        if [ "${curl_version}" -ge 0816 ]; then
+            # --parallel-max-host is only supported since 8.16.0.
+            CURL_PARALLEL="${CURL_PARALLEL} --parallel-max-host 5"
         fi
     fi
+    if [ "${curl_version}" -ge 0783 ]; then
+        # --no-clobber is only supported since 7.83.0.
+        CURL_NO_CLOBBER="--no-clobber"
+    fi
 
     # Detecting whether we need --parallel. It's easier to rely on
     # the shell's argument parsing.

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants