Skip to content

install: Add cleanup step#3759

Merged
patrickelectric merged 1 commit intobluerobotics:masterfrom
patrickelectric:clean-disk-space
Feb 4, 2026
Merged

install: Add cleanup step#3759
patrickelectric merged 1 commit intobluerobotics:masterfrom
patrickelectric:clean-disk-space

Conversation

@patrickelectric
Copy link
Member

@patrickelectric patrickelectric commented Feb 4, 2026

Summary by Sourcery

Add a pre-installation disk space check with automatic cleanup to ensure sufficient free space before installing.

Enhancements:

  • Refactor available disk space calculation into a reusable helper function returning MB.
  • Introduce a disk cleanup step that removes apt caches, package lists, and non-English locale files to free space before enforcing minimum space requirements.
  • Improve logging around disk space by reporting available space before and after cleanup.

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
@sourcery-ai
Copy link

sourcery-ai bot commented Feb 4, 2026

Reviewer's Guide

Adds a reusable function to compute available disk space in MB and introduces a pre-installation disk cleanup sequence (apt caches, apt lists, non-English locales) before enforcing a minimum free-space check in the installer.

Sequence diagram for installer disk space computation and cleanup

sequenceDiagram
    participant Installer as install_sh
    participant FS as filesystem
    participant AptCache as apt_cache
    participant AptLists as apt_lists
    participant Locale as locales

    Installer->>FS: stat -f / --format %a
    FS-->>Installer: free_blocks
    Installer->>FS: stat -f / --format %S
    FS-->>Installer: block_size
    Installer->>Installer: compute AVAILABLE_SPACE_MB
    Installer->>Installer: set NECESSARY_SPACE_MB = 1024
    Installer->>Installer: echo available and required space

    Installer->>AptCache: check /var/cache/apt
    alt cache dir exists
        Installer->>AptCache: du -sh /var/cache/apt
        AptCache-->>Installer: size
        Installer->>AptCache: apt-get clean
    end

    Installer->>AptLists: check /var/lib/apt/lists
    alt lists dir exists
        Installer->>AptLists: du -sh /var/lib/apt/lists
        AptLists-->>Installer: size
        Installer->>AptLists: rm -rf /var/lib/apt/lists/*
    end

    Installer->>Locale: check /usr/share/locale
    alt locale dir exists
        Installer->>Locale: du -sh /usr/share/locale
        Locale-->>Installer: size
        Installer->>Locale: find non en* dirs and rm -rf
    end

    Installer->>Installer: echo Disk cleanup complete

    Installer->>FS: stat -f / (recompute)
    FS-->>Installer: free_blocks, block_size
    Installer->>Installer: compute AVAILABLE_SPACE_MB after cleanup
    Installer->>Installer: echo Available space after cleanup

    alt insufficient space
        Installer->>Installer: echo error and exit 1
    else sufficient space
        Installer->>Installer: continue installation
    end
Loading

Flow diagram for pre-installation disk space check and cleanup

flowchart TD
    A[start_install_script] --> B[echo Checking for available space]
    B --> C[call get_available_space_mb]
    C --> D[set AVAILABLE_SPACE_MB]
    D --> E[set NECESSARY_SPACE_MB = 1024]
    E --> F[echo Available and required space]
    F --> G[echo Attempting to free up disk space]

    G --> H{dir /var/cache/apt exists}
    H -- yes --> H1[echo Cleaning /var/cache/apt size]
    H1 --> H2[apt-get clean]
    H -- no --> I

    H2 --> I{dir /var/lib/apt/lists exists}
    I -- yes --> I1[echo Cleaning /var/lib/apt/lists size]
    I1 --> I2[rm -rf /var/lib/apt/lists/*]
    I -- no --> J

    I2 --> J{dir /usr/share/locale exists}
    J -- yes --> J1[echo Cleaning non english locale files size]
    J1 --> J2[find /usr/share/locale ! -name en* -exec rm -rf]
    J -- no --> K

    J2 --> K[echo Disk cleanup complete]

    K --> L[call get_available_space_mb]
    L --> M[set AVAILABLE_SPACE_MB after cleanup]
    M --> N[echo Available space after cleanup]
    N --> O{AVAILABLE_SPACE_MB < NECESSARY_SPACE_MB}
    O -- yes --> P[echo Not enough free space and exit 1]
    O -- no --> Q[continue installation]
Loading

File-Level Changes

Change Details Files
Refactor available disk space calculation into a function and reuse it before and after cleanup.
  • Introduce get_available_space_mb() helper that uses stat to compute free space in MB.
  • Replace inline AVAILABLE_SPACE_MB arithmetic with a call to get_available_space_mb().
  • Clarify comment to state that free space is calculated in MB rather than GB.
install/install.sh
Add disk cleanup steps before enforcing the minimum required free space.
  • Log current available and required space before cleanup.
  • If present, clean /var/cache/apt using apt-get clean, ignoring errors.
  • If present, remove files under /var/lib/apt/lists to reclaim package list space.
  • If present, delete non-English locale directories under /usr/share/locale to free space.
  • Log completion of cleanup, recompute available space, and log post-cleanup free-space value before failing if still below threshold.
install/install.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The disk cleanup logic runs unconditionally on every install; consider only triggering the cleanup when AVAILABLE_SPACE_MB is below NECESSARY_SPACE_MB to avoid surprising data removal on systems that already have sufficient free space.
  • The rm -rf of all non-en* locales under /usr/share/locale is quite aggressive and may break non-English environments; it might be safer to either narrow the paths, make this opt-in, or gate it behind a configuration flag.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The disk cleanup logic runs unconditionally on every install; consider only triggering the cleanup when AVAILABLE_SPACE_MB is below NECESSARY_SPACE_MB to avoid surprising data removal on systems that already have sufficient free space.
- The `rm -rf` of all non-`en*` locales under `/usr/share/locale` is quite aggressive and may break non-English environments; it might be safer to either narrow the paths, make this opt-in, or gate it behind a configuration flag.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@patrickelectric patrickelectric merged commit 65c7b69 into bluerobotics:master Feb 4, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments