Skip to content

Commit

Permalink
Disk space checks should come earlier and use MB in the message
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimergp committed Nov 8, 2024
1 parent ee89d73 commit 4d03001
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions constructor/header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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@//@/@')
Expand Down

0 comments on commit 4d03001

Please sign in to comment.