diff --git a/constructor/header.sh b/constructor/header.sh index f91e49ae0..52f533741 100644 --- a/constructor/header.sh +++ b/constructor/header.sh @@ -21,6 +21,16 @@ if ! echo "$0" | grep '\.sh$' > /dev/null; then return 1 fi +total_installation_size_kb="__TOTAL_INSTALLATION_SIZE_KB__" +free_disk_space_bytes="$(df -Pk "$PREFIX" | tail -n 1 | awk '{print $4}')" +free_disk_space_kb="$((free_disk_space_bytes / 1024))" +free_disk_space_kb_with_buffer="$((free_disk_space_kb - 50 * 1024))" # add 50MB of buffer +if [ "$free_disk_space_kb_with_buffer" -lt "$total_installation_size_kb" ]; then + printf "ERROR: Not enough free disk space. Only %s MB are available, but %s MB are required (leaving a 50 MB buffer).\\n" \ + "$((free_disk_space_kb / 1024))" "$((total_installation_size_kb / 1024))" >&2 + exit 1 +fi + #if osx and min_osx_version min_osx_version="__MIN_OSX_VERSION__" system_osx_version=$(SYSTEM_VERSION_COMPAT=0 sw_vers -productVersion) @@ -394,15 +404,6 @@ if ! mkdir -p "$PREFIX"; then exit 1 fi -total_installation_size_kb="__TOTAL_INSTALLATION_SIZE_KB__" -free_disk_space_bytes="$(df -Pk "$PREFIX" | tail -n 1 | awk '{print $4}')" -free_disk_space_kb="$((free_disk_space_bytes / 1024))" -free_disk_space_kb_with_buffer="$((free_disk_space_bytes - 100 * 1024))" # add 100MB of buffer -if [ "$free_disk_space_kb_with_buffer" -lt "$total_installation_size_kb" ]; then - printf "ERROR: Not enough free disk space: %s < %s\\n" "$free_disk_space_kb_with_buffer" "$total_installation_size_kb" >&2 - exit 1 -fi - # pwd does not convert two leading slashes to one # https://github.com/conda/constructor/issues/284 PREFIX=$(cd "$PREFIX"; pwd | sed 's@//@/@')