From 0cb2ad1b20ea3b97ef0e19516ac0de63dd0df464 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Thu, 18 Aug 2022 17:21:07 -0600 Subject: [PATCH] Installer: Check space before starting --- CHANGELOG.md | 1 + gui/gui_main.py | 8 ++++++++ resources/installer.py | 7 +++++++ resources/utilities.py | 6 ++++++ 4 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03118e38a..b07b3284f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.4.11 - Enable AppleMCEReporterDisabler whenever spoofing affected SMBIOS - ie. iMacPro1,1, MacPro6,1 and MacPro7,1 +- Verify host's disk space before downloading macOS Installers ## 0.4.10 - Resolve Nvidia Kepler support in macOS 12.5 Beta 3 and newer diff --git a/gui/gui_main.py b/gui/gui_main.py index 346540ef0..bd2495f6d 100644 --- a/gui/gui_main.py +++ b/gui/gui_main.py @@ -1511,6 +1511,14 @@ class wx_python_gui: except ValueError: pass + # Ensure we have space to both download and extract the installer + host_space = utilities.get_free_space() + needed_space = app_dict['Size'] * 2 + if host_space < needed_space: + dlg = wx.MessageDialog(self.frame_modal, f"You do not have enough free space to download and extract this installer. Please free up some space and try again\n\n{utilities.human_fmt(host_space)} available vs {utilities.human_fmt(needed_space)} required", "Insufficient Space", wx.OK | wx.ICON_WARNING) + dlg.ShowModal() + return + self.frame.DestroyChildren() installer_name = f"macOS {app_dict['Version']} ({app_dict['Build']})" diff --git a/resources/installer.py b/resources/installer.py index 07bc1e773..4ce7bf097 100644 --- a/resources/installer.py +++ b/resources/installer.py @@ -372,6 +372,13 @@ def generate_installer_creation_script(tmp_location, installer_path, disk): if utilities.check_filesystem_type() != "apfs": # HFS+ disks do not support CoW args[1] = "-R" + # Ensure we have enough space for the duplication + space_available = utilities.get_free_space() + space_needed = Path(ia_tmp).stat().st_size + if space_available < space_needed: + print("Not enough free space to create installer.sh") + print(f"{utilities.human_fmt(space_available)} available, {utilities.human_fmt(space_needed)} required") + return False subprocess.run(args) # Adjust installer_path to point to the copied installer diff --git a/resources/utilities.py b/resources/utilities.py index 8e5f5d89a..11eeef612 100644 --- a/resources/utilities.py +++ b/resources/utilities.py @@ -13,6 +13,7 @@ from ctypes import CDLL, c_uint, byref import time import atexit import requests +import shutil from resources import constants, ioreg from data import sip_data, os_data @@ -549,6 +550,11 @@ def find_disk_off_uuid(uuid): pass return None +def get_free_space(disk=None): + if disk is None: + disk = "/" + total, used, free = shutil.disk_usage("/") + return free def grab_mount_point_from_disk(disk): data = plistlib.loads(subprocess.run(f"diskutil info -plist {disk}".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode())