Skip to content

Commit

Permalink
Only set --no-clobber if curl is 7.83 or newer
Browse files Browse the repository at this point in the history
  • Loading branch information
samueloph committed Jul 8, 2024
1 parent 0ca9a10 commit c914de9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ should be using curl directly if your use case is not covered.
* Encode whitespaces in URLs;
* Download multiple URLs in parallel;
* Follow redirects;
* Automatically choose a filename as output, without overwritting files;
* Automatically choose a filename as output;
* Avoid overwriting files if the installed curl version is 7.83 or higher (--no-clobber);
* Perform retries;
* Set the downloaded file timestamp to the value provided by the server, if available;
* Disable **curl**'s URL globbing parser so **{}** and **\[\]** characters in URLs are not treated specially.
Expand Down
16 changes: 14 additions & 2 deletions wcurl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ URLS=""
readonly PER_URL_PARAMETERS="\
--globoff \
--location \
--no-clobber \
--proto-default https \
--remote-name-all \
--remote-time \
Expand All @@ -114,6 +113,19 @@ sanitize()
exec_curl() {
CMD="curl "

# Store version to check if it supports --no-clobber.
curl_version=$($CMD --version | cut -f2 -d' ' | head -n1)

# --no-clobber is only supported since 7.83.
if [ "$(echo "$curl_version" | cut -f1 -d.)" -ge 8 ]; then
NO_CLOBBER="--no-clobber"
elif [ "$(echo "$curl_version" | cut -f1 -d.)" -eq 7 ] && \
[ "$(echo "$curl_version" | cut -f2 -d.)" -ge 83 ]; then
NO_CLOBBER="--no-clobber"
else
NO_CLOBBER=""
fi

# Detecting whether we need --parallel. It's easier to rely on
# the shell's argument parsing.
# shellcheck disable=SC2086
Expand All @@ -137,7 +149,7 @@ exec_curl() {
NEXT_PARAMETER=""
for url in ${URLS}; do
# shellcheck disable=SC2086
set -- "$@" ${NEXT_PARAMETER} ${PER_URL_PARAMETERS} ${CURL_OPTIONS} "${url}"
set -- "$@" ${NEXT_PARAMETER} ${PER_URL_PARAMETERS} ${NO_CLOBBER} ${CURL_OPTIONS} "${url}"
NEXT_PARAMETER="--next"
done

Expand Down
4 changes: 3 additions & 1 deletion wcurl.1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ By default, \fBwcurl\fR will:
.br
\[bu] Follow redirects;
.br
\[bu] Automatically choose a filename as output, without overwitting files;
\[bu] Automatically choose a filename as output;
.br
\[bu] Avoid overwriting files if the installed curl version is 7.83 or higher (--no-clobber);
.br
\[bu] Perform retries;
.br
Expand Down

0 comments on commit c914de9

Please sign in to comment.