Skip to content

feat(clean): remove stale iOS/iPadOS .ipsw software updates#693

Merged
tw93 merged 3 commits intotw93:mainfrom
sebastianbreguel:feat/clean-ios-software-updates
Apr 7, 2026
Merged

feat(clean): remove stale iOS/iPadOS .ipsw software updates#693
tw93 merged 3 commits intotw93:mainfrom
sebastianbreguel:feat/clean-ios-software-updates

Conversation

@sebastianbreguel
Copy link
Copy Markdown
Contributor

@sebastianbreguel sebastianbreguel commented Apr 7, 2026

Summary

Adds clean_cached_device_firmware() that removes cached .ipsw firmware installers from ~/Library/iTunes/{iPhone,iPad,iPod} Software Updates/ and Apple Configurator 2's nested cache under ~/Library/Group Containers/*.group.com.apple.configurator/.

.ipsw = full iOS/iPadOS firmware image (~5–8GB each) dropped by Finder/iTunes when you restore or update a device over cable, or by Apple Configurator 2 when managing device fleets. Once applied they're dead weight — Apple re-downloads on demand.

Who this actually helps

Honest scope: probably <10% of users have any .ipsw on disk (OTA updates from the device itself don't touch the Mac). But when the files are there, the win is huge:

  • iOS developers restoring test devices
  • Apple Configurator 2 users (fleet management — firmware accumulates fast)
  • Anyone who restored an iPhone/iPad via cable and never looked at that folder again

For the other 90% it's a silent no-op (one find at maxdepth 1, negligible cost). Same profile as Xcode DeviceSupport cleanup (#519): nicho, pero cuando aplica se liberan decenas de GB.

Before / After

Before — firmware files sit unused, eating disk:

$ du -sh ~/Library/iTunes/iPhone\ Software\ Updates/
 12G    /Users/you/Library/iTunes/iPhone Software Updates/

$ ls ~/Library/iTunes/iPhone\ Software\ Updates/
iPhone15,2_17.5_21F79_Restore.ipsw     6.1G
iPhone17,1_18.0_22A3354_Restore.ipsw   5.9G

$ mo clean
...
  → Device backups
    ⚠ iOS backups: 3.2G, Path: ~/Library/Application Support/MobileSync/Backup
  (firmware left untouched — 12G wasted)

After — firmware removed, backups still respected:

$ mo clean --dry-run
...
  → Device backups & firmware
    ↪ Cached device firmware, 2 files, 12G dry
    ⚠ iOS backups: 3.2G, Path: ~/Library/Application Support/MobileSync/Backup

$ mo clean
...
  → Device backups & firmware
    ✓ Cached device firmware, 2 files, 12G
    ⚠ iOS backups: 3.2G, Path: ~/Library/Application Support/MobileSync/Backup

$ du -sh ~/Library/iTunes/iPhone\ Software\ Updates/
 0B     /Users/you/Library/iTunes/iPhone Software Updates/

User with no cached firmware (majority case):

$ mo clean
...
  → Device backups & firmware
    ⚠ iOS backups: 3.2G, Path: ~/Library/Application Support/MobileSync/Backup
  (no firmware line → function silently no-ops)

Design choices

  • Never touches backups under MobileSync/ — only .ipsw files at the firmware paths
  • Dry-run aware, whitelist-respecting, size reporting, counter integration — matches clean_chrome_old_versions pattern
  • Registers whitelist sentinels in manage/whitelist.sh so users discover and protect the paths via mo clean --whitelist:
    [ ] iOS/iPadOS device firmware (.ipsw) from iTunes/Finder
    [ ] Apple Configurator 2 device firmware (.ipsw)
    
  • Section renamed from Device backups to Device backups & firmware (firmware isn't a backup)

Test plan

  • bats tests/clean_cached_device_firmware.bats — 6/6 pass

    • no-op when empty
    • dry-run reports iTunes dirs
    • finds nested .ipsw under Apple Configurator 2 Group Container
    • non-dry-run actually deletes
    • dry-run with real safe_remove (no mock) leaves filesystem untouched
    • respects whitelist
  • Regression: bats tests/clean_browser_versions.bats tests/clean_user_core.bats all green

  • Verified no-op path on a real Mac with zero .ipsw files (no false positives, no errors)

  • Manual validation on real Mac: created 10MB fixture .ipsw, ran ./mo clean --dry-run, verified output:

    ➤ Device backups & firmware
      → Cached device firmware, 1 files, 10.5MB dry
    

    Fixture cleaned up after test.

@sebastianbreguel sebastianbreguel requested a review from tw93 as a code owner April 7, 2026 03:32
sebastianbreguel and others added 3 commits April 7, 2026 14:23
Add clean_ios_software_updates that removes cached firmware installers
from ~/Library/iTunes/{iPhone,iPad,iPod} Software Updates. These are
5-8GB .ipsw files already consumed by the device; macOS re-downloads
them on demand. Backups under MobileSync are never touched.

Follows the clean_chrome_old_versions pattern: dry-run aware,
whitelist-respecting, integrated into the Device backups section
alongside check_ios_device_backups.
Address tw93 follow-up nits on the initial ipsw cleanup:

- Rename function to clean_cached_device_firmware and section to
  'Device backups & firmware' (ipsw is firmware, not a backup)
- Extend coverage to Apple Configurator 2 nested firmware cache under
  ~/Library/Group Containers/*.group.com.apple.configurator (was missed)
- Register whitelist sentinels in manage/whitelist.sh so users can
  discover and protect the paths through the whitelist UI
- Add dry-run test that uses real safe_remove (no mock) to verify the
  filesystem stays untouched in preview mode
- Add Configurator 2 fixture test
@tw93 tw93 force-pushed the feat/clean-ios-software-updates branch from 6bd81d4 to ac6ee19 Compare April 7, 2026 06:24
@tw93 tw93 merged commit 9e799b5 into tw93:main Apr 7, 2026
9 checks passed
@tw93
Copy link
Copy Markdown
Owner

tw93 commented Apr 7, 2026

@sebastianbreguel thanks for this. I kept the feature, pushed a small maintainer follow-up so the cleanup stats only count successful removals, and merged it now.

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