Commit 9a8470c9 authored by Yann E. MORIN's avatar Yann E. MORIN Committed by Thomas Petazzoni
Browse files

support/download: convert wget to use the wrapper



This drastically simplifies the wget helper, as it no longer has to deal
with atomically saving the downloaded archive.

Signed-off-by: default avatar"Yann E. MORIN" <yann.morin.1998@free.fr>
Tested-by: default avatarThomas De Schampheleire <thomas.de.schampheleire@gmail.com>
(Tested by running 'make busybox-source')
Signed-off-by: default avatarThomas Petazzoni <thomas.petazzoni@free-electrons.com>
parent a92290aa
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -208,7 +208,9 @@ endef

define DOWNLOAD_WGET
	test -e $(DL_DIR)/$(2) || \
	$(EXTRA_ENV) support/download/wget '$(call qstrip,$(1))' $(DL_DIR)/$(2) && \
	$(EXTRA_ENV) support/download/wrapper wget \
		$(DL_DIR)/$(2) \
		'$(call qstrip,$(1))' && \
	$(call VERIFY_HASH,$(PKGDIR)/$($(PKG)_NAME).hash,$(DL_DIR)/$(2))
endef

+8 −27
Original line number Diff line number Diff line
#!/bin/bash

# We want to catch any command failure, and exit immediately
# We want to catch any unexpected failure, and exit immediately
set -e

# Download helper for wget
# Call it with:
#   $1: URL
#   $2: output file
# Download helper for wget, to be called from the download wrapper script
# Expected arguments:
#   $1: output file
#   $2: URL
# And this environment:
#   WGET     : the wget command to call
#   BUILD_DIR: path to Buildroot's build dir

url="${1}"
output="${2}"
output="${1}"
url="${2}"

tmp_dl="$( mktemp "${BUILD_DIR}/.XXXXXX" )"
tmp_output="$( mktemp "${output}.XXXXXX" )"

# Play tic-tac-toe with temp files
# - first, we download to a trashable location (the build-dir)
# - then we copy to a temporary tarball in the final location, so it is
#   on the same filesystem as the final file
# - finally, we atomically rename to the final file

ret=1
if ${WGET} -O "${tmp_dl}" "${url}"; then
    if mv "${tmp_dl}" "${tmp_output}"; then
        mv "${tmp_output}" "${output}"
        ret=0
    fi
fi

rm -f "${tmp_dl}" "${tmp_output}"
exit ${ret}
${WGET} -O "${output}" "${url}"