Skip to content

beesh: Abort if download fails #58

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions src/beesh.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -274,27 +274,22 @@ function fetch_one_file() {
nocheck=""
fi

if [ ! -s "${F}/${file}" ] ; then
rm -vf "${F}/${file}"
fi

trap "rm -f ${F}/${file}" EXIT

print_info "fetching $url"
wget \
--output-document="${F}/${file}" \
--no-clobber \
--timeout=60 \
--tries=1 \
"${url}" || true

trap - EXIT

ls -ld "${F}/${file}"

if [ ! -s "${F}/${file}" ] ; then
print_error "ERROR: ${F}/${file} is empty, download failed."
exit 1
if [ -s "${F}/${file}" ]; then
print_info "File ‘${F}/${file}‘ already there; not retrieving."
else
print_info "fetching $url"
wget \
--output-document="${F}/${file}.tmp" \
--timeout=60 \
--tries=1 \
"${url}"
ls -ld "${F}/${file}.tmp"
if [ ! -s "${F}/${file}.tmp" ] ; then
print_error "ERROR: ${F}/${file}.tmp is empty, download failed."
rm "${F}/${file}.tmp"
exit 1
fi
mv "${F}/${file}.tmp" "${F}/${file}"
fi
fi

Expand Down