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
This commit is contained in:
Derek Higgins 2013-10-03 22:18:08 +01:00
parent 4cae314d18
commit 50ea375154

View File

@ -36,8 +36,16 @@ fi
rcode=$(curl -L -o $tmp -w '%{http_code}' $url $time_cond) rcode=$(curl -L -o $tmp -w '%{http_code}' $url $time_cond)
if [ "$rcode" = "200" ] ; then if [ "$rcode" = "200" ] ; then
echo $success # In cases where servers ignore the Modified time,
mv $tmp $dest # 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 elif [ "$rcode" = "304" ] ; then
echo "Server copy has not changed. Using locally cached $url" echo "Server copy has not changed. Using locally cached $url"
rm -f $tmp rm -f $tmp