From 2907f4efc3c57dd3eeef0a673a82908f9d04f085 Mon Sep 17 00:00:00 2001 From: Luxury Date: Sun, 8 Nov 2026 23:09:58 -0500 Subject: [PATCH] Stop the installer space check at an unavailable drive root --- installer/steps.py | 3 ++- tests/installer_test.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/installer/steps.py b/installer/steps.py index ba439a5f..18a71225 100644 --- a/installer/steps.py +++ b/installer/steps.py @@ -168,7 +168,8 @@ def run_tool(ctx, step, script, args, parse=None, cwd=None): def free_bytes(path): """Free bytes on the disk of path (its nearest existing parent) and that parent's device.""" p = Path(path) - while not p.exists(): + # An unavailable drive or share has no existing ancestor: let disk_usage report its OS error at the root. + while not p.exists() and p.parent != p: p = p.parent return shutil.disk_usage(p).free, os.stat(p).st_dev diff --git a/tests/installer_test.py b/tests/installer_test.py index b57ccf41..b0b58f1c 100644 --- a/tests/installer_test.py +++ b/tests/installer_test.py @@ -489,6 +489,29 @@ class CleanupTest(unittest.TestCase): self.assertEqual(self.run_cleanup(), 'cleanup.romfs_unreadable') +class FreeSpaceTest(unittest.TestCase): + def test_missing_folders_use_the_nearest_existing_parent(self): + with tempfile.TemporaryDirectory() as d: + parent = Path(d) + path = parent / 'missing' / 'install' + with mock.patch.object(steps.shutil, 'disk_usage', return_value=SimpleNamespace(free=1234)) as usage: + self.assertEqual(steps.free_bytes(path), (1234, parent.stat().st_dev)) + usage.assert_called_once_with(parent) + self.assertFalse(path.parent.exists()) + + def test_missing_root_reports_the_filesystem_error(self): + path = Path(ROOT.anchor) / 'missing' / 'install' + root = Path(path.anchor) + error = FileNotFoundError(2, 'No such file or directory', str(root)) + # Bound the failed existence checks so the old parent walk cannot hang the test suite. + with mock.patch.object(Path, 'exists', side_effect=[False] * (len(path.parents) + 1)): + with mock.patch.object(steps.shutil, 'disk_usage', side_effect=error) as usage: + with self.assertRaises(FileNotFoundError) as raised: + steps.free_bytes(path) + self.assertIs(raised.exception, error) + usage.assert_called_once_with(root) + + class BaseGameCheckTest(unittest.TestCase): """Issue #261: an update NSP chosen as the base game was reported as "not Tears of the Kingdom".""" BASE, UPDATE = '0100F2C0115B6000', '0100F2C0115B6800'