Skip to content
Snippets Groups Projects
Unverified Commit d01ed085 authored by Julian Ospald's avatar Julian Ospald :tea:
Browse files

Use trap to clean up interrupted download in cache

Fixes #73
parent 21ba3f37
No related branches found
No related tags found
No related merge requests found
...@@ -869,6 +869,37 @@ download() { ...@@ -869,6 +869,37 @@ download() {
edo ${DOWNLOADER} ${DOWNLOADER_OPTS} "$1" edo ${DOWNLOADER} ${DOWNLOADER_OPTS} "$1"
} }
# @FUNCTION: download_to_cache
# @USAGE: <url>
# @DESCRIPTION:
# Downloads the given url as a file into the cache directory
# and makes sure the file is deleted on failed/interrupted download.
download_to_cache() {
[ -z "$1" ] && die "Internal error: no argument given to download_to_cache"
_dtc_download_url="$1"
_dtc_download_tarball_name=$(basename "${_dtc_download_url}")
rm_tarball() {
if [ -e "${CACHE_LOCATION}/${_dtc_download_tarball_name}" ] ; then
rm "${CACHE_LOCATION}/${_dtc_download_tarball_name}"
fi
}
(
trap 'rm_tarball' 2
edo cd "${CACHE_LOCATION}"
# shellcheck disable=SC2086
edo ${DOWNLOADER} ${DOWNLOADER_OPTS} "${_dtc_download_url}"
trap - 2
) || {
rm_tarball
die "Failed to download"
}
unset _dtc_download_tarball_name _dtc_download_url
}
# @FUNCTION: download_silent # @FUNCTION: download_silent
# @USAGE: <url> # @USAGE: <url>
# @DESCRIPTION: # @DESCRIPTION:
...@@ -1193,8 +1224,7 @@ install_ghc() { ...@@ -1193,8 +1224,7 @@ install_ghc() {
( (
if ${CACHING} ; then if ${CACHING} ; then
if [ ! -e "${CACHE_LOCATION}/${download_tarball_name}" ] ; then if [ ! -e "${CACHE_LOCATION}/${download_tarball_name}" ] ; then
edo cd "${CACHE_LOCATION}" download_to_cache "${download_url}"
download "${download_url}"
fi fi
edo cd "${tmp_dir}" edo cd "${tmp_dir}"
unpack "${CACHE_LOCATION}/${download_tarball_name}" unpack "${CACHE_LOCATION}/${download_tarball_name}"
...@@ -1468,8 +1498,7 @@ install_cabal() { ...@@ -1468,8 +1498,7 @@ install_cabal() {
( (
if ${CACHING} ; then if ${CACHING} ; then
if [ ! -e "${CACHE_LOCATION}/${download_tarball_name}" ] ; then if [ ! -e "${CACHE_LOCATION}/${download_tarball_name}" ] ; then
edo cd "${CACHE_LOCATION}" download_to_cache "${download_url}"
download "${download_url}"
fi fi
edo cd "${tmp_dir}" edo cd "${tmp_dir}"
unpack "${CACHE_LOCATION}/${download_tarball_name}" unpack "${CACHE_LOCATION}/${download_tarball_name}"
...@@ -1536,8 +1565,7 @@ compile_ghc() { ...@@ -1536,8 +1565,7 @@ compile_ghc() {
( (
if ${CACHING} ; then if ${CACHING} ; then
if [ ! -e "${CACHE_LOCATION}/${download_tarball_name}" ] ; then if [ ! -e "${CACHE_LOCATION}/${download_tarball_name}" ] ; then
edo cd "${CACHE_LOCATION}" download_to_cache "${download_url}"
download "${download_url}"
fi fi
edo cd "${tmp_dir}" edo cd "${tmp_dir}"
unpack "${CACHE_LOCATION}/${download_tarball_name}" unpack "${CACHE_LOCATION}/${download_tarball_name}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment