From 4d030018041cfae00f4a990220b900167428fe25 Mon Sep 17 00:00:00 2001 From: jaimergp Date: Fri, 8 Nov 2024 14:10:38 +0100 Subject: [PATCH 1/5] Disk space checks should come earlier and use MB in the message --- constructor/header.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) 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@//@/@') From ce3b6c76ba57e6ac6eccc874b3fdfa0d76a8660d Mon Sep 17 00:00:00 2001 From: jaimergp Date: Fri, 8 Nov 2024 14:12:02 +0100 Subject: [PATCH 2/5] add news --- news/889-disk | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 news/889-disk diff --git a/news/889-disk b/news/889-disk new file mode 100644 index 000000000..d312c7c7b --- /dev/null +++ b/news/889-disk @@ -0,0 +1,19 @@ +### Enhancements + +* + +### Bug fixes + +* Perform disk space checks earlier and report errors in MB (`.sh` installers only). (#778 via 889) + +### Deprecations + +* + +### Docs + +* + +### Other + +* From 138616e772a432fc470f8f780f3b43f92355299b Mon Sep 17 00:00:00 2001 From: jaimergp Date: Fri, 8 Nov 2024 18:07:00 +0100 Subject: [PATCH 3/5] move right before the first mkdir --- constructor/header.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/constructor/header.sh b/constructor/header.sh index 52f533741..851024c31 100644 --- a/constructor/header.sh +++ b/constructor/header.sh @@ -21,16 +21,6 @@ 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) @@ -399,6 +389,16 @@ elif [ "$FORCE" = "1" ] && [ -e "$PREFIX" ]; then REINSTALL=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 ! mkdir -p "$PREFIX"; then printf "ERROR: Could not create directory: '%s'\\n" "$PREFIX" >&2 exit 1 From 0b834f037add0518520d05c143c4a841d558d2ea Mon Sep 17 00:00:00 2001 From: jaimergp Date: Fri, 8 Nov 2024 18:32:49 +0100 Subject: [PATCH 4/5] fix again --- constructor/header.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/constructor/header.sh b/constructor/header.sh index 851024c31..3ec18fcdb 100644 --- a/constructor/header.sh +++ b/constructor/header.sh @@ -390,12 +390,11 @@ elif [ "$FORCE" = "1" ] && [ -e "$PREFIX" ]; then 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="$(df -Pk "$PREFIX" | tail -n 1 | awk '{print $4}')" 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 + "$((free_disk_space_kb_with_buffer / 1024))" "$((total_installation_size_kb / 1024))" >&2 exit 1 fi From 4aff6e203cd2587fcaab420116973405cdd2a70e Mon Sep 17 00:00:00 2001 From: jaimergp Date: Fri, 8 Nov 2024 18:38:43 +0100 Subject: [PATCH 5/5] move again --- constructor/header.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/constructor/header.sh b/constructor/header.sh index 3ec18fcdb..8fbcddbad 100644 --- a/constructor/header.sh +++ b/constructor/header.sh @@ -390,16 +390,18 @@ elif [ "$FORCE" = "1" ] && [ -e "$PREFIX" ]; then fi total_installation_size_kb="__TOTAL_INSTALLATION_SIZE_KB__" +total_installation_size_mb="$(( total_installation_size_kb / 1024 ))" +if ! mkdir -p "$PREFIX"; then + printf "ERROR: Could not create directory: '%s'.\\n" "$PREFIX" >&2 + printf "Check permissions and available disk space (%s MB needed).\\n" "$total_installation_size_mb" >&2 + exit 1 +fi + free_disk_space_kb="$(df -Pk "$PREFIX" | tail -n 1 | awk '{print $4}')" 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_with_buffer / 1024))" "$((total_installation_size_kb / 1024))" >&2 - exit 1 -fi - -if ! mkdir -p "$PREFIX"; then - printf "ERROR: Could not create directory: '%s'\\n" "$PREFIX" >&2 + "$((free_disk_space_kb_with_buffer / 1024))" "$total_installation_size_mb" >&2 exit 1 fi