From efb1f435d4242b6574a63b07656e9a56bb952de7 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Mon, 17 Jun 2013 13:28:13 +0100 Subject: [PATCH] Improve first time download of ubuntu images. If a cached copy of the file doesn't exist, cache_url() passes a non-existent path to -z/--time-cond and you see this warning: Warning: Illegal date format for -z, --timecond (and not a file name). Warning: Disabling time condition. See curl_getdate(3) for valid date syntax. It works just fine, but the warning is ugly. Change-Id: Ic6f13a2c596b988308d7fca9cd1745e5d48ae5fb --- elements/ubuntu/root.d/10-cache-ubuntu-tarball | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/elements/ubuntu/root.d/10-cache-ubuntu-tarball b/elements/ubuntu/root.d/10-cache-ubuntu-tarball index 65d569b5..e062163e 100755 --- a/elements/ubuntu/root.d/10-cache-ubuntu-tarball +++ b/elements/ubuntu/root.d/10-cache-ubuntu-tarball @@ -18,10 +18,20 @@ cache_url() { local url=$1 local dest=$2 + + mkdir -p $(dirname $dest) local tmp=$(mktemp $(dirname $dest)/.download.XXXXXXXX) - rcode=$(curl -o $tmp -z $dest -w '%{http_code}' $url) + + if [ -f $dest ] ; then + time_cond="-z $dest" + success="Server copy has changed. Using server version of $url" + else + success="Downloaded and cached $url for the first time" + fi + + rcode=$(curl -o $tmp -w '%{http_code}' $url $time_cond) if [ "$rcode" == "200" ] ; then - echo "Server copy has changed. Using server version of $url" + echo $success mv $tmp $dest elif [ "$rcode" == "304" ] ; then echo "Server copy has not changed. Using locally cached $url"