[gnome-software: 4/8] packagekit: Merge packagekit-offline plugin into packagekit




commit fd7f2d142948a34dba52c25a425469b66377603a
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu May 20 15:35:43 2021 +0100

    packagekit: Merge packagekit-offline plugin into packagekit
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 contrib/gnome-software.spec.in                    |   1 -
 plugins/packagekit/gs-plugin-packagekit-offline.c | 181 ----------------------
 plugins/packagekit/gs-plugin-packagekit.c         | 157 +++++++++++++++++++
 plugins/packagekit/meson.build                    |  16 --
 plugins/rpm-ostree/gs-plugin-rpm-ostree.c         |   1 -
 5 files changed, 157 insertions(+), 199 deletions(-)
---
diff --git a/contrib/gnome-software.spec.in b/contrib/gnome-software.spec.in
index d067ae7c4..4f5af478c 100644
--- a/contrib/gnome-software.spec.in
+++ b/contrib/gnome-software.spec.in
@@ -163,7 +163,6 @@ desktop-file-validate %{buildroot}%{_datadir}/applications/*.desktop
 %{gs_plugin_dir}/libgs_plugin_icons.so
 %{gs_plugin_dir}/libgs_plugin_modalias.so
 %{gs_plugin_dir}/libgs_plugin_os-release.so
-%{gs_plugin_dir}/libgs_plugin_packagekit-offline.so
 %{gs_plugin_dir}/libgs_plugin_packagekit-proxy.so
 %{gs_plugin_dir}/libgs_plugin_packagekit-refine-repos.so
 %{gs_plugin_dir}/libgs_plugin_packagekit-refresh.so
diff --git a/plugins/packagekit/gs-plugin-packagekit.c b/plugins/packagekit/gs-plugin-packagekit.c
index 326414bd2..7fda8bf9e 100644
--- a/plugins/packagekit/gs-plugin-packagekit.c
+++ b/plugins/packagekit/gs-plugin-packagekit.c
@@ -2028,3 +2028,160 @@ gs_plugin_file_to_app (GsPlugin *plugin,
        gs_app_list_add (list, app);
        return TRUE;
 }
+
+static gboolean
+gs_plugin_packagekit_convert_error (GError **error,
+                                   PkErrorEnum error_enum,
+                                   const gchar *details)
+{
+       switch (error_enum) {
+       case PK_ERROR_ENUM_PACKAGE_DOWNLOAD_FAILED:
+       case PK_ERROR_ENUM_NO_CACHE:
+       case PK_ERROR_ENUM_NO_NETWORK:
+       case PK_ERROR_ENUM_NO_MORE_MIRRORS_TO_TRY:
+       case PK_ERROR_ENUM_CANNOT_FETCH_SOURCES:
+       case PK_ERROR_ENUM_UNFINISHED_TRANSACTION:
+               g_set_error_literal (error,
+                                    GS_PLUGIN_ERROR,
+                                    GS_PLUGIN_ERROR_NO_NETWORK,
+                                    details);
+               break;
+       case PK_ERROR_ENUM_BAD_GPG_SIGNATURE:
+       case PK_ERROR_ENUM_CANNOT_UPDATE_REPO_UNSIGNED:
+       case PK_ERROR_ENUM_GPG_FAILURE:
+       case PK_ERROR_ENUM_MISSING_GPG_SIGNATURE:
+       case PK_ERROR_ENUM_PACKAGE_CORRUPT:
+               g_set_error_literal (error,
+                                    GS_PLUGIN_ERROR,
+                                    GS_PLUGIN_ERROR_NO_SECURITY,
+                                    details);
+               break;
+       case PK_ERROR_ENUM_TRANSACTION_CANCELLED:
+               g_set_error_literal (error,
+                                    GS_PLUGIN_ERROR,
+                                    GS_PLUGIN_ERROR_CANCELLED,
+                                    details);
+               break;
+       case PK_ERROR_ENUM_NO_PACKAGES_TO_UPDATE:
+       case PK_ERROR_ENUM_UPDATE_NOT_FOUND:
+               g_set_error_literal (error,
+                                    GS_PLUGIN_ERROR,
+                                    GS_PLUGIN_ERROR_NOT_SUPPORTED,
+                                    details);
+               break;
+       case PK_ERROR_ENUM_NO_SPACE_ON_DEVICE:
+               g_set_error_literal (error,
+                                    GS_PLUGIN_ERROR,
+                                    GS_PLUGIN_ERROR_NO_SPACE,
+                                    details);
+               break;
+       default:
+               g_set_error_literal (error,
+                                    GS_PLUGIN_ERROR,
+                                    GS_PLUGIN_ERROR_FAILED,
+                                    details);
+               break;
+       }
+       return FALSE;
+}
+
+gboolean
+gs_plugin_add_updates_historical (GsPlugin *plugin,
+                                 GsAppList *list,
+                                 GCancellable *cancellable,
+                                 GError **error)
+{
+       guint64 mtime;
+       guint i;
+       g_autoptr(GPtrArray) package_array = NULL;
+       g_autoptr(GError) error_local = NULL;
+       g_autoptr(PkResults) results = NULL;
+       PkExitEnum exit_code;
+
+       /* get the results */
+       results = pk_offline_get_results (&error_local);
+       if (results == NULL) {
+               /* was any offline update attempted */
+               if (g_error_matches (error_local,
+                                    PK_OFFLINE_ERROR,
+                                    PK_OFFLINE_ERROR_NO_DATA)) {
+                       return TRUE;
+               }
+
+               g_set_error (error,
+                            GS_PLUGIN_ERROR,
+                            GS_PLUGIN_ERROR_INVALID_FORMAT,
+                            "Failed to get offline update results: %s",
+                            error_local->message);
+               return FALSE;
+       }
+
+       /* get the mtime of the results */
+       mtime = pk_offline_get_results_mtime (error);
+       if (mtime == 0)
+               return FALSE;
+
+       /* only return results if successful */
+       exit_code = pk_results_get_exit_code (results);
+       if (exit_code != PK_EXIT_ENUM_SUCCESS) {
+               g_autoptr(PkError) error_code = NULL;
+
+               error_code = pk_results_get_error_code (results);
+               if (error_code == NULL) {
+                       g_set_error (error,
+                                    GS_PLUGIN_ERROR,
+                                    GS_PLUGIN_ERROR_FAILED,
+                                    "Offline update failed without error_code set");
+                       return FALSE;
+               }
+
+               return gs_plugin_packagekit_convert_error (error,
+                                                          pk_error_get_code (error_code),
+                                                          pk_error_get_details (error_code));
+       }
+
+       /* distro upgrade? */
+       if (pk_results_get_role (results) == PK_ROLE_ENUM_UPGRADE_SYSTEM) {
+               g_autoptr(GsApp) app = NULL;
+
+               app = gs_app_new (NULL);
+               gs_app_set_from_unique_id (app, "*/*/*/system/*", AS_COMPONENT_KIND_GENERIC);
+               gs_app_set_management_plugin (app, "packagekit");
+               gs_app_add_quirk (app, GS_APP_QUIRK_IS_WILDCARD);
+               gs_app_set_state (app, GS_APP_STATE_UNKNOWN);
+               gs_app_set_kind (app, AS_COMPONENT_KIND_OPERATING_SYSTEM);
+               gs_app_set_bundle_kind (app, AS_BUNDLE_KIND_PACKAGE);
+               gs_app_set_install_date (app, mtime);
+               gs_app_set_metadata (app, "GnomeSoftware::Creator",
+                                    gs_plugin_get_name (plugin));
+               gs_app_list_add (list, app);
+
+               return TRUE;
+       }
+
+       /* get list of package-ids */
+       package_array = pk_results_get_package_array (results);
+       for (i = 0; i < package_array->len; i++) {
+               PkPackage *pkg = g_ptr_array_index (package_array, i);
+               const gchar *package_id;
+               g_autoptr(GsApp) app = NULL;
+               g_auto(GStrv) split = NULL;
+
+               app = gs_app_new (NULL);
+               package_id = pk_package_get_id (pkg);
+               split = g_strsplit (package_id, ";", 4);
+               gs_plugin_packagekit_set_packaging_format (plugin, app);
+               gs_app_add_source (app, split[0]);
+               gs_app_set_update_version (app, split[1]);
+               gs_app_set_management_plugin (app, "packagekit");
+               gs_app_add_source_id (app, package_id);
+               gs_app_set_state (app, GS_APP_STATE_UPDATABLE);
+               gs_app_set_kind (app, AS_COMPONENT_KIND_GENERIC);
+               gs_app_set_bundle_kind (app, AS_BUNDLE_KIND_PACKAGE);
+               gs_app_set_install_date (app, mtime);
+               gs_app_set_metadata (app, "GnomeSoftware::Creator",
+                                    gs_plugin_get_name (plugin));
+               gs_app_list_add (list, app);
+       }
+       return TRUE;
+}
diff --git a/plugins/packagekit/meson.build b/plugins/packagekit/meson.build
index 22b410fb5..9378b8b01 100644
--- a/plugins/packagekit/meson.build
+++ b/plugins/packagekit/meson.build
@@ -95,22 +95,6 @@ shared_module(
   dependencies : [ plugin_libs, packagekit ],
 )
 
-shared_module(
-  'gs_plugin_packagekit-offline',
-sources : [
-    'gs-plugin-packagekit-offline.c',
-    'packagekit-common.c',
-  ],
-  include_directories : [
-    include_directories('../..'),
-    include_directories('../../lib'),
-  ],
-  install : true,
-  install_dir: plugin_dir,
-  c_args : cargs,
-  dependencies : [ plugin_libs, packagekit ],
-)
-
 shared_module(
   'gs_plugin_packagekit-proxy',
 sources : 'gs-plugin-packagekit-proxy.c',
diff --git a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
index eda1d134f..06f07754d 100644
--- a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
+++ b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
@@ -68,7 +68,6 @@ gs_plugin_initialize (GsPlugin *plugin)
         * more sense to use a custom plugin instead of using PackageKit.
         */
        gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit");
-       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-offline");
        gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-proxy");
        gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-refine-repos");
        gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-refresh");


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