Commit 1bcd249f by Mislav Marohnić

Avoid re-downloading if there's a valid tarball in build location

If there already exists a valid tarball in the build location, e.g. as
artefact of a previous install using `--keep`, don't re-download the
file, as there is no need.

References #487
parent a3009b46
...@@ -261,7 +261,7 @@ fetch_tarball() { ...@@ -261,7 +261,7 @@ fetch_tarball() {
tar_args="${tar_args/z/j}" tar_args="${tar_args/z/j}"
fi fi
if ! symlink_tarball_from_cache "$package_filename" "$checksum"; then if ! reuse_existing_tarball "$package_filename" "$checksum"; then
echo "Downloading ${package_filename}..." >&2 echo "Downloading ${package_filename}..." >&2
http head "$mirror_url" && http head "$mirror_url" &&
download_tarball "$mirror_url" "$package_filename" "$checksum" || download_tarball "$mirror_url" "$package_filename" "$checksum" ||
...@@ -278,13 +278,19 @@ fetch_tarball() { ...@@ -278,13 +278,19 @@ fetch_tarball() {
} >&4 2>&1 } >&4 2>&1
} }
symlink_tarball_from_cache() { reuse_existing_tarball() {
[ -n "$RUBY_BUILD_CACHE_PATH" ] || return 1
local package_filename="$1" local package_filename="$1"
local cached_package_filename="${RUBY_BUILD_CACHE_PATH}/$package_filename"
local checksum="$2" local checksum="$2"
# Reuse existing file in build location
if [ -e "$package_filename" ] && verify_checksum "$package_filename" "$checksum"; then
return 0
fi
# Reuse previously downloaded file in cache location
[ -n "$RUBY_BUILD_CACHE_PATH" ] || return 1
local cached_package_filename="${RUBY_BUILD_CACHE_PATH}/$package_filename"
[ -e "$cached_package_filename" ] || return 1 [ -e "$cached_package_filename" ] || return 1
verify_checksum "$cached_package_filename" "$checksum" >&4 2>&1 || return 1 verify_checksum "$cached_package_filename" "$checksum" >&4 2>&1 || return 1
ln -s "$cached_package_filename" "$package_filename" >&4 2>&1 || return 1 ln -s "$cached_package_filename" "$package_filename" >&4 2>&1 || return 1
......
...@@ -68,3 +68,46 @@ export RUBY_BUILD_CACHE_PATH= ...@@ -68,3 +68,46 @@ export RUBY_BUILD_CACHE_PATH=
unstub curl unstub curl
unstub md5 unstub md5
} }
@test "existing tarball in build location is reused" {
stub md5 true "echo 83e6d7725e20166024a1eb74cde80677"
stub curl false
stub wget false
export -n RUBY_BUILD_CACHE_PATH
export RUBY_BUILD_BUILD_PATH="${TMP}/build"
mkdir -p "$RUBY_BUILD_BUILD_PATH"
ln -s "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_BUILD_PATH"
run_inline_definition <<DEF
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#83e6d7725e20166024a1eb74cde80677" copy
DEF
assert_success
[ -x "${INSTALL_ROOT}/bin/package" ]
unstub md5
}
@test "existing tarball in build location is discarded if not matching checksum" {
stub md5 true \
"echo invalid" \
"echo 83e6d7725e20166024a1eb74cde80677"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
export -n RUBY_BUILD_CACHE_PATH
export RUBY_BUILD_BUILD_PATH="${TMP}/build"
mkdir -p "$RUBY_BUILD_BUILD_PATH"
touch "${RUBY_BUILD_BUILD_PATH}/package-1.0.0.tar.gz"
run_inline_definition <<DEF
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#83e6d7725e20166024a1eb74cde80677" copy
DEF
assert_success
[ -x "${INSTALL_ROOT}/bin/package" ]
unstub md5
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment