Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check available disk space in sh installers #751

Merged
merged 5 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions constructor/header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,15 @@ 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}')"
jaimergp marked this conversation as resolved.
Show resolved Hide resolved
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
2 changes: 2 additions & 0 deletions constructor/shar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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_KB': str(approx_size_kb(info, "total")),
}
if has_license:
replace['LICENSE'] = read_ascii_only(info['license_file'])
Expand Down
19 changes: 19 additions & 0 deletions news/751-disk-usage-sh
Original file line number Diff line number Diff line change
@@ -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

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
Loading