From 8189b01a268ce9468ee9d2e8bbace8d58a31dc1c Mon Sep 17 00:00:00 2001 From: Christian Winther Date: Fri, 26 Jan 2024 20:17:54 +0000 Subject: [PATCH] improve naming of directory-is-empty --- docker/shared/root/docker/entrypoint.sh | 2 +- docker/shared/root/docker/helpers.sh | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docker/shared/root/docker/entrypoint.sh b/docker/shared/root/docker/entrypoint.sh index 57378d23f..9a170be13 100755 --- a/docker/shared/root/docker/entrypoint.sh +++ b/docker/shared/root/docker/entrypoint.sh @@ -31,7 +31,7 @@ IFS=' ' read -ar skip_scripts <<< "$ENTRYPOINT_SKIP_SCRIPTS" mkdir -p "${ENTRYPOINT_D_ROOT}" # If ENTRYPOINT_D_ROOT directory is empty, warn and run the regular command -if is-directory-empty "${ENTRYPOINT_D_ROOT}"; then +if directory-is-empty "${ENTRYPOINT_D_ROOT}"; then log-warning "No files found in ${ENTRYPOINT_D_ROOT}, skipping configuration" exec "$@" diff --git a/docker/shared/root/docker/helpers.sh b/docker/shared/root/docker/helpers.sh index 5826f3c9a..d2913e7d3 100644 --- a/docker/shared/root/docker/helpers.sh +++ b/docker/shared/root/docker/helpers.sh @@ -317,13 +317,14 @@ function file-exists() { [[ -f "$1" ]] } + # @description Checks if $1 contains any files or not # @arg $1 string The path to check # @exitcode 0 If $1 contains files # @exitcode 1 If $1 does *NOT* contain files -function is-directory-empty() +function directory-is-empty() { - ! find "${1}" -mindepth 1 -maxdepth 1 -type f -print -quit 2> /dev/null | read -r + [ -z "$(ls -A "${1}")" ] } # @description Ensures a directory exists (via mkdir)