From 6b9cc77633d940859f3ee8f08f4042df285a9b11 Mon Sep 17 00:00:00 2001 From: Softer Date: Mon, 8 Jun 2026 02:28:39 +0300 Subject: [PATCH] Simplify pacman sync() and guard gpg-agent kill on running state Collapse the duplicated self.ask() blocks in sync() into a single call via a msg variable, and drop the redundant default_cmd='pacman' (it is already the default). In _reinit_keyring(), check that gpg-agent is actually running (pgrep -x) before killing it, instead of catching the killall error and assuming it was not running. --- archinstall/lib/pacman/pacman.py | 38 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/archinstall/lib/pacman/pacman.py b/archinstall/lib/pacman/pacman.py index bd845410..83b965e2 100644 --- a/archinstall/lib/pacman/pacman.py +++ b/archinstall/lib/pacman/pacman.py @@ -55,35 +55,35 @@ class Pacman: return try: - self.run('-Syy', default_cmd='pacman') + self.run('-Syy') except SysCallError as err: if b'GPGME' in err.worker_log or b'keyring' in err.worker_log.lower(): warn('Pacman sync failed with keyring error, attempting keyring reinit') self._reinit_keyring() - self.ask( - 'Could not sync a new package database after keyring reinit', - 'Could not sync mirrors', - self.run, - '-Syy', - default_cmd='pacman', - ) + msg = 'Could not sync a new package database after keyring reinit' else: - self.ask( - 'Could not sync a new package database', - 'Could not sync mirrors', - self.run, - '-Syy', - default_cmd='pacman', - ) + msg = 'Could not sync a new package database' + + self.ask(msg, 'Could not sync mirrors', self.run, '-Syy') self.synced = True @staticmethod - def _reinit_keyring() -> None: + def _is_running(process: str) -> bool: try: - SysCommand('killall gpg-agent') - except SysCallError as err: - debug(f'killall gpg-agent failed (may not be running): {err}') + SysCommand(f'pgrep -x {process}') + return True + except SysCallError: + debug(f'{process} is not running') + return False + + @staticmethod + def _reinit_keyring() -> None: + if Pacman._is_running('gpg-agent'): + try: + SysCommand('killall gpg-agent') + except SysCallError as err: + debug(f'Failed to kill gpg-agent: {err}') try: SysCommand('pacman-key --init')