From f8b5e93d94a8c2a7d2fd70dbe0a20a8a9f5889eb Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 4 Jul 2024 18:13:06 +0000 Subject: [PATCH] make.sh: Refactor the space check Signed-off-by: Michael Tremer --- make.sh | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/make.sh b/make.sh index 18d8093e8..e644a594d 100755 --- a/make.sh +++ b/make.sh @@ -385,18 +385,17 @@ prepareenv() { exiterror "root privileges required for building" fi - # Checking for necessary temporary space - print_line "Checking for necessary space on disk $BASE_DEV" - BASE_DEV=`df -P -k $BASEDIR | tail -n 1 | awk '{ print $1 }'` - BASE_ASPACE=`df -P -k $BASEDIR | tail -n 1 | awk '{ print $4 }'` - if (( 2048000 > $BASE_ASPACE )); then - BASE_USPACE=`du -skx $BASEDIR | awk '{print $1}'` - if (( 2048000 - $BASE_USPACE > $BASE_ASPACE )); then - print_status FAIL - exiterror "Not enough temporary space available, need at least 2GB on $BASE_DEV" - fi - else - print_status DONE + local free_space free_blocks block_size + + # Fetch free blocks + read -r free_blocks block_size <<< "$(stat --file-system --format="%a %S" "${BUILD_DIR}")" + + # Calculate free space + (( free_space = free_blocks * block_size / 1024 / 1024 )) + + # Check if we have at least 4GB of space + if [ "${free_space}" -lt 4096 ]; then + exiterror "Not enough temporary space available, need at least 4GB" fi # Set umask