/** * pk_plugin_transaction_get_updates: */ static void pk_plugin_transaction_get_updates (PkTransaction *transaction) { GPtrArray *array; PkResults *results; results = pk_transaction_get_results (transaction); array = pk_results_get_package_array (results); if (array->len != 0) { g_debug ("got %i updates, so ignoring %s", array->len, PK_OFFLINE_PREPARED_UPDATE_FILENAME); goto out; } if (g_file_test (PK_OFFLINE_PREPARED_UPDATE_FILENAME, G_FILE_TEST_EXISTS)) { g_debug ("Removing %s as no updates", PK_OFFLINE_PREPARED_UPDATE_FILENAME); g_unlink (PK_OFFLINE_PREPARED_UPDATE_FILENAME); } else { g_debug ("No %s present, so no need to delete", PK_OFFLINE_PREPARED_UPDATE_FILENAME); } out: g_ptr_array_unref (array); }
/** * pk_plugin_transaction_get_updates: */ static void pk_plugin_transaction_get_updates (PkTransaction *transaction) { gchar *path; GPtrArray *array; PkResults *results; results = pk_transaction_get_results (transaction); path = g_build_filename (LOCALSTATEDIR, "lib", "PackageKit", "prepared-update", NULL); array = pk_results_get_package_array (results); if (array->len != 0) { g_debug ("got %i updates, so ignoring %s", array->len, path); goto out; } if (g_file_test (path, G_FILE_TEST_EXISTS)) { g_debug ("Removing %s as no updates", path); g_unlink (path); } else { g_debug ("No %s present, so no need to delete", path); } out: g_free (path); g_ptr_array_unref (array); }
/** * 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_package_sack_resolve_cb: **/ static void pk_package_sack_resolve_cb (GObject *source_object, GAsyncResult *res, PkPackageSackState *state) { PkClient *client = PK_CLIENT (source_object); PkPackage *item; guint i; PkPackage *package; const gchar *package_id; g_autoptr(GError) error = NULL; g_autoptr(PkResults) results = NULL; g_autoptr(GPtrArray) packages = NULL; /* get the results */ results = pk_client_generic_finish (client, res, &error); if (results == NULL) { g_warning ("failed to resolve: %s", error->message); pk_package_sack_merge_bool_state_finish (state, error); return; } /* get the packages */ packages = pk_results_get_package_array (results); if (packages->len == 0) { g_warning ("%i", state->ret); error = g_error_new (1, 0, "no packages found!"); pk_package_sack_merge_bool_state_finish (state, error); return; } /* set data on each item */ for (i = 0; i < packages->len; i++) { item = g_ptr_array_index (packages, i); package_id = pk_package_get_id (item); package = pk_package_sack_find_by_id (state->sack, package_id); if (package == NULL) { g_warning ("failed to find %s", package_id); continue; } /* set data */ g_object_set (package, "info", pk_package_get_info (item), "summary", pk_package_get_summary (item), NULL); g_object_unref (package); } /* all okay */ state->ret = TRUE; /* we're done */ pk_package_sack_merge_bool_state_finish (state, error); }
/** * pk_plugin_transaction_action_method: */ static void pk_plugin_transaction_action_method (PkPlugin *plugin, PkTransaction *transaction, PkResults *results) { GPtrArray *invalidated = NULL; PkPackage *pkg; PkPackageSack *sack; const gchar *package_id; gchar **package_ids; guint i; /* get the existing prepared updates */ sack = pk_plugin_get_existing_prepared_updates (PK_OFFLINE_PREPARED_UPDATE_FILENAME); if (pk_package_sack_get_size (sack) == 0) goto out; /* are there any requested packages that match in prepared-updates */ package_ids = pk_transaction_get_package_ids (transaction); for (i = 0; package_ids[i] != NULL; i++) { pkg = pk_package_sack_find_by_id_name_arch (sack, package_ids[i]); if (pkg != NULL) { g_debug ("%s modified %s, invalidating prepared-updates", package_ids[i], pk_package_get_id (pkg)); pk_plugin_state_changed (plugin); g_object_unref (pkg); goto out; } } /* are there any changed deps that match a package in prepared-updates */ invalidated = pk_results_get_package_array (results); for (i = 0; i < invalidated->len; i++) { package_id = pk_package_get_id (g_ptr_array_index (invalidated, i)); pkg = pk_package_sack_find_by_id_name_arch (sack, package_id); if (pkg != NULL) { g_debug ("%s modified %s, invalidating prepared-updates", package_id, pk_package_get_id (pkg)); pk_plugin_state_changed (plugin); g_object_unref (pkg); goto out; } } out: if (invalidated != NULL) g_ptr_array_unref (invalidated); g_object_unref (sack); }
/** * pk_package_sack_resolve_cb: **/ static void pk_package_sack_resolve_cb (GObject *source_object, GAsyncResult *res, PkPackageSackState *state) { PkClient *client = PK_CLIENT (source_object); GError *error = NULL; PkResults *results; GPtrArray *packages = NULL; PkPackage *item; guint i; PkPackage *package; PkInfoEnum info; gchar *summary; gchar *package_id; /* get the results */ results = pk_client_generic_finish (client, res, &error); if (results == NULL) { g_warning ("failed to resolve: %s", error->message); pk_package_sack_merge_bool_state_finish (state, error); g_error_free (error); goto out; } /* get the packages */ packages = pk_results_get_package_array (results); if (packages->len == 0) { g_warning ("%i", state->ret); error = g_error_new (1, 0, "no packages found!"); pk_package_sack_merge_bool_state_finish (state, error); g_error_free (error); goto out; } /* set data on each item */ for (i=0; i<packages->len; i++) { item = g_ptr_array_index (packages, i); g_object_get (item, "info", &info, "package-id", &package_id, "summary", &summary, NULL); /* get package, and set data */ package = pk_package_sack_find_by_id (state->sack, package_id); if (package == NULL) { g_warning ("failed to find %s", package_id); goto skip; } /* set data */ g_object_set (package, "info", info, "summary", summary, NULL); g_object_unref (package); skip: g_free (summary); g_free (package_id); } /* all okay */ state->ret = TRUE; /* we're done */ pk_package_sack_merge_bool_state_finish (state, error); out: if (results != NULL) g_object_unref (results); if (packages != NULL) g_ptr_array_unref (packages); }
/** * 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; }
/** * pk_debuginfo_install_add_deps: **/ static gboolean pk_debuginfo_install_add_deps (PkDebuginfoInstallPrivate *priv, GPtrArray *packages_search, GPtrArray *packages_results, GError **error) { gboolean ret = TRUE; PkResults *results = NULL; PkPackage *item; gchar *package_id = NULL; GPtrArray *list = NULL; GError *error_local = NULL; gchar **package_ids = NULL; gchar *name_debuginfo; guint i; gchar **split; PkError *error_code = NULL; /* get depends for them all, not adding dup's */ package_ids = pk_ptr_array_to_strv (packages_search); results = pk_client_get_depends (priv->client, pk_bitfield_value (PK_FILTER_ENUM_NONE), package_ids, TRUE, NULL, NULL, NULL, &error_local); if (results == NULL) { *error = g_error_new (1, 0, "failed to get_depends: %s", error_local->message); g_error_free (error_local); ret = FALSE; 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 get depends: %s, %s", pk_error_enum_to_string (pk_error_get_code (error_code)), pk_error_get_details (error_code)); ret = FALSE; goto out; } /* add dependent packages */ list = pk_results_get_package_array (results); for (i=0; i<list->len; i++) { item = g_ptr_array_index (list, i); split = pk_package_id_split (pk_package_get_id (item)); /* add -debuginfo */ name_debuginfo = pk_debuginfo_install_name_to_debuginfo (split[PK_PACKAGE_ID_NAME]); g_strfreev (split); /* resolve name */ g_debug ("resolving: %s", name_debuginfo); package_id = pk_debuginfo_install_resolve_name_to_id (priv, name_debuginfo, &error_local); if (package_id == NULL) { /* TRANSLATORS: we couldn't find the package name, non-fatal */ g_print (_("Failed to find the package %s, or already installed: %s"), name_debuginfo, error_local->message); g_print ("\n"); g_error_free (error_local); /* don't quit, this is non-fatal */ error = NULL; } /* add to array to install */ if (package_id != NULL && !g_str_has_suffix (package_id, "installed")) { g_debug ("going to try to install (for deps): %s", package_id); g_ptr_array_add (packages_results, g_strdup (package_id)); } g_free (package_id); g_free (name_debuginfo); } 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 (package_ids); return ret; }
/** * pk_plugin_transaction_finished_results: */ void pk_plugin_transaction_finished_results (PkPlugin *plugin, PkTransaction *transaction) { gchar **package_ids = NULL; gchar *package_id_tmp; GPtrArray *array = NULL; GPtrArray *list = NULL; guint i; PkInfoEnum info; PkPackage *item; PkResults *results; PkRoleEnum role; /* skip simulate actions */ if (pk_bitfield_contain (pk_transaction_get_transaction_flags (transaction), PK_TRANSACTION_FLAG_ENUM_SIMULATE)) { goto out; } /* skip only-download */ if (pk_bitfield_contain (pk_transaction_get_transaction_flags (transaction), PK_TRANSACTION_FLAG_ENUM_ONLY_DOWNLOAD)) { goto out; } /* load */ if (plugin->priv->db == NULL) pk_transaction_plugin_load_db (plugin, transaction); /* no database */ if (plugin->priv->db == NULL) goto out; /* check the role */ role = pk_transaction_get_role (transaction); if (role != PK_ROLE_ENUM_INSTALL_PACKAGES) goto out; /* connect to backend */ if (!pk_backend_is_implemented (plugin->backend, PK_ROLE_ENUM_GET_FILES)) { g_debug ("cannot get files"); goto out; } /* get results */ results = pk_transaction_get_results (transaction); array = pk_results_get_package_array (results); /* filter on INSTALLING | UPDATING */ list = g_ptr_array_new_with_free_func (g_free); for (i=0; i<array->len; i++) { item = g_ptr_array_index (array, i); info = pk_package_get_info (item); if (info == PK_INFO_ENUM_INSTALLING || info == PK_INFO_ENUM_UPDATING) { /* we convert the package_id data to be 'installed' */ package_id_tmp = pk_package_id_build (pk_package_get_name (item), pk_package_get_version (item), pk_package_get_arch (item), "installed"); g_ptr_array_add (list, package_id_tmp); } } /* process file lists on these packages */ g_debug ("processing %i packags for desktop files", list->len); if (list->len == 0) goto out; /* get all the files touched in the packages we just installed */ pk_backend_reset_job (plugin->backend, plugin->job); pk_backend_job_set_vfunc (plugin->job, PK_BACKEND_SIGNAL_FINISHED, (PkBackendJobVFunc) pk_plugin_finished_cb, plugin); pk_backend_job_set_vfunc (plugin->job, PK_BACKEND_SIGNAL_FILES, (PkBackendJobVFunc) pk_plugin_files_cb, plugin); pk_backend_job_set_status (plugin->job, PK_STATUS_ENUM_SCAN_APPLICATIONS); pk_backend_job_set_percentage (plugin->job, 101); package_ids = pk_ptr_array_to_strv (list); pk_backend_get_files (plugin->backend, plugin->job, package_ids); /* wait for finished */ g_main_loop_run (plugin->priv->loop); pk_backend_job_set_percentage (plugin->job, 100); out: if (array != NULL) g_ptr_array_unref (array); if (list != NULL) g_ptr_array_unref (list); g_strfreev (package_ids); }
/** * pk_offline_auth_set_results: * @results: A #PkResults * @error: A #GError or %NULL * * Saves the transaction results to a file. * * Return value: %TRUE for success, else %FALSE and @error set * * Since: 0.9.6 **/ gboolean pk_offline_auth_set_results (PkResults *results, GError **error) { guint i; PkPackage *package; g_autoptr(GError) error_local = NULL; g_autofree gchar *data = NULL; g_autoptr(GKeyFile) key_file = NULL; g_autoptr(PkError) pk_error = NULL; g_autoptr(GPtrArray) packages = NULL; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); key_file = g_key_file_new (); pk_error = pk_results_get_error_code (results); if (pk_error != NULL) { g_key_file_set_boolean (key_file, PK_OFFLINE_RESULTS_GROUP, "Success", FALSE); g_key_file_set_string (key_file, PK_OFFLINE_RESULTS_GROUP, "ErrorCode", pk_error_enum_to_string (pk_error_get_code (pk_error))); g_key_file_set_string (key_file, PK_OFFLINE_RESULTS_GROUP, "ErrorDetails", pk_error_get_details (pk_error)); } else { g_key_file_set_boolean (key_file, PK_OFFLINE_RESULTS_GROUP, "Success", TRUE); } /* save packages if any set */ packages = pk_results_get_package_array (results); if (packages->len > 0) { g_autoptr(GString) string = NULL; string = g_string_new (""); for (i = 0; i < packages->len; i++) { package = g_ptr_array_index (packages, i); switch (pk_package_get_info (package)) { case PK_INFO_ENUM_UPDATING: case PK_INFO_ENUM_INSTALLING: g_string_append_printf (string, "%s,", pk_package_get_id (package)); break; default: break; } } if (string->len > 0) g_string_set_size (string, string->len - 1); g_key_file_set_string (key_file, PK_OFFLINE_RESULTS_GROUP, "Packages", string->str); } /* write file */ data = g_key_file_to_data (key_file, NULL, &error_local); if (data == NULL) { g_set_error (error, PK_OFFLINE_ERROR, PK_OFFLINE_ERROR_FAILED, "failed to get keyfile data: %s", error_local->message); return FALSE; } if (!g_file_set_contents (PK_OFFLINE_RESULTS_FILENAME, data, -1, &error_local)) { g_set_error (error, PK_OFFLINE_ERROR, PK_OFFLINE_ERROR_FAILED, "failed to write file: %s", error_local->message); return FALSE; } return TRUE; }
/** * pk_offline_update_write_results: **/ static void pk_offline_update_write_results (PkResults *results) { gboolean ret; gchar *data = NULL; GError *error = NULL; GKeyFile *key_file; GPtrArray *packages; GString *string; guint i; PkError *pk_error; PkPackage *package; key_file = g_key_file_new (); pk_error = pk_results_get_error_code (results); if (pk_error != NULL) { g_key_file_set_boolean (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "Success", FALSE); g_key_file_set_string (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "ErrorCode", pk_error_enum_to_string (pk_error_get_code (pk_error))); g_key_file_set_string (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "ErrorDetails", pk_error_get_details (pk_error)); } else { g_key_file_set_boolean (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "Success", TRUE); } /* save packages if any set */ packages = pk_results_get_package_array (results); if (packages != NULL) { string = g_string_new (""); for (i = 0; i < packages->len; i++) { package = g_ptr_array_index (packages, i); switch (pk_package_get_info (package)) { case PK_INFO_ENUM_UPDATING: case PK_INFO_ENUM_INSTALLING: g_string_append_printf (string, "%s,", pk_package_get_id (package)); break; default: break; } } if (string->len > 0) g_string_set_size (string, string->len - 1); g_key_file_set_string (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "Packages", string->str); g_string_free (string, TRUE); } /* write file */ data = g_key_file_to_data (key_file, NULL, &error); if (data == NULL) { g_warning ("failed to get keyfile data: %s", error->message); g_error_free (error); goto out; } ret = g_file_set_contents (PK_OFFLINE_UPDATE_RESULTS_FILENAME, data, -1, &error); if (!ret) { g_warning ("failed to write file: %s", error->message); g_error_free (error); goto out; } out: g_key_file_free (key_file); g_free (data); }
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; }