/** * pk_debuginfo_install_resolve_name_to_id: **/ static gchar * pk_debuginfo_install_resolve_name_to_id (PkDebuginfoInstallPrivate *priv, const gchar *package_name, GError **error) { PkResults *results = NULL; PkPackage *item; gchar *package_id = NULL; GPtrArray *list = NULL; GError *error_local = NULL; gchar **names; PkError *error_code = NULL; /* resolve takes a char** */ names = g_strsplit (package_name, ";", -1); /* resolve */ results = pk_client_resolve (priv->client, pk_bitfield_from_enums (PK_FILTER_ENUM_NEWEST, -1), names, NULL, NULL, NULL, &error_local); if (results == NULL) { *error = g_error_new (1, 0, "failed to resolve: %s", error_local->message); g_error_free (error_local); goto out; } /* check error code */ error_code = pk_results_get_error_code (results); if (error_code != NULL) { *error = g_error_new (1, 0, "failed to resolve: %s, %s", pk_error_enum_to_string (pk_error_get_code (error_code)), pk_error_get_details (error_code)); goto out; } /* check we only got one match */ list = pk_results_get_package_array (results); if (list->len == 0) { *error = g_error_new (1, 0, "no package %s found", package_name); goto out; } if (list->len > 1) { *error = g_error_new (1, 0, "more than one package found for %s", package_name); goto out; } /* get the package id */ item = g_ptr_array_index (list, 0); package_id = g_strdup (pk_package_get_id (item)); out: if (error_code != NULL) g_object_unref (error_code); if (results != NULL) g_object_unref (results); if (list != NULL) g_ptr_array_unref (list); g_strfreev (names); return package_id; }
/** * pk_console_resolve_package: **/ gchar * pk_console_resolve_package (PkClient *client, PkBitfield filter, const gchar *package_name, GError **error) { gchar *package_id = NULL; gboolean valid; gchar **tmp; PkResults *results; GPtrArray *array = NULL; guint i; gchar *printable; PkPackage *package; /* have we passed a complete package_id? */ valid = pk_package_id_check (package_name); if (valid) return g_strdup (package_name); /* split */ tmp = g_strsplit (package_name, ",", -1); /* get the list of possibles */ results = pk_client_resolve (client, filter, tmp, NULL, NULL, NULL, error); if (results == NULL) goto out; /* get the packages returned */ array = pk_results_get_package_array (results); if (array == NULL) { *error = g_error_new (1, 0, "did not get package struct for %s", package_name); goto out; } /* nothing found */ if (array->len == 0) { *error = g_error_new (1, 0, "could not find %s", package_name); goto out; } /* just one thing found */ if (array->len == 1) { package = g_ptr_array_index (array, 0); g_object_get (package, "package-id", &package_id, NULL); goto out; } /* TRANSLATORS: more than one package could be found that matched, to follow is a list of possible packages */ g_print ("%s\n", _("More than one package matches:")); for (i=0; i<array->len; i++) { package = g_ptr_array_index (array, i); g_object_get (package, "package-id", &package_id, NULL); printable = pk_package_id_to_printable (package_id); g_print ("%i. %s\n", i+1, printable); g_free (printable); g_free (package_id); } /* TRANSLATORS: This finds out which package in the list to use */ i = pk_console_get_number (_("Please choose the correct package: "), array->len); package = g_ptr_array_index (array, i-1); g_object_get (package, "package-id", &package_id, NULL); out: if (results != NULL) g_object_unref (results); if (array != NULL) g_ptr_array_unref (array); g_strfreev (tmp); return package_id; }
gboolean gs_plugin_url_to_app (GsPlugin *plugin, GsAppList *list, const gchar *url, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); g_autofree gchar *scheme = NULL; g_autofree gchar *path = NULL; const gchar *id = NULL; const gchar * const *id_like = NULL; g_auto(GStrv) package_ids = NULL; g_autoptr(PkResults) results = NULL; g_autoptr(GsApp) app = NULL; g_autoptr(GsOsRelease) os_release = NULL; g_autoptr(GPtrArray) packages = NULL; g_autoptr(GPtrArray) details = NULL; g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin); path = gs_utils_get_url_path (url); /* only do this for apt:// on debian or debian-like distros */ os_release = gs_os_release_new (error); if (os_release == NULL) { g_prefix_error (error, "failed to determine OS information:"); return FALSE; } else { id = gs_os_release_get_id (os_release); id_like = gs_os_release_get_id_like (os_release); scheme = gs_utils_get_url_scheme (url); if (!(g_strcmp0 (scheme, "apt") == 0 && (g_strcmp0 (id, "debian") == 0 || g_strv_contains (id_like, "debian")))) { return TRUE; } } app = gs_app_new (NULL); gs_plugin_packagekit_set_packaging_format (plugin, app); gs_app_add_source (app, path); gs_app_set_kind (app, AS_APP_KIND_GENERIC); gs_app_set_bundle_kind (app, AS_BUNDLE_KIND_PACKAGE); package_ids = g_new0 (gchar *, 2); package_ids[0] = g_strdup (path); g_mutex_lock (&priv->client_mutex); results = pk_client_resolve (priv->client, pk_bitfield_from_enums (PK_FILTER_ENUM_NEWEST, PK_FILTER_ENUM_ARCH, -1), package_ids, cancellable, gs_packagekit_helper_cb, helper, error); g_mutex_unlock (&priv->client_mutex); if (!gs_plugin_packagekit_results_valid (results, error)) { g_prefix_error (error, "failed to resolve package_ids: "); return FALSE; } /* get results */ packages = pk_results_get_package_array (results); details = pk_results_get_details_array (results); if (packages->len >= 1) { if (gs_app_get_local_file (app) != NULL) return TRUE; gs_plugin_packagekit_resolve_packages_app (plugin, packages, app); gs_plugin_packagekit_refine_details_app (plugin, details, app); gs_app_list_add (list, app); } else { g_warning ("no results returned"); } return TRUE; }