Skip to content

Commit

Permalink
fix: do not abort if cache var is empty (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chumper authored Feb 13, 2022
1 parent db53a2f commit dba7c9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/usr/local/buildpack/utils/cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ function download_file () {
# If BUILDPACK_CACHE_MAX_ALLOCATED_DISK is not set then the cache will be cleaned
function cleanup_cache () {
local single_file=${1:false}
check BUILDPACK_CACHE_DIR true

if [ -z "${BUILDPACK_CACHE_DIR}" ]; then
# BUILD_CACHE_DIR is empty
exit 0
fi

local max_fill_level=${BUILDPACK_CACHE_MAX_ALLOCATED_DISK:-100}

Expand Down
7 changes: 5 additions & 2 deletions test/bash/cache.bats
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ teardown() {
echo $TEST_FILL_LEVEL
}

run cleanup_cache
assert_success

# create cache dir
BUILDPACK_CACHE_DIR="${TEST_ROOT_DIR}/cache"
mkdir -p "${BUILDPACK_CACHE_DIR}/b"
Expand All @@ -100,12 +103,12 @@ teardown() {
BUILDPACK_CACHE_DIR= \
BUILDPACK_CACHE_MAX_ALLOCATED_DISK= \
run cleanup_cache
assert_failure
assert_success

BUILDPACK_CACHE_DIR= \
BUILDPACK_CACHE_MAX_ALLOCATED_DISK=20 \
run cleanup_cache
assert_failure
assert_success

BUILDPACK_CACHE_MAX_ALLOCATED_DISK= \
run cleanup_cache
Expand Down

0 comments on commit dba7c9b

Please sign in to comment.