From 9709fbc117aa4f6cfc3768759661d9975aebdb43 Mon Sep 17 00:00:00 2001 From: Pon Pon Date: Sun, 16 Feb 2025 10:26:54 -0800 Subject: [PATCH 1/4] Add error handling to flatpak_system_updates getter --- nobara-updater/src/nobara_sync.py | 57 ++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/nobara-updater/src/nobara_sync.py b/nobara-updater/src/nobara_sync.py index 71a55e9..2c85fdc 100755 --- a/nobara-updater/src/nobara_sync.py +++ b/nobara-updater/src/nobara_sync.py @@ -526,31 +526,50 @@ def check_updates(return_texts: bool = False) -> None | tuple[str | None, str | def fp_get_system_updates() -> list[Flatpak.Ref] | None: # Get our flatpak updates system_installation = Flatpak.Installation.new_system(None) - flatpak_system_updates = system_installation.list_installed_refs_for_update(None) - del system_installation - if flatpak_system_updates != []: - return flatpak_system_updates - return [] + with fp_system_installation_list(system_installation) as flatpak_sys_updates: + if flatpak_system_updates != []: + return flatpak_system_updates + return [] def install_system_flatpak_updates() -> None: # System installation updates system_installation = Flatpak.Installation.new_system(None) - flatpak_sys_updates = system_installation.list_installed_refs_for_update(None) - if flatpak_sys_updates is not None: - transaction = Flatpak.Transaction.new_for_installation(system_installation) - for ref in flatpak_sys_updates: - logger.info( - "Updating %s for system installation...", ref.get_appdata_name() - ) + with fp_system_installation_list(system_installation) as flatpak_sys_updates: + if flatpak_sys_updates is not None: + transaction = Flatpak.Transaction.new_for_installation(system_installation) + for ref in flatpak_sys_updates: + logger.info( + "Updating %s for system installation...", ref.get_appdata_name() + ) + try: + # Perform the update + transaction.add_update(ref.format_ref(), None, None) + except Exception as e: + logger.error("Error updating %s: %s", ref.get_appdata_name(), e) + transaction.run() + logger.info("Flatpak System Updates complete!") + +class fp_system_installation_list(object): + # Generates flatpak_system_updates for other functions with error handling + def __init__(self, system_installation): + self.system_installation = system_installation + + + def __enter__(self): + error = True # No do-while in Python so init to true to run loop once + while not error: try: - # Perform the update - transaction.add_update(ref.format_ref(), None, None) - except Exception as e: - logger.error("Error updating %s: %s", ref.get_appdata_name(), e) - transaction.run() - logger.info("Flatpak System Updates complete!") - del system_installation + flatpak_system_updates = self.system_installation.list_installed_refs_for_update(None) + except gi.repository.GLib.GError as e: + logger.error(e) + else: + error = False + return flatpak_system_updates + + + def __exit__(self, *args): + del self.system_installation def button_ensure_sensitivity( widget: Gtk.Widget, desired_state: bool From 40e3b53c5cb8876aff09dedcb65f509892dfeef7 Mon Sep 17 00:00:00 2001 From: Pon Pon Date: Tue, 18 Feb 2025 17:24:01 -0800 Subject: [PATCH 2/4] Initialize flatpak_system_updates to None when no Flatpak updates --- nobara-updater/src/nobara_sync.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nobara-updater/src/nobara_sync.py b/nobara-updater/src/nobara_sync.py index 2c85fdc..b416386 100755 --- a/nobara-updater/src/nobara_sync.py +++ b/nobara-updater/src/nobara_sync.py @@ -527,8 +527,8 @@ def fp_get_system_updates() -> list[Flatpak.Ref] | None: # Get our flatpak updates system_installation = Flatpak.Installation.new_system(None) with fp_system_installation_list(system_installation) as flatpak_sys_updates: - if flatpak_system_updates != []: - return flatpak_system_updates + if flatpak_sys_updates != []: + return flatpak_sys_updates return [] @@ -557,6 +557,7 @@ def __init__(self, system_installation): def __enter__(self): + flatpak_system_updates = None error = True # No do-while in Python so init to true to run loop once while not error: try: From 6ac0ff4a41cdffdb27a7052503547898edbc7009 Mon Sep 17 00:00:00 2001 From: Pon Pon Date: Fri, 21 Feb 2025 13:18:30 -0800 Subject: [PATCH 3/4] Fix system_installation ref count system_installation needs to be deleted manually using del for cleanup to occur. #44 added a context manager in 9709fbc117aa4f6cfc3768759661d9975aebdb43 however did not properly clean up refcount. This change removes spurious references, and reintroduces `del` where required. --- nobara-updater/src/nobara_sync.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nobara-updater/src/nobara_sync.py b/nobara-updater/src/nobara_sync.py index b416386..da99662 100755 --- a/nobara-updater/src/nobara_sync.py +++ b/nobara-updater/src/nobara_sync.py @@ -525,8 +525,7 @@ def check_updates(return_texts: bool = False) -> None | tuple[str | None, str | def fp_get_system_updates() -> list[Flatpak.Ref] | None: # Get our flatpak updates - system_installation = Flatpak.Installation.new_system(None) - with fp_system_installation_list(system_installation) as flatpak_sys_updates: + with fp_system_installation_list(Flatpak.Installation.new_system(None)) as flatpak_sys_updates: if flatpak_sys_updates != []: return flatpak_sys_updates return [] @@ -549,6 +548,7 @@ def install_system_flatpak_updates() -> None: logger.error("Error updating %s: %s", ref.get_appdata_name(), e) transaction.run() logger.info("Flatpak System Updates complete!") + del system_installation class fp_system_installation_list(object): # Generates flatpak_system_updates for other functions with error handling From 977a17dc45c22ffb270977576afc0285d14195c0 Mon Sep 17 00:00:00 2001 From: Pon Pon Date: Fri, 21 Feb 2025 13:35:18 -0800 Subject: [PATCH 4/4] Fix deadlock when no internet connection --- nobara-updater/src/nobara_sync.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nobara-updater/src/nobara_sync.py b/nobara-updater/src/nobara_sync.py index da99662..3e21c7f 100755 --- a/nobara-updater/src/nobara_sync.py +++ b/nobara-updater/src/nobara_sync.py @@ -564,6 +564,8 @@ def __enter__(self): flatpak_system_updates = self.system_installation.list_installed_refs_for_update(None) except gi.repository.GLib.GError as e: logger.error(e) + except: + raise else: error = False return flatpak_system_updates