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

feat: Checks needed disk space before starting install #38

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions install.ps1
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ Test-GitVersion

$force = $args -contains "--force"

# Check if there is enough free space
$requiredSpace = 1100MB # 1100 MiB
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How was this value chosen?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was near the smallest amount needed to complete the install of shorebird, including the Flutter cache, and pub packages that are pulled down.

Testing was done on MacOS

hdiutil create -size 1250m -fs HFS+ -volname "TestVolume" test.dmg
hdiutil attach test.dmg
HOME=/Volumes/TestVolume ./install.sh
hdiutil detach /Volumes/TestVolume

$installDrive = (Split-Path -Qualifier $installDirectory).TrimEnd(':')
$freeSpace = (Get-PSDrive -Name $installDrive).Free
if ($freeSpace -lt $requiredSpace) {
if ($force) {
Write-Output "Attempting Shorebird install with less than 1100 MiB of free space."
}
else {
Write-Output "Error: Not enough free space. At least 1100 MiB is required. Use --force to install anyway."
exit 1
}
}

if (Test-Path $installDirectory) {
if ($force) {
Write-Output "Existing Shorebird installation detected. Overwriting..."
Expand Down
12 changes: 12 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ if [ $GIT_VERSION_COMPARISON -eq 2 ]; then
exit 1
fi

# Check if there is enough free space
REQUIRED_SPACE=$((1100 * 1024)) # 1100 MiB in KiB
FREE_SPACE=$(df -k "$(dirname "$(install_dir)")" | tail -1 | awk '{print $4}')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really dense line and could stand to be broken up and commented

if [ $FREE_SPACE -lt $REQUIRED_SPACE ]; then
if [ "$FORCE" = true ]; then
echo "Attempting Shorebird install with less than 1100 MiB of free space."
else
echo >&2 "Error: Not enough free space. At least 1100 MiB is required. Use --force to install anyway."
exit 1
fi
fi

# Check if install_dir already exists
if [ -d "$(install_dir)" ]; then
if [ "$FORCE" = true ]; then
Expand Down
Loading