[gnome-software/1114-packagekit-prepared-update-not-found-var-lib-packagekit-prepared-update] packagekit: Ensure update is prepared when all packages are downloaded



commit 14892ec6f6112ce33505087a9c4f4f8eeae0053c
Author: Milan Crha <mcrha redhat com>
Date:   Mon Oct 25 10:57:40 2021 +0200

    packagekit: Ensure update is prepared when all packages are downloaded
    
    Having all packages for update downloaded doesn't mean the update is prepared.
    As the "all downloaded" state is used to recognize that difference mark one
    package for a download, thus the update created the required prepared-update
    file, when it does not exist.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1114

 plugins/packagekit/gs-plugin-packagekit.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
---
diff --git a/plugins/packagekit/gs-plugin-packagekit.c b/plugins/packagekit/gs-plugin-packagekit.c
index e2dbde686..71c8307ed 100644
--- a/plugins/packagekit/gs-plugin-packagekit.c
+++ b/plugins/packagekit/gs-plugin-packagekit.c
@@ -715,6 +715,8 @@ gs_plugin_add_updates (GsPlugin *plugin,
        g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin);
        g_autoptr(PkResults) results = NULL;
        g_autoptr(GPtrArray) array = NULL;
+       g_autoptr(GsApp) first_app = NULL;
+       gboolean all_downloaded = TRUE;
 
        /* do sync call */
        gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
@@ -735,8 +737,24 @@ gs_plugin_add_updates (GsPlugin *plugin,
                PkPackage *package = g_ptr_array_index (array, i);
                g_autoptr(GsApp) app = NULL;
                app = gs_plugin_packagekit_build_update_app (plugin, package);
+               all_downloaded = all_downloaded && !gs_app_get_size_download (app);
+               if (all_downloaded && first_app == NULL)
+                       first_app = g_object_ref (app);
                gs_app_list_add (list, app);
        }
+       /* Having all packages downloaded doesn't mean the update is also prepared,
+          because the 'prepared-update' file can be missing, thus verify it and
+          if not found, then set one application as needed download, to have
+          the update properly prepared. */
+       if (all_downloaded && first_app != NULL) {
+               g_auto(GStrv) prepared_ids = NULL;
+               /* It's an overhead to get all the package IDs, but there's no easier
+                  way to verify the prepared-update file exists. */
+               prepared_ids = pk_offline_get_prepared_ids (NULL);
+               if (prepared_ids == NULL || prepared_ids[0] == NULL)
+                       gs_app_set_size_download (first_app, 1);
+       }
+
        return TRUE;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]