static void backend_search_groups_thread(PkBackendJob *job, GVariant *params, gpointer user_data) { gchar **search; PkBitfield filters; g_variant_get(params, "(t^a&s)", &filters, &search); AptIntf *apt = static_cast<AptIntf*>(pk_backend_job_get_user_data(job)); if (!apt->init()) { g_debug("Failed to create apt cache"); apt->emitFinished(); return; } pk_backend_job_set_status(job, PK_STATUS_ENUM_QUERY); // It's faster to emmit the packages here rather than in the matching part PkgList output; output = apt->getPackagesFromGroup(search); apt->emitPackages(output, filters); pk_backend_job_set_percentage(job, 100); apt->emitFinished(); }
static void backend_get_packages_thread (PkBackendJob *job, GVariant *params, gpointer user_data) { PkBitfield filters; GList *list = NULL; sqlite3 *db = NULL; filters = pk_backend_get_uint (backend, "filters"); pk_backend_job_set_status (job, PK_STATUS_ENUM_QUERY); pk_backend_job_set_percentage (job, PK_BACKEND_PERCENTAGE_INVALID); db = db_open(); if ((pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED) && pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) || (!pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED) && !pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED))) { list = box_db_repos_packages_search_all (db, NULL, 0); } else if (pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED)) { list = box_db_repos_packages_search_installed (db, NULL, 0); } else if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) { list = box_db_repos_packages_search_available (db, NULL, 0); } add_packages_from_list (backend, list, FALSE); box_db_repos_package_list_free (list); db_close(db); pk_backend_finished (backend); }
static void pk_backend_resolve_thread(PkBackendJob *job, GVariant *params, gpointer user_data) { gchar **vals, **val; sqlite3_stmt *stmt; PkInfoEnum ret; PkBackendKatjaJobData *job_data = pk_backend_job_get_user_data(job); pk_backend_job_set_status(job, PK_STATUS_ENUM_QUERY); pk_backend_job_set_percentage(job, 0); g_variant_get(params, "(t^a&s)", NULL, &vals); if ((sqlite3_prepare_v2(job_data->db, "SELECT (p1.name || ';' || p1.ver || ';' || p1.arch || ';' || r.repo), p1.summary, " "p1.full_name FROM pkglist AS p1 NATURAL JOIN repos AS r " "WHERE p1.name LIKE @search AND p1.repo_order = " "(SELECT MIN(p2.repo_order) FROM pkglist AS p2 WHERE p2.name = p1.name GROUP BY p2.name)", -1, &stmt, NULL) == SQLITE_OK)) { /* Output packages matching each pattern */ for (val = vals; *val; val++) { sqlite3_bind_text(stmt, 1, *val, -1, SQLITE_TRANSIENT); while (sqlite3_step(stmt) == SQLITE_ROW) { ret = katja_pkg_is_installed((gchar *) sqlite3_column_text(stmt, 2)); if ((ret == PK_INFO_ENUM_INSTALLED) || (ret == PK_INFO_ENUM_UPDATING)) { pk_backend_job_package(job, PK_INFO_ENUM_INSTALLED, (gchar *) sqlite3_column_text(stmt, 0), (gchar *) sqlite3_column_text(stmt, 1)); } else if (ret == PK_INFO_ENUM_INSTALLING) { pk_backend_job_package(job, PK_INFO_ENUM_AVAILABLE, (gchar *) sqlite3_column_text(stmt, 0), (gchar *) sqlite3_column_text(stmt, 1)); } } sqlite3_clear_bindings(stmt); sqlite3_reset(stmt); } sqlite3_finalize(stmt); } else { pk_backend_job_error_code(job, PK_ERROR_ENUM_CANNOT_GET_FILELIST, "%s", sqlite3_errmsg(job_data->db)); } pk_backend_job_set_percentage(job, 100); pk_backend_job_finished(job); }
static void pk_backend_get_updates (PkBackend *backend, PkBackendJob *job, PkBitfield filters) { pk_backend_job_set_status (job, PK_STATUS_ENUM_QUERY); pk_backend_job_set_percentage (job, PK_BACKEND_PERCENTAGE_INVALID); pk_backend_job_thread_create (job, backend_get_updates_thread, NULL, NULL); }
/** * pk_backend_refresh_cache: */ static void pk_backend_refresh_cache (PkBackend *backend, PkBackendJob *job, gboolean force) { pk_backend_job_set_status (job, PK_STATUS_ENUM_REFRESH_CACHE); pk_backend_job_set_percentage (job, PK_BACKEND_PERCENTAGE_INVALID); pk_backend_job_thread_create (job, backend_refresh_cache_thread, NULL, NULL); }
static void pk_backend_update_system (PkBackend *backend, PkBackendJob *job, PkBitfield transaction_flags) { pk_backend_job_set_status (job, PK_STATUS_ENUM_UPDATE); pk_backend_job_set_percentage (job, PK_BACKEND_PERCENTAGE_INVALID); pk_backend_job_thread_create (job, backend_update_system_thread, NULL, NULL); }
static void backend_search_package_thread(PkBackendJob *job, GVariant *params, gpointer user_data) { gchar **values; gchar *search; PkBitfield filters; PkRoleEnum role; g_variant_get(params, "(t^a&s)", &filters, &values); search = g_strjoinv("|", values); AptIntf *apt = static_cast<AptIntf*>(pk_backend_job_get_user_data(job)); if (!apt->init()) { g_debug("Failed to create apt cache"); g_free(search); apt->emitFinished(); return; } if (_error->PendingError() == true) { g_free(search); apt->emitFinished(); return; } pk_backend_job_set_status(job, PK_STATUS_ENUM_QUERY); pk_backend_job_set_percentage(job, PK_BACKEND_PERCENTAGE_INVALID); pk_backend_job_set_allow_cancel(job, true); PkgList output; role = pk_backend_job_get_role(job); if (role == PK_ROLE_ENUM_SEARCH_DETAILS) { output = apt->searchPackageDetails(search); } else { output = apt->searchPackageName(search); } g_free(search); // It's faster to emmit the packages here than in the matching part apt->emitPackages(output, filters); pk_backend_job_set_percentage(job, 100); apt->emitFinished(); }
static void pk_backend_transaction_progress_cb (alpm_progress_t type, const gchar *target, gint percent, gsize targets, gsize current) { static gint recent = 101; gsize overall = percent + (current - 1) * 100; /* TODO: remove block if/when this is made consistent upstream */ if (type == ALPM_PROGRESS_CONFLICTS_START || type == ALPM_PROGRESS_DISKSPACE_START || type == ALPM_PROGRESS_INTEGRITY_START || type == ALPM_PROGRESS_LOAD_START || type == ALPM_PROGRESS_KEYRING_START) { if (current < targets) { ++current; overall += 100; } } if (current < 1 || targets < current) { g_warning ("TODO: CURRENT/TARGETS FAILED for %d", type); } g_return_if_fail (target != NULL); g_return_if_fail (0 <= percent && percent <= 100); g_return_if_fail (1 <= current && current <= targets); g_return_if_fail (backend != NULL); /* update transaction progress */ switch (type) { case ALPM_PROGRESS_ADD_START: case ALPM_PROGRESS_UPGRADE_START: case ALPM_PROGRESS_DOWNGRADE_START: case ALPM_PROGRESS_REINSTALL_START: case ALPM_PROGRESS_REMOVE_START: case ALPM_PROGRESS_CONFLICTS_START: case ALPM_PROGRESS_DISKSPACE_START: case ALPM_PROGRESS_INTEGRITY_START: case ALPM_PROGRESS_LOAD_START: case ALPM_PROGRESS_KEYRING_START: if (percent == recent) { break; } pk_backend_set_sub_percentage (backend, percent); pk_backend_job_set_percentage (job, overall / targets); recent = percent; g_debug ("%d%% of %s complete (%zu of %zu)", percent, target, current, targets); break; default: g_warning ("unknown progress type %d", type); break; } }
static void pk_backend_search_thread(PkBackendJob *job, GVariant *params, gpointer user_data) { gchar **vals, *search, *query; sqlite3_stmt *stmt; PkInfoEnum ret; PkBackendKatjaJobData *job_data = pk_backend_job_get_user_data(job); pk_backend_job_set_status(job, PK_STATUS_ENUM_QUERY); pk_backend_job_set_percentage(job, 0); g_variant_get(params, "(t^a&s)", NULL, &vals); search = g_strjoinv("%", vals); query = sqlite3_mprintf("SELECT (p1.name || ';' || p1.ver || ';' || p1.arch || ';' || r.repo), p1.summary, " "p1.full_name FROM pkglist AS p1 NATURAL JOIN repos AS r " "WHERE p1.%s LIKE '%%%q%%' AND p1.ext NOT LIKE 'obsolete' AND p1.repo_order = " "(SELECT MIN(p2.repo_order) FROM pkglist AS p2 WHERE p2.name = p1.name GROUP BY p2.name)", (gchar *) user_data, search); if ((sqlite3_prepare_v2(job_data->db, query, -1, &stmt, NULL) == SQLITE_OK)) { /* Now we're ready to output all packages */ while (sqlite3_step(stmt) == SQLITE_ROW) { ret = katja_pkg_is_installed((gchar *) sqlite3_column_text(stmt, 2)); if ((ret == PK_INFO_ENUM_INSTALLED) || (ret == PK_INFO_ENUM_UPDATING)) { pk_backend_job_package(job, PK_INFO_ENUM_INSTALLED, (gchar *) sqlite3_column_text(stmt, 0), (gchar *) sqlite3_column_text(stmt, 1)); } else if (ret == PK_INFO_ENUM_INSTALLING) { pk_backend_job_package(job, PK_INFO_ENUM_AVAILABLE, (gchar *) sqlite3_column_text(stmt, 0), (gchar *) sqlite3_column_text(stmt, 1)); } } sqlite3_finalize(stmt); } else { pk_backend_job_error_code(job, PK_ERROR_ENUM_CANNOT_GET_FILELIST, "%s", sqlite3_errmsg(job_data->db)); } sqlite3_free(query); g_free(search); pk_backend_job_set_percentage(job, 100); pk_backend_job_finished(job); }
void OpPackageKitProgress::Update() { if (CheckChange() == false) { // No change has happened skip return; } // Set the new percent pk_backend_job_set_percentage(m_job, static_cast<unsigned int>(Percent)); }
static void pk_backend_install_packages (PkBackend *backend, PkBackendJob *job, PkBitfield transaction_flags, gchar **package_ids) { pk_backend_job_set_percentage (job, PK_BACKEND_PERCENTAGE_INVALID); pk_backend_job_set_status (job, PK_STATUS_ENUM_INSTALL); pk_backend_set_strv (backend, "pkids", package_ids); pk_backend_job_thread_create (job, backend_install_packages_thread, NULL, NULL); }
static void pk_backend_remove_packages_thread(PkBackendJob *job, GVariant *params, gpointer user_data) { gchar **pkg_tokens, **pkg_ids, *cmd_line; guint i; gdouble percent_step; gboolean allow_deps, autoremove; GError *err = NULL; PkBitfield transaction_flags = 0; g_variant_get(params, "(t^a&sbb)", &transaction_flags, &pkg_ids, &allow_deps, &autoremove); if (pk_bitfield_contain(transaction_flags, PK_TRANSACTION_FLAG_ENUM_SIMULATE)) { pk_backend_job_set_status(job, PK_STATUS_ENUM_DEP_RESOLVE); } else { pk_backend_job_set_status(job, PK_STATUS_ENUM_REMOVE); /* Add percent_step percents per removed package */ percent_step = 100.0 / g_strv_length(pkg_ids); for (i = 0; pkg_ids[i]; i++) { pk_backend_job_set_percentage(job, percent_step * i); pkg_tokens = pk_package_id_split(pkg_ids[i]); cmd_line = g_strconcat("/sbin/removepkg ", pkg_tokens[PK_PACKAGE_ID_NAME], NULL); /* Pkgtools return always 0 */ g_spawn_command_line_sync(cmd_line, NULL, NULL, NULL, &err); g_free(cmd_line); g_strfreev(pkg_tokens); if (err) { pk_backend_job_error_code(job, PK_ERROR_ENUM_PACKAGE_FAILED_TO_REMOVE, "%s", err->message); g_error_free(err); goto out; } pk_backend_job_set_percentage(job, 100); } } out: pk_backend_job_finished(job); }
/** * pk_backend_search_names_thread: */ static void pk_backend_search_names_thread (PkBackendJob *job, GVariant *params, gpointer user_data) { GTimer *timer; guint percentage; PkBitfield filters; gchar *filters_text; gchar **search; g_variant_get (params, "(t^a&s)", &filters, &search); filters_text = pk_filter_bitfield_to_string (filters); g_debug ("started task (%p) search=%s filters=%s", job, search[0], filters_text); g_free (filters_text); pk_backend_job_set_status (job, PK_STATUS_ENUM_QUERY); timer = g_timer_new (); percentage = 0; do { /* now is a good time to see if we should cancel the thread */ if (is_cancelled) { pk_backend_job_error_code (job, PK_ERROR_ENUM_TRANSACTION_CANCELLED, "The thread was stopped successfully"); pk_backend_job_finished (job); return; } pk_backend_job_set_percentage (job, percentage); percentage += 10; g_usleep (1000*100); } while (percentage < 100); g_timer_destroy (timer); pk_backend_job_set_percentage (job, 100); g_debug ("exited task (%p)", job); pk_backend_job_package (job, PK_INFO_ENUM_INSTALLED, "glib2;2.14.0;i386;fedora", "The GLib library"); pk_backend_job_package (job, PK_INFO_ENUM_INSTALLED, "gtk2;gtk2-2.11.6-6.fc8;i386;fedora", "GTK+ Libraries for GIMP"); pk_backend_job_finished (job); }
static void pk_backend_update_packages (PkBackend *backend, PkBackendJob *job, PkBitfield transaction_flags, gchar **package_ids) { gint i; pk_backend_job_set_status (job, PK_STATUS_ENUM_UPDATE); pk_backend_job_set_percentage (job, PK_BACKEND_PERCENTAGE_INVALID); for (i = 0; package_ids[i]; i++) { pk_backend_set_string (backend, "pkgid", package_ids[i]); pk_backend_job_thread_create (job, backend_update_package_thread, NULL, NULL); } }
static void pk_backend_search_group (PkBackend *backend, PkBitfield filters, gchar **search) { SearchParams *params; pk_backend_job_set_status (job, PK_STATUS_ENUM_QUERY); pk_backend_job_set_percentage (job, PK_BACKEND_PERCENTAGE_INVALID); params = g_new0 (SearchParams, 1); params->filters = filters; params->search_type = SEARCH_TAG; params->needle = g_strdup_printf ("group::%s", search[0]); params->backend = backend; pk_backend_set_pointer (backend, "search-params", params); pk_backend_job_thread_create (job, backend_search_thread, NULL, NULL); }
/** * pk_backend_search_description: */ static void pk_backend_search_description (PkBackend *backend, PkBitfield filters, gchar **search) { SearchParams *params; pk_backend_job_set_status (job, PK_STATUS_ENUM_QUERY); pk_backend_job_set_percentage (job, PK_BACKEND_PERCENTAGE_INVALID); params = g_new0 (SearchParams, 1); params->filters = filters; params->search_type = SEARCH_DESCRIPTION; params->needle = g_utf8_strdown (search[0], -1); params->backend = backend; pk_backend_set_pointer (backend, "search-params", params); pk_backend_job_thread_create (job, backend_search_thread, NULL, NULL); }
static void pk_backend_remove_packages (PkBackend *backend, PkBackendJob *job, gchar **package_ids, gboolean allow_deps, gboolean autoremove) { gpointer *params; pk_backend_job_set_status (job, PK_STATUS_ENUM_REMOVE); pk_backend_job_set_percentage (job, PK_BACKEND_PERCENTAGE_INVALID); /* params is a small array we can pack our thread parameters into */ params = g_new0 (gpointer, 2); params[0] = g_strdupv (package_ids); params[1] = GINT_TO_POINTER (allow_deps); params[2] = GINT_TO_POINTER (autoremove); pk_backend_set_pointer (backend, "remove-params", params); pk_backend_job_thread_create (job, backend_remove_packages_thread, NULL, NULL); }
static void pk_opkg_progress_cb (const opkg_progress_data_t *pdata, void *data) { PkBackend *backend = (PkBackend*) data; if (!backend) return; pk_backend_job_set_percentage (job, pdata->percentage); if (pdata->pkg) { gchar *uid; pkg_t *pkg = pdata->pkg; gint status = PK_INFO_ENUM_UNKNOWN; uid = g_strdup_printf ("%s;%s;%s;", pkg->name, pkg->version, pkg->architecture); if (pdata->action == OPKG_DOWNLOAD) status = PK_INFO_ENUM_DOWNLOADING; else if (pdata->action == OPKG_INSTALL) status = PK_INFO_ENUM_INSTALLING; else if (pdata->action == OPKG_REMOVE) status = PK_INFO_ENUM_REMOVING; pk_backend_job_package (job, status, uid, pkg->description); g_free (uid); } switch (pdata->action) { case OPKG_DOWNLOAD: pk_backend_job_set_status (job, PK_STATUS_ENUM_DOWNLOAD); break; case OPKG_INSTALL: pk_backend_job_set_status (job, PK_STATUS_ENUM_INSTALL); break; case OPKG_REMOVE: pk_backend_job_set_status (job, PK_STATUS_ENUM_REMOVE); break; } }
/** * pk_plugin_transaction_finished_end: */ void pk_plugin_transaction_finished_end (PkPlugin *plugin, PkTransaction *transaction) { AsBuilder *builder = NULL; 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; } /* check the role */ role = pk_transaction_get_role (transaction); if (role != PK_ROLE_ENUM_REFRESH_CACHE) goto out; /* use a local backend instance */ pk_backend_reset_job (plugin->backend, plugin->job); pk_backend_job_set_status (plugin->job, PK_STATUS_ENUM_SCAN_APPLICATIONS); /* refresh the AppStream cache using the database builder */ builder = as_builder_new (); as_builder_initialize (builder); as_builder_refresh_cache (builder, FALSE, NULL); pk_backend_job_set_percentage (plugin->job, 100); pk_backend_job_set_status (plugin->job, PK_STATUS_ENUM_FINISHED); out: if (builder != NULL) g_object_unref (builder); }
static void pk_backend_transaction_dlcb (const gchar *basename, off_t complete, off_t total) { guint percentage = 100, sub_percentage = 100; g_return_if_fail (basename != NULL); g_return_if_fail (complete <= total); g_return_if_fail (backend != NULL); if (total > 0) { sub_percentage = complete * 100 / total; } if (dtotal > 0) { percentage = (dcomplete + complete) * 100 / dtotal; } else if (dtotal < 0) { /* database files */ percentage = (dcomplete * 100 + sub_percentage) / -dtotal; if (complete == total) { complete = total = 1; } else { complete = total + 1; } } if (complete == 0) { g_debug ("downloading file %s", basename); pk_backend_job_set_status (job, PK_STATUS_ENUM_DOWNLOAD); pk_backend_transaction_download_start (backend, basename); } else if (complete == total) { dcomplete += complete; } pk_backend_set_sub_percentage (backend, sub_percentage); pk_backend_job_set_percentage (job, percentage); }
/** * pk_plugin_transaction_finished_end: */ void pk_plugin_transaction_finished_end (PkPlugin *plugin, PkTransaction *transaction) { gchar *error_msg = NULL; gchar *path; gchar *statement; gfloat step; gint rc; GPtrArray *array = NULL; guint i; 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_REFRESH_CACHE) goto out; /* connect to backend */ if (!pk_backend_is_implemented (plugin->backend, PK_ROLE_ENUM_SEARCH_FILE)) { g_debug ("cannot search files"); goto out; } /* use a local backend instance */ 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_PACKAGE, (PkBackendJobVFunc) pk_plugin_package_cb, plugin); pk_backend_job_set_status (plugin->job, PK_STATUS_ENUM_SCAN_APPLICATIONS); /* reset hash */ g_hash_table_remove_all (plugin->priv->hash); pk_backend_job_set_percentage (plugin->job, 101); /* first go through the existing data, and look for * modifications and removals */ statement = g_strdup ("SELECT filename, md5 FROM cache"); rc = sqlite3_exec (plugin->priv->db, statement, pk_plugin_sqlite_cache_rescan_cb, plugin, &error_msg); g_free (statement); if (rc != SQLITE_OK) { g_warning ("SQL error: %s\n", error_msg); sqlite3_free (error_msg); goto out; } array = g_ptr_array_new_with_free_func (g_free); pk_plugin_get_desktop_files (plugin, PK_DESKTOP_DEFAULT_APPLICATION_DIR, array); if (array->len) { step = 100.0f / array->len; pk_backend_job_set_status (plugin->job, PK_STATUS_ENUM_GENERATE_PACKAGE_LIST); /* process files in an array */ for (i=0; i<array->len; i++) { pk_backend_job_set_percentage (plugin->job, i * step); path = g_ptr_array_index (array, i); pk_plugin_sqlite_add_filename (plugin, path, NULL); } } pk_backend_job_set_percentage (plugin->job, 100); pk_backend_job_set_status (plugin->job, PK_STATUS_ENUM_FINISHED); out: if (array != NULL) g_ptr_array_unref (array); }
/** * pk_backend_spawn_parse_stdout: **/ static gboolean pk_backend_spawn_parse_stdout (PkBackendSpawn *backend_spawn, PkBackendJob *job, const gchar *line, GError **error) { gchar **sections; guint size; gchar *command; gchar *text; gboolean ret = TRUE; guint64 speed; guint64 download_size_remaining; PkInfoEnum info; PkRestartEnum restart; PkGroupEnum group; gulong package_size; gint percentage; PkErrorEnum error_enum; PkStatusEnum status_enum; PkMessageEnum message_enum; PkRestartEnum restart_enum; PkSigTypeEnum sig_type; PkUpdateStateEnum update_state_enum; PkMediaTypeEnum media_type_enum; PkDistroUpgradeEnum distro_upgrade_enum; PkBackendSpawnPrivate *priv = backend_spawn->priv; g_return_val_if_fail (PK_IS_BACKEND_SPAWN (backend_spawn), FALSE); /* check if output line */ if (line == NULL) return FALSE; /* split by tab */ sections = g_strsplit (line, "\t", 0); command = sections[0]; /* get size */ size = g_strv_length (sections); if (g_strcmp0 (command, "package") == 0) { if (size != 4) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } if (pk_package_id_check (sections[2]) == FALSE) { g_set_error_literal (error, 1, 0, "invalid package_id"); ret = FALSE; goto out; } info = pk_info_enum_from_string (sections[1]); if (info == PK_INFO_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Info enum not recognised, and hence ignored: '%s'", sections[1]); ret = FALSE; goto out; } g_strdelimit (sections[3], PK_UNSAFE_DELIMITERS, ' '); ret = g_utf8_validate (sections[3], -1, NULL); if (!ret) { g_set_error (error, 1, 0, "text '%s' was not valid UTF8!", sections[3]); ret = FALSE; goto out; } pk_backend_job_package (job, info, sections[2], sections[3]); } else if (g_strcmp0 (command, "details") == 0) { if (size != 7) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } group = pk_group_enum_from_string (sections[3]); /* ITS4: ignore, checked for overflow */ package_size = atol (sections[6]); if (package_size > 1073741824) { g_set_error_literal (error, 1, 0, "package size cannot be larger than one Gb"); ret = FALSE; goto out; } g_strdelimit (sections[4], PK_UNSAFE_DELIMITERS, ' '); ret = g_utf8_validate (sections[4], -1, NULL); if (!ret) { g_set_error (error, 1, 0, "text '%s' was not valid UTF8!", sections[4]); ret = FALSE; goto out; } text = g_strdup (sections[4]); /* convert ; to \n as we can't emit them on stdout */ g_strdelimit (text, ";", '\n'); pk_backend_job_details (job, sections[1], sections[2], group, text, sections[5], package_size); g_free (text); } else if (g_strcmp0 (command, "finished") == 0) { if (size != 1) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } pk_backend_job_finished (job); priv->is_busy = FALSE; /* from this point on, we can start the kill timer */ pk_backend_spawn_start_kill_timer (backend_spawn); } else if (g_strcmp0 (command, "files") == 0) { gchar **tmp; if (size != 3) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } tmp = g_strsplit (sections[2], ";", -1); pk_backend_job_files (job, sections[1], tmp); g_strfreev (tmp); } else if (g_strcmp0 (command, "repo-detail") == 0) { if (size != 4) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } g_strdelimit (sections[2], PK_UNSAFE_DELIMITERS, ' '); ret = g_utf8_validate (sections[2], -1, NULL); if (!ret) { g_set_error (error, 1, 0, "text '%s' was not valid UTF8!", sections[2]); ret = FALSE; goto out; } if (g_strcmp0 (sections[3], "true") == 0) { pk_backend_job_repo_detail (job, sections[1], sections[2], TRUE); } else if (g_strcmp0 (sections[3], "false") == 0) { pk_backend_job_repo_detail (job, sections[1], sections[2], FALSE); } else { g_set_error (error, 1, 0, "invalid qualifier '%s'", sections[3]); ret = FALSE; goto out; } } else if (g_strcmp0 (command, "updatedetail") == 0) { gchar **updates; gchar **obsoletes; gchar **vendor_urls; gchar **bugzilla_urls; gchar **cve_urls; if (size != 13) { g_set_error (error, 1, 0, "invalid command '%s', size %i", command, size); ret = FALSE; goto out; } restart = pk_restart_enum_from_string (sections[7]); if (restart == PK_RESTART_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Restart enum not recognised, and hence ignored: '%s'", sections[7]); ret = FALSE; goto out; } g_strdelimit (sections[12], PK_UNSAFE_DELIMITERS, ' '); ret = g_utf8_validate (sections[12], -1, NULL); if (!ret) { g_set_error (error, 1, 0, "text '%s' was not valid UTF8!", sections[12]); ret = FALSE; goto out; } update_state_enum = pk_update_state_enum_from_string (sections[10]); /* convert ; to \n as we can't emit them on stdout */ g_strdelimit (sections[8], ";", '\n'); g_strdelimit (sections[9], ";", '\n'); updates = g_strsplit (sections[2], "&", -1); obsoletes = g_strsplit (sections[3], "&", -1); vendor_urls = g_strsplit (sections[4], ";", -1); bugzilla_urls = g_strsplit (sections[5], ";", -1); cve_urls = g_strsplit (sections[6], ";", -1); pk_backend_job_update_detail (job, sections[1], updates, obsoletes, vendor_urls, bugzilla_urls, cve_urls, restart, sections[8], sections[9], update_state_enum, sections[11], sections[12]); g_strfreev (updates); g_strfreev (obsoletes); g_strfreev (vendor_urls); g_strfreev (bugzilla_urls); g_strfreev (cve_urls); } else if (g_strcmp0 (command, "percentage") == 0) { if (size != 2) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } ret = pk_strtoint (sections[1], &percentage); if (!ret) { g_set_error (error, 1, 0, "invalid percentage value %s", sections[1]); ret = FALSE; } else if (percentage < 0 || percentage > 100) { g_set_error (error, 1, 0, "invalid percentage value %i", percentage); ret = FALSE; } else { pk_backend_job_set_percentage (job, percentage); } } else if (g_strcmp0 (command, "item-progress") == 0) { if (size != 4) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } if (!pk_package_id_check (sections[1])) { g_set_error (error, 1, 0, "invalid package_id"); ret = FALSE; goto out; } status_enum = pk_status_enum_from_string (sections[2]); if (status_enum == PK_STATUS_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Status enum not recognised, and hence ignored: '%s'", sections[2]); ret = FALSE; goto out; } ret = pk_strtoint (sections[3], &percentage); if (!ret) { g_set_error (error, 1, 0, "invalid item-progress value %s", sections[3]); ret = FALSE; goto out; } if (percentage < 0 || percentage > 100) { g_set_error (error, 1, 0, "invalid item-progress value %i", percentage); ret = FALSE; goto out; } pk_backend_job_set_item_progress (job, sections[1], status_enum, percentage); } else if (g_strcmp0 (command, "error") == 0) { if (size != 3) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } error_enum = pk_error_enum_from_string (sections[1]); if (error_enum == PK_ERROR_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Error enum not recognised, and hence ignored: '%s'", sections[1]); ret = FALSE; goto out; } /* convert back all the ;'s to newlines */ text = g_strdup (sections[2]); /* convert ; to \n as we can't emit them on stdout */ g_strdelimit (text, ";", '\n'); /* convert % else we try to format them */ g_strdelimit (text, "%", '$'); pk_backend_job_error_code (job, error_enum, "%s", text); g_free (text); } else if (g_strcmp0 (command, "requirerestart") == 0) { if (size != 3) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } restart_enum = pk_restart_enum_from_string (sections[1]); if (restart_enum == PK_RESTART_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Restart enum not recognised, and hence ignored: '%s'", sections[1]); ret = FALSE; goto out; } if (!pk_package_id_check (sections[2])) { g_set_error (error, 1, 0, "invalid package_id"); ret = FALSE; goto out; } pk_backend_job_require_restart (job, restart_enum, sections[2]); } else if (g_strcmp0 (command, "message") == 0) { if (size != 3) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } G_GNUC_BEGIN_IGNORE_DEPRECATIONS message_enum = pk_message_enum_from_string (sections[1]); G_GNUC_END_IGNORE_DEPRECATIONS if (message_enum == PK_MESSAGE_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Message enum not recognised, and hence ignored: '%s'", sections[1]); ret = FALSE; goto out; } text = g_strdup (sections[2]); /* convert ; to \n as we can't emit them on stdout */ g_strdelimit (text, ";", '\n'); G_GNUC_BEGIN_IGNORE_DEPRECATIONS pk_backend_job_message (job, message_enum, "%s", text); G_GNUC_END_IGNORE_DEPRECATIONS g_free (text); } else if (g_strcmp0 (command, "status") == 0) {
static void pk_backend_get_details (PkBackend *backend, PkBackendJob *job, gchar **package_ids) { pk_backend_job_set_percentage (job, PK_BACKEND_PERCENTAGE_INVALID); pk_backend_job_thread_create (job, backend_get_details_thread, NULL, NULL); }
void OpPackageKitProgress::Done() { pk_backend_job_set_percentage(m_job, 100); }
static void pk_backend_install_packages_thread(PkBackendJob *job, GVariant *params, gpointer user_data) { gchar *dest_dir_name, **pkg_tokens, **pkg_ids; guint i; gdouble percent_step; GSList *repo, *install_list = NULL, *l; sqlite3_stmt *pkglist_stmt = NULL, *collection_stmt = NULL; PkBitfield transaction_flags = 0; PkInfoEnum ret; PkBackendKatjaJobData *job_data = pk_backend_job_get_user_data(job); g_variant_get(params, "(t^a&s)", &transaction_flags, &pkg_ids); pk_backend_job_set_status(job, PK_STATUS_ENUM_DEP_RESOLVE); if ((sqlite3_prepare_v2(job_data->db, "SELECT summary, cat FROM pkglist NATURAL JOIN repos " "WHERE name LIKE @name AND ver LIKE @ver AND arch LIKE @arch AND repo LIKE @repo", -1, &pkglist_stmt, NULL) != SQLITE_OK) || (sqlite3_prepare_v2(job_data->db, "SELECT (c.collection_pkg || ';' || p.ver || ';' || p.arch || ';' || r.repo), p.summary, " "p.full_name, p.ext FROM collections AS c " "JOIN pkglist AS p ON c.collection_pkg = p.name " "JOIN repos AS r ON p.repo_order = r.repo_order " "WHERE c.name LIKE @name AND r.repo LIKE @repo", -1, &collection_stmt, NULL) != SQLITE_OK)) { pk_backend_job_error_code(job, PK_ERROR_ENUM_CANNOT_GET_FILELIST, "%s", sqlite3_errmsg(job_data->db)); goto out; } for (i = 0; pkg_ids[i]; i++) { pkg_tokens = pk_package_id_split(pkg_ids[i]); sqlite3_bind_text(pkglist_stmt, 1, pkg_tokens[PK_PACKAGE_ID_NAME], -1, SQLITE_TRANSIENT); sqlite3_bind_text(pkglist_stmt, 2, pkg_tokens[PK_PACKAGE_ID_VERSION], -1, SQLITE_TRANSIENT); sqlite3_bind_text(pkglist_stmt, 3, pkg_tokens[PK_PACKAGE_ID_ARCH], -1, SQLITE_TRANSIENT); sqlite3_bind_text(pkglist_stmt, 4, pkg_tokens[PK_PACKAGE_ID_DATA], -1, SQLITE_TRANSIENT); if (sqlite3_step(pkglist_stmt) == SQLITE_ROW) { /* If it isn't a collection */ if (g_strcmp0((gchar *) sqlite3_column_text(pkglist_stmt, 1), "collections")) { if (pk_bitfield_contain(transaction_flags, PK_TRANSACTION_FLAG_ENUM_SIMULATE)) { pk_backend_job_package(job, PK_INFO_ENUM_INSTALLING, pkg_ids[i], (gchar *) sqlite3_column_text(pkglist_stmt, 0)); } else { install_list = g_slist_append(install_list, g_strdup(pkg_ids[i])); } } else { sqlite3_bind_text(collection_stmt, 1, pkg_tokens[PK_PACKAGE_ID_NAME], -1, SQLITE_TRANSIENT); sqlite3_bind_text(collection_stmt, 2, pkg_tokens[PK_PACKAGE_ID_DATA], -1, SQLITE_TRANSIENT); while (sqlite3_step(collection_stmt) == SQLITE_ROW) { ret = katja_pkg_is_installed((gchar *) sqlite3_column_text(collection_stmt, 2)); if ((ret == PK_INFO_ENUM_INSTALLING) || (ret == PK_INFO_ENUM_UPDATING)) { if ((pk_bitfield_contain(transaction_flags, PK_TRANSACTION_FLAG_ENUM_SIMULATE)) && !g_strcmp0((gchar *) sqlite3_column_text(collection_stmt, 3), "obsolete")) { /* TODO: Don't just skip obsolete packages but remove them */ } else if (pk_bitfield_contain(transaction_flags, PK_TRANSACTION_FLAG_ENUM_SIMULATE)) { pk_backend_job_package(job, ret, (gchar *) sqlite3_column_text(collection_stmt, 0), (gchar *) sqlite3_column_text(collection_stmt, 1)); } else { install_list = g_slist_append(install_list, g_strdup((gchar *) sqlite3_column_text(collection_stmt, 0))); } } } sqlite3_clear_bindings(collection_stmt); sqlite3_reset(collection_stmt); } } sqlite3_clear_bindings(pkglist_stmt); sqlite3_reset(pkglist_stmt); g_strfreev(pkg_tokens); } if (install_list && !pk_bitfield_contain(transaction_flags, PK_TRANSACTION_FLAG_ENUM_SIMULATE)) { /* / 2 means total percentage for installing and for downloading */ percent_step = 100.0 / g_slist_length(install_list) / 2; /* Download the packages */ pk_backend_job_set_status(job, PK_STATUS_ENUM_DOWNLOAD); dest_dir_name = g_build_filename(LOCALSTATEDIR, "cache", "PackageKit", "downloads", NULL); for (l = install_list, i = 0; l; l = g_slist_next(l), i++) { pk_backend_job_set_percentage(job, percent_step * i); pkg_tokens = pk_package_id_split(l->data); repo = g_slist_find_custom(repos, pkg_tokens[PK_PACKAGE_ID_DATA], katja_cmp_repo); if (repo) katja_pkgtools_download(KATJA_PKGTOOLS(repo->data), job, dest_dir_name, pkg_tokens[PK_PACKAGE_ID_NAME]); g_strfreev(pkg_tokens); } g_free(dest_dir_name); /* Install the packages */ pk_backend_job_set_status(job, PK_STATUS_ENUM_INSTALL); for (l = install_list; l; l = g_slist_next(l), i++) { pk_backend_job_set_percentage(job, percent_step * i); pkg_tokens = pk_package_id_split(l->data); repo = g_slist_find_custom(repos, pkg_tokens[PK_PACKAGE_ID_DATA], katja_cmp_repo); if (repo) katja_pkgtools_install(KATJA_PKGTOOLS(repo->data), job, pkg_tokens[PK_PACKAGE_ID_NAME]); g_strfreev(pkg_tokens); } } g_slist_free_full(install_list, g_free); out: sqlite3_finalize(pkglist_stmt); sqlite3_finalize(collection_stmt); pk_backend_job_finished (job); }
/** * 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); }
static gboolean pk_backend_spawn_parse_stdout (PkBackendSpawn *backend_spawn, PkBackendJob *job, const gchar *line, GError **error) { guint size; gchar *command; gchar *text; guint64 speed; guint64 download_size_remaining; PkInfoEnum info; PkRestartEnum restart; PkGroupEnum group; gulong package_size; gint percentage; PkErrorEnum error_enum; PkStatusEnum status_enum; PkRestartEnum restart_enum; PkSigTypeEnum sig_type; PkUpdateStateEnum update_state_enum; PkMediaTypeEnum media_type_enum; PkDistroUpgradeEnum distro_upgrade_enum; PkBackendSpawnPrivate *priv = backend_spawn->priv; g_auto(GStrv) sections = NULL; g_return_val_if_fail (PK_IS_BACKEND_SPAWN (backend_spawn), FALSE); /* check if output line */ if (line == NULL) return FALSE; /* split by tab */ sections = g_strsplit (line, "\t", 0); command = sections[0]; /* get size */ size = g_strv_length (sections); if (g_strcmp0 (command, "package") == 0) { if (size != 4) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } if (pk_package_id_check (sections[2]) == FALSE) { g_set_error_literal (error, 1, 0, "invalid package_id"); return FALSE; } info = pk_info_enum_from_string (sections[1]); if (info == PK_INFO_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Info enum not recognised, and hence ignored: '%s'", sections[1]); return FALSE; } g_strdelimit (sections[3], PK_UNSAFE_DELIMITERS, ' '); if (!g_utf8_validate (sections[3], -1, NULL)) { g_set_error (error, 1, 0, "text '%s' was not valid UTF8!", sections[3]); return FALSE; } pk_backend_job_package (job, info, sections[2], sections[3]); } else if (g_strcmp0 (command, "details") == 0) { if (size != 8) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } group = pk_group_enum_from_string (sections[4]); /* ITS4: ignore, checked for overflow */ package_size = atol (sections[7]); if (package_size > 1073741824) { g_set_error_literal (error, 1, 0, "package size cannot be that large"); return FALSE; } g_strdelimit (sections[5], PK_UNSAFE_DELIMITERS, ' '); if (!g_utf8_validate (sections[4], -1, NULL)) { g_set_error (error, 1, 0, "text '%s' was not valid UTF8!", sections[5]); return FALSE; } text = g_strdup (sections[5]); /* convert ; to \n as we can't emit them on stdout */ g_strdelimit (text, ";", '\n'); pk_backend_job_details (job, sections[1], sections[2], sections[3], group, text, sections[6], package_size); g_free (text); } else if (g_strcmp0 (command, "finished") == 0) { if (size != 1) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } pk_backend_job_finished (job); priv->is_busy = FALSE; /* from this point on, we can start the kill timer */ pk_backend_spawn_start_kill_timer (backend_spawn); } else if (g_strcmp0 (command, "files") == 0) { g_auto(GStrv) tmp = NULL; if (size != 3) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } tmp = g_strsplit (sections[2], ";", -1); pk_backend_job_files (job, sections[1], tmp); } else if (g_strcmp0 (command, "repo-detail") == 0) { if (size != 4) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } g_strdelimit (sections[2], PK_UNSAFE_DELIMITERS, ' '); if (!g_utf8_validate (sections[2], -1, NULL)) { g_set_error (error, 1, 0, "text '%s' was not valid UTF8!", sections[2]); return FALSE; } if (g_strcmp0 (sections[3], "true") == 0) { pk_backend_job_repo_detail (job, sections[1], sections[2], TRUE); } else if (g_strcmp0 (sections[3], "false") == 0) { pk_backend_job_repo_detail (job, sections[1], sections[2], FALSE); } else { g_set_error (error, 1, 0, "invalid qualifier '%s'", sections[3]); return FALSE; } } else if (g_strcmp0 (command, "updatedetail") == 0) { g_auto(GStrv) updates = NULL; g_auto(GStrv) obsoletes = NULL; g_auto(GStrv) vendor_urls = NULL; g_auto(GStrv) bugzilla_urls = NULL; g_auto(GStrv) cve_urls = NULL; if (size != 13) { g_set_error (error, 1, 0, "invalid command '%s', size %i", command, size); return FALSE; } restart = pk_restart_enum_from_string (sections[7]); if (restart == PK_RESTART_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Restart enum not recognised, and hence ignored: '%s'", sections[7]); return FALSE; } g_strdelimit (sections[12], PK_UNSAFE_DELIMITERS, ' '); if (!g_utf8_validate (sections[12], -1, NULL)) { g_set_error (error, 1, 0, "text '%s' was not valid UTF8!", sections[12]); return FALSE; } update_state_enum = pk_update_state_enum_from_string (sections[10]); /* convert ; to \n as we can't emit them on stdout */ g_strdelimit (sections[8], ";", '\n'); g_strdelimit (sections[9], ";", '\n'); updates = g_strsplit (sections[2], "&", -1); obsoletes = g_strsplit (sections[3], "&", -1); vendor_urls = g_strsplit (sections[4], ";", -1); bugzilla_urls = g_strsplit (sections[5], ";", -1); cve_urls = g_strsplit (sections[6], ";", -1); pk_backend_job_update_detail (job, sections[1], updates, obsoletes, vendor_urls, bugzilla_urls, cve_urls, restart, sections[8], sections[9], update_state_enum, sections[11], sections[12]); } else if (g_strcmp0 (command, "percentage") == 0) { if (size != 2) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } if (!pk_strtoint (sections[1], &percentage)) { g_set_error (error, 1, 0, "invalid percentage value %s", sections[1]); return FALSE; } else if (percentage < 0 || percentage > 100) { g_set_error (error, 1, 0, "invalid percentage value %i", percentage); return FALSE; } else { pk_backend_job_set_percentage (job, percentage); } } else if (g_strcmp0 (command, "item-progress") == 0) { if (size != 4) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } if (!pk_package_id_check (sections[1])) { g_set_error (error, 1, 0, "invalid package_id"); return FALSE; } status_enum = pk_status_enum_from_string (sections[2]); if (status_enum == PK_STATUS_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Status enum not recognised, and hence ignored: '%s'", sections[2]); return FALSE; } if (!pk_strtoint (sections[3], &percentage)) { g_set_error (error, 1, 0, "invalid item-progress value %s", sections[3]); return FALSE; } if (percentage < 0 || percentage > 100) { g_set_error (error, 1, 0, "invalid item-progress value %i", percentage); return FALSE; } pk_backend_job_set_item_progress (job, sections[1], status_enum, percentage); } else if (g_strcmp0 (command, "error") == 0) { if (size != 3) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } error_enum = pk_error_enum_from_string (sections[1]); if (error_enum == PK_ERROR_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Error enum not recognised, and hence ignored: '%s'", sections[1]); return FALSE; } /* convert back all the ;'s to newlines */ text = g_strdup (sections[2]); /* convert ; to \n as we can't emit them on stdout */ g_strdelimit (text, ";", '\n'); /* convert % else we try to format them */ g_strdelimit (text, "%", '$'); pk_backend_job_error_code (job, error_enum, "%s", text); g_free (text); } else if (g_strcmp0 (command, "requirerestart") == 0) { if (size != 3) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } restart_enum = pk_restart_enum_from_string (sections[1]); if (restart_enum == PK_RESTART_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Restart enum not recognised, and hence ignored: '%s'", sections[1]); return FALSE; } if (!pk_package_id_check (sections[2])) { g_set_error (error, 1, 0, "invalid package_id"); return FALSE; } pk_backend_job_require_restart (job, restart_enum, sections[2]); } else if (g_strcmp0 (command, "status") == 0) { if (size != 2) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } status_enum = pk_status_enum_from_string (sections[1]); if (status_enum == PK_STATUS_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Status enum not recognised, and hence ignored: '%s'", sections[1]); return FALSE; } pk_backend_job_set_status (job, status_enum); } else if (g_strcmp0 (command, "speed") == 0) { if (size != 2) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } if (!pk_strtouint64 (sections[1], &speed)) { g_set_error (error, 1, 0, "failed to parse speed: '%s'", sections[1]); return FALSE; } pk_backend_job_set_speed (job, speed); } else if (g_strcmp0 (command, "download-size-remaining") == 0) { if (size != 2) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } if (!pk_strtouint64 (sections[1], &download_size_remaining)) { g_set_error (error, 1, 0, "failed to parse download_size_remaining: '%s'", sections[1]); return FALSE; } pk_backend_job_set_download_size_remaining (job, download_size_remaining); } else if (g_strcmp0 (command, "allow-cancel") == 0) { if (size != 2) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } if (g_strcmp0 (sections[1], "true") == 0) { pk_backend_job_set_allow_cancel (job, TRUE); } else if (g_strcmp0 (sections[1], "false") == 0) { pk_backend_job_set_allow_cancel (job, FALSE); } else { g_set_error (error, 1, 0, "invalid section '%s'", sections[1]); return FALSE; } } else if (g_strcmp0 (command, "no-percentage-updates") == 0) { if (size != 1) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } pk_backend_job_set_percentage (job, PK_BACKEND_PERCENTAGE_INVALID); } else if (g_strcmp0 (command, "repo-signature-required") == 0) { if (size != 9) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } sig_type = pk_sig_type_enum_from_string (sections[8]); if (sig_type == PK_SIGTYPE_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Sig enum not recognised, and hence ignored: '%s'", sections[8]); return FALSE; } if (pk_strzero (sections[1])) { g_set_error (error, 1, 0, "package_id blank, and hence ignored: '%s'", sections[1]); return FALSE; } if (pk_strzero (sections[2])) { g_set_error (error, 1, 0, "repository name blank, and hence ignored: '%s'", sections[2]); return FALSE; } /* pass _all_ of the data */ pk_backend_job_repo_signature_required (job, sections[1], sections[2], sections[3], sections[4], sections[5], sections[6], sections[7], sig_type); } else if (g_strcmp0 (command, "eula-required") == 0) { if (size != 5) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } if (pk_strzero (sections[1])) { g_set_error (error, 1, 0, "eula_id blank, and hence ignored: '%s'", sections[1]); return FALSE; } if (pk_strzero (sections[2])) { g_set_error (error, 1, 0, "package_id blank, and hence ignored: '%s'", sections[2]); return FALSE; } if (pk_strzero (sections[4])) { g_set_error (error, 1, 0, "agreement name blank, and hence ignored: '%s'", sections[4]); return FALSE; } pk_backend_job_eula_required (job, sections[1], sections[2], sections[3], sections[4]); } else if (g_strcmp0 (command, "media-change-required") == 0) { if (size != 4) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } media_type_enum = pk_media_type_enum_from_string (sections[1]); if (media_type_enum == PK_MEDIA_TYPE_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "media type enum not recognised, and hence ignored: '%s'", sections[1]); return FALSE; } pk_backend_job_media_change_required (job, media_type_enum, sections[2], sections[3]); } else if (g_strcmp0 (command, "distro-upgrade") == 0) { if (size != 4) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } distro_upgrade_enum = pk_distro_upgrade_enum_from_string (sections[1]); if (distro_upgrade_enum == PK_DISTRO_UPGRADE_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "distro upgrade enum not recognised, and hence ignored: '%s'", sections[1]); return FALSE; } g_strdelimit (sections[3], PK_UNSAFE_DELIMITERS, ' '); if (!g_utf8_validate (sections[3], -1, NULL)) { g_set_error (error, 1, 0, "text '%s' was not valid UTF8!", sections[3]); return FALSE; } pk_backend_job_distro_upgrade (job, distro_upgrade_enum, sections[2], sections[3]); } else if (g_strcmp0 (command, "category") == 0) { if (size != 6) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); return FALSE; } if (g_strcmp0 (sections[1], sections[2]) == 0) { g_set_error_literal (error, 1, 0, "cat_id cannot be the same as parent_id"); return FALSE; } if (pk_strzero (sections[2])) { g_set_error_literal (error, 1, 0, "cat_id cannot not blank"); return FALSE; } if (pk_strzero (sections[3])) { g_set_error_literal (error, 1, 0, "name cannot not blank"); return FALSE; } g_strdelimit (sections[4], PK_UNSAFE_DELIMITERS, ' '); if (!g_utf8_validate (sections[4], -1, NULL)) { g_set_error (error, 1, 0, "text '%s' was not valid UTF8!", sections[4]); return FALSE; } if (pk_strzero (sections[5])) { g_set_error_literal (error, 1, 0, "icon cannot not blank"); return FALSE; } if (g_str_has_prefix (sections[5], "/")) { g_set_error (error, 1, 0, "icon '%s' should be a named icon, not a path", sections[5]); return FALSE; } pk_backend_job_category (job, sections[1], sections[2], sections[3], sections[4], sections[5]); } else { g_set_error (error, 1, 0, "invalid command '%s'", command); return FALSE; } return TRUE; }
static void common_progress(int value, gpointer user_data) { PkBackend* backend = (PkBackend *) user_data; pk_backend_job_set_percentage (job, value); }
/** * pk_backend_search_names: * * A really long wait........ */ void pk_backend_search_names (PkBackend *backend, PkBackendJob *job, PkBitfield filters, gchar **values) { pk_backend_job_set_percentage (job, PK_BACKEND_PERCENTAGE_INVALID); g_timeout_add (200, pk_backend_search_name_timeout, backend); }
static void backend_find_packages_thread (PkBackendJob *job, GVariant *params, gpointer user_data) { PkBitfield filters; const gchar *search; gchar **values; guint mode; GList *list = NULL; sqlite3 *db = NULL; gint filter_box = 0; filters = pk_backend_get_uint (backend, "filters"); mode = pk_backend_get_uint (backend, "mode"); values = pk_backend_get_strv (backend, "search"); /* FIXME: support multiple packages */ search = values[0]; pk_backend_job_set_status (job, PK_STATUS_ENUM_QUERY); if (pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED)) { filter_box = filter_box | PKG_INSTALLED; } if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) { filter_box = filter_box | PKG_AVAILABLE; } if (pk_bitfield_contain (filters, PK_FILTER_ENUM_DEVELOPMENT)) { filter_box = filter_box | PKG_DEVEL; } if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_DEVELOPMENT)) { filter_box = filter_box | PKG_NON_DEVEL; } if (pk_bitfield_contain (filters, PK_FILTER_ENUM_GUI)) { filter_box = filter_box | PKG_GUI; } if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_GUI)) { filter_box = filter_box | PKG_TEXT; } if (mode == SEARCH_TYPE_DETAILS) { filter_box = filter_box | PKG_SEARCH_DETAILS; } pk_backend_job_set_percentage (job, PK_BACKEND_PERCENTAGE_INVALID); db = db_open (); if (mode == SEARCH_TYPE_FILE) { list = box_db_repos_search_file_with_filter (db, search, filter_box); add_packages_from_list (backend, list, FALSE); box_db_repos_package_list_free (list); } else if (mode == SEARCH_TYPE_RESOLVE) { list = box_db_repos_packages_search_one (db, (gchar *)search); add_packages_from_list (backend, list, FALSE); box_db_repos_package_list_free (list); } else { if ((pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED) && pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) || (!pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED) && !pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED))) { list = box_db_repos_packages_search_all (db, (gchar *)search, filter_box); } else if (pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED)) { list = box_db_repos_packages_search_installed (db, (gchar *)search, filter_box); } else if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) { list = box_db_repos_packages_search_available (db, (gchar *)search, filter_box); } add_packages_from_list (backend, list, FALSE); box_db_repos_package_list_free (list); } db_close (db); pk_backend_finished (backend); }