improve error handling for downloads

This commit is contained in:
Björn Busse 2016-07-30 02:08:59 +02:00 committed by Björn Busse
parent 5ac7e3fd98
commit d718987f48

View File

@ -126,7 +126,13 @@ xkcd_get_all_images() {
awk '/Permanent link to this comic: / {print $6}' | \ awk '/Permanent link to this comic: / {print $6}' | \
awk 'BEGIN{FS="/";} {print $4}') awk 'BEGIN{FS="/";} {print $4}')
if [[ -z "$nimg_latest" ]]; then
VERBOSE=1
error "Failed to find latest image number, not downloading anything"
exit 1
else
log "Found: $nimg_latest" log "Found: $nimg_latest"
fi
for ((i=1; i<=$nimg_latest; i++)); do for ((i=1; i<=$nimg_latest; i++)); do
local img_url_hotlink=$(xkcd_get_hotlink_url $i) local img_url_hotlink=$(xkcd_get_hotlink_url $i)
@ -138,8 +144,10 @@ xkcd_get_all_images() {
fi fi
log "Downloading ${i} ${img_url_hotlink} (${img_name})" log "Downloading ${i} ${img_url_hotlink} (${img_name})"
local r=$(curl -sO $img_url_hotlink) $(curl -sO $img_url_hotlink)
log "Success: $r" if (( 0 != "$?" )); then
error "Failed to download ${i}"
fi
done done
echo 0 echo 0