From 3bd7836de4a46cb6b6d3db7db26d768016a8aad8 Mon Sep 17 00:00:00 2001 From: jaimergp Date: Thu, 25 Jan 2024 11:36:00 +0100 Subject: [PATCH 1/5] check available disk space in sh installers --- constructor/header.sh | 8 ++++++++ constructor/shar.py | 2 ++ 2 files changed, 10 insertions(+) diff --git a/constructor/header.sh b/constructor/header.sh index d35bab72b..80a753f8d 100644 --- a/constructor/header.sh +++ b/constructor/header.sh @@ -349,6 +349,14 @@ if ! mkdir -p "$PREFIX"; then exit 1 fi +total_installation_size="__TOTAL_INSTALLATION_SIZE__" +free_disk_space="$(df -Pk "$PREFIX" | tail -n 1 | awk '{print $4}')" +free_disk_space_with_buffer="$((free_disk_space - 100 * 1024 * 1024))" # add 100MB of buffer +if [ "$free_disk_space_with_buffer" -lt "$total_installation_size" ]; then + printf "ERROR: Not enough free disk space: %s < %s\\n" "$free_disk_space" "$total_installation_size" >&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@//@/@') diff --git a/constructor/shar.py b/constructor/shar.py index 299f3ab9f..1ed5e79ee 100644 --- a/constructor/shar.py +++ b/constructor/shar.py @@ -18,6 +18,7 @@ from .preconda import write_files as preconda_write_files from .utils import ( add_condarc, + approx_size_kb, filename_dist, fill_template, get_final_channels, @@ -90,6 +91,7 @@ def get_header(conda_exec, tarball, info): 'pycache': '__pycache__', 'SHORTCUTS': shortcuts_flags(info), 'REGISTER_ENVS': str(info.get("register_envs", True)).lower(), + 'TOTAL_INSTALLATION_SIZE': approx_size_kb(info, "total") } if has_license: replace['LICENSE'] = read_ascii_only(info['license_file']) From d81a9464f3dcfe029dee2f226ef6ea6c750b6db9 Mon Sep 17 00:00:00 2001 From: jaimergp Date: Thu, 25 Jan 2024 11:39:45 +0100 Subject: [PATCH 2/5] add news --- news/751-disk-usage-sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 news/751-disk-usage-sh diff --git a/news/751-disk-usage-sh b/news/751-disk-usage-sh new file mode 100644 index 000000000..19cc24775 --- /dev/null +++ b/news/751-disk-usage-sh @@ -0,0 +1,19 @@ +### Enhancements + +* In SH installers, error early if available disk space for chosen installation path is insufficient. (#749 via #751) + +### Bug fixes + +* + +### Deprecations + +* + +### Docs + +* + +### Other + +* From 24998dabbe52e8fc525e8bca6e660fb9e6468e74 Mon Sep 17 00:00:00 2001 From: jaimergp Date: Fri, 26 Jan 2024 11:38:36 +0100 Subject: [PATCH 3/5] str this int --- constructor/shar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constructor/shar.py b/constructor/shar.py index 1ed5e79ee..dd1a3dbd7 100644 --- a/constructor/shar.py +++ b/constructor/shar.py @@ -91,7 +91,7 @@ def get_header(conda_exec, tarball, info): 'pycache': '__pycache__', 'SHORTCUTS': shortcuts_flags(info), 'REGISTER_ENVS': str(info.get("register_envs", True)).lower(), - 'TOTAL_INSTALLATION_SIZE': approx_size_kb(info, "total") + 'TOTAL_INSTALLATION_SIZE': str(approx_size_kb(info, "total")), } if has_license: replace['LICENSE'] = read_ascii_only(info['license_file']) From a5acaa9ab629dce8397ca1aa0799cb8c38e2928c Mon Sep 17 00:00:00 2001 From: jaimergp Date: Fri, 26 Jan 2024 17:14:15 +0100 Subject: [PATCH 4/5] use kb everywhere --- constructor/header.sh | 11 ++++++----- constructor/shar.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/constructor/header.sh b/constructor/header.sh index 80a753f8d..875d83c30 100644 --- a/constructor/header.sh +++ b/constructor/header.sh @@ -349,11 +349,12 @@ if ! mkdir -p "$PREFIX"; then exit 1 fi -total_installation_size="__TOTAL_INSTALLATION_SIZE__" -free_disk_space="$(df -Pk "$PREFIX" | tail -n 1 | awk '{print $4}')" -free_disk_space_with_buffer="$((free_disk_space - 100 * 1024 * 1024))" # add 100MB of buffer -if [ "$free_disk_space_with_buffer" -lt "$total_installation_size" ]; then - printf "ERROR: Not enough free disk space: %s < %s\\n" "$free_disk_space" "$total_installation_size" >&2 +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 diff --git a/constructor/shar.py b/constructor/shar.py index dd1a3dbd7..9f2d90425 100644 --- a/constructor/shar.py +++ b/constructor/shar.py @@ -91,7 +91,7 @@ def get_header(conda_exec, tarball, info): 'pycache': '__pycache__', 'SHORTCUTS': shortcuts_flags(info), 'REGISTER_ENVS': str(info.get("register_envs", True)).lower(), - 'TOTAL_INSTALLATION_SIZE': str(approx_size_kb(info, "total")), + 'TOTAL_INSTALLATION_SIZE_KB': str(approx_size_kb(info, "total")), } if has_license: replace['LICENSE'] = read_ascii_only(info['license_file']) From 11b7c1ab41191f00cd48f11f9ccccc77ee61da6a Mon Sep 17 00:00:00 2001 From: jaimergp Date: Fri, 26 Jan 2024 17:48:40 +0100 Subject: [PATCH 5/5] satisfy shellcheck --- constructor/header.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constructor/header.sh b/constructor/header.sh index 875d83c30..eb76cc6b8 100644 --- a/constructor/header.sh +++ b/constructor/header.sh @@ -351,7 +351,7 @@ 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="$((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