From fbc8f70c995a0ccf89a4da38bc9c1a3cd0e33880 Mon Sep 17 00:00:00 2001 From: h8d13 Date: Tue, 6 Jan 2026 22:49:10 +0100 Subject: [PATCH 1/2] Protect host mirrorlists when not in ISO env --- archinstall/lib/pacman/config.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/archinstall/lib/pacman/config.py b/archinstall/lib/pacman/config.py index 6b46824636..a8834cca94 100644 --- a/archinstall/lib/pacman/config.py +++ b/archinstall/lib/pacman/config.py @@ -2,6 +2,7 @@ from pathlib import Path from shutil import copy2 +from ..general import running_from_host from ..models.packages import Repository @@ -46,9 +47,12 @@ def apply(self) -> None: if row + 1 < len(content) and content[row + 1].lstrip().startswith('#'): content[row + 1] = re.sub(r'^#\s*', '', content[row + 1]) - # Write the modified content back to the file - with open(self._config_path, 'w') as f: - f.writelines(content) + # Modify file only in ISO env + if running_from_host(): + pass + else: + with open(self._config_path, 'w') as f: + f.writelines(content) def persist(self) -> None: if self._repositories and self._config_remote_path: From 42c4bef93f8c5d4c770a7256c7982dbd878b5fb0 Mon Sep 17 00:00:00 2001 From: h8d13 Date: Wed, 7 Jan 2026 13:44:04 +0100 Subject: [PATCH 2/2] Add atexit handler and safeguard properly --- archinstall/lib/pacman/config.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/archinstall/lib/pacman/config.py b/archinstall/lib/pacman/config.py index a8834cca94..5fac145204 100644 --- a/archinstall/lib/pacman/config.py +++ b/archinstall/lib/pacman/config.py @@ -1,3 +1,4 @@ +import atexit import re from pathlib import Path from shutil import copy2 @@ -47,10 +48,12 @@ def apply(self) -> None: if row + 1 < len(content) and content[row + 1].lstrip().startswith('#'): content[row + 1] = re.sub(r'^#\s*', '', content[row + 1]) - # Modify file only in ISO env + # Apply temp using backup then revert on exit handler if running_from_host(): - pass - else: + temp_copy = self._config_path.with_suffix('.bak') + copy2(self._config_path, temp_copy) + atexit.register(lambda: copy2(temp_copy, self._config_path)) + else: # Apply directly with open(self._config_path, 'w') as f: f.writelines(content)