From 50ea37515411228f2a9eea96a01bd219457bbb11 Mon Sep 17 00:00:00 2001 From: Derek Higgins Date: Thu, 3 Oct 2013 22:18:08 +0100 Subject: [PATCH] Ignore empty files returned by curl In cases where servers ignore the Modified time, curl cancels the download, outputs a http 200 and leaves the output file untouched, we don't want this empty file. Fixes bug #1234926 Change-Id: I05b0dd95dcd53ca50d88ec07f2f1ee9958b6adb7 --- elements/cache-url/bin/cache-url | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/elements/cache-url/bin/cache-url b/elements/cache-url/bin/cache-url index 09ec48c9..3ac19369 100755 --- a/elements/cache-url/bin/cache-url +++ b/elements/cache-url/bin/cache-url @@ -36,8 +36,16 @@ fi rcode=$(curl -L -o $tmp -w '%{http_code}' $url $time_cond) if [ "$rcode" = "200" ] ; then - echo $success - mv $tmp $dest + # In cases where servers ignore the Modified time, + # curl cancels the download, outputs a 200 and leaves + # the output file untouched, we don't want this empty file. + if [ -n "$time_cond" -a ! -s $tmp ] ; then + echo "Ignoring empty file returned by curl. Using locally cached $url" + rm -f $tmp + else + echo $success + mv $tmp $dest + fi elif [ "$rcode" = "304" ] ; then echo "Server copy has not changed. Using locally cached $url" rm -f $tmp