From bad433fa926ade2f8a0dd8f9a841d9e8101c99f7 Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Wed, 5 Feb 2020 10:16:25 +0100 Subject: [PATCH] Fix cache-url -f When there is a hashsum mismatch diskimage-builder forces downloads with the -f switch of cache-url. This is currently broken because bash escapes the quotes in curl_opts. This tricks curl trying to download 'no-cache' instead of the url. This can be fixed by using an array for curl_opts which does the correct thing here. Change-Id: Id9f1579dda9a3e0a2b08dd5faaeef0e2e580d419 --- diskimage_builder/elements/cache-url/bin/cache-url | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/diskimage_builder/elements/cache-url/bin/cache-url b/diskimage_builder/elements/cache-url/bin/cache-url index cd260d48..dee05d6e 100755 --- a/diskimage_builder/elements/cache-url/bin/cache-url +++ b/diskimage_builder/elements/cache-url/bin/cache-url @@ -61,7 +61,7 @@ done url=$1 dest=$2 time_cond= -curl_opts="--retry 3 --retry-delay 30 " +curl_opts=(--retry 3 --retry-delay 30) if [ -z $url -o -z $dest ] ; then show_options 1 @@ -77,7 +77,7 @@ else fi if [ "$FORCE_REVALIDATE" = "1" ]; then - curl_opts+="-H 'Pragma: no-cache, must-revalidate' -H 'Cache-Control: no-cache, must-revalidate'" + curl_opts+=(-H "Pragma: no-cache, must-revalidate" -H "Cache-Control: no-cache, must-revalidate") success="Downloaded and cached $url, having forced upstream caches to revalidate" elif [ -f $dest -a -s $dest ] ; then time_cond="-z $dest" @@ -86,7 +86,7 @@ else success="Downloaded and cached $url for the first time" fi -rcode=$(curl -v -L -o $tmp -w '%{http_code}' --connect-timeout 10 $curl_opts $url $time_cond) +rcode=$(curl -v -L -o $tmp -w '%{http_code}' --connect-timeout 10 "${curl_opts[@]}" $url $time_cond) if [ "$rcode" == "200" -o "${url:0:7}" == "file://" ] ; then # In cases where servers ignore the Modified time, # curl cancels the download, outputs a 200 and leaves