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'])