Skip to content

Commit

Permalink
Disk space checks should come earlier and use MB in the message (#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimergp authored Nov 9, 2024
1 parent 6b551ff commit 9a10ec5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
14 changes: 8 additions & 6 deletions constructor/header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -392,17 +392,19 @@ elif [ "$FORCE" = "1" ] && [ -e "$PREFIX" ]; then
REINSTALL=1
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 "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

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
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: %s < %s\\n" "$free_disk_space_kb_with_buffer" "$total_installation_size_kb" >&2
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_mb" >&2
exit 1
fi

Expand Down
19 changes: 19 additions & 0 deletions news/889-disk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Perform disk space checks earlier and report errors in MB (`.sh` installers only). (#778 via 889)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>

0 comments on commit 9a10ec5

Please sign in to comment.