static void pk_backend_search_files_thread(PkBackendJob *job, GVariant *params, gpointer user_data) { gchar **search; PkBitfield filters; AptIntf *apt = static_cast<AptIntf*>(pk_backend_job_get_user_data(job)); g_variant_get(params, "(t^a&s)", &filters, &search); pk_backend_job_set_allow_cancel(job, true); // as we can only search for installed files lets avoid the opposite if (!pk_bitfield_contain(filters, PK_FILTER_ENUM_NOT_INSTALLED)) { if (!apt->init()) { g_debug("Failed to create apt cache"); return; } pk_backend_job_set_status(job, PK_STATUS_ENUM_QUERY); PkgList output; output = apt->searchPackageFiles(search); // It's faster to emit the packages here rather than in the matching part apt->emitPackages(output, filters); } }
gboolean pk_backend_finish (PkBackend *self, GError *error) { gboolean cancelled = FALSE; g_return_val_if_fail (self != NULL, FALSE); pk_backend_job_set_allow_cancel (self, FALSE); g_static_mutex_lock (&mutex); if (cancellable != NULL) { cancelled = g_cancellable_is_cancelled (cancellable); g_object_unref (cancellable); cancellable = NULL; } g_static_mutex_unlock (&mutex); if (error != NULL) { pk_backend_error (self, error); g_error_free (error); } if (cancelled) { pk_backend_job_set_status (self, PK_STATUS_ENUM_CANCEL); } pk_backend_job_finished (self); return (error == NULL); }
/** * pk_backend_refresh_cache_thread: */ static void pk_backend_refresh_cache_thread(PkBackendJob *job, GVariant *params, gpointer user_data) { pk_backend_job_set_allow_cancel(job, true); 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; } PkBackend *backend = PK_BACKEND(pk_backend_job_get_backend(job)); if (pk_backend_is_online(backend)) { apt->refreshCache(); if (_error->PendingError() == true) { show_errors(job, PK_ERROR_ENUM_CANNOT_FETCH_SOURCES, true); } } else { pk_backend_job_error_code(job, PK_ERROR_ENUM_NO_NETWORK, "Cannot refresh cache whilst offline"); } apt->emitFinished(); }
static void backend_get_updates_thread(PkBackendJob *job, GVariant *params, gpointer user_data) { PkBitfield filters; g_variant_get(params, "(t)", &filters); pk_backend_job_set_allow_cancel(job, true); 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); PkgList updates; PkgList blocked; updates = apt->getUpdates(blocked); apt->emitUpdates(updates, filters); apt->emitPackages(blocked, filters, PK_INFO_ENUM_BLOCKED); apt->emitFinished(); }
void pk_alpm_run (PkBackendJob *job, PkStatusEnum status, PkBackendJobThreadFunc func, gpointer data) { g_return_if_fail (func != NULL); pk_backend_job_set_allow_cancel (job, TRUE); pk_backend_job_set_status (job, status); pk_backend_job_thread_create (job, func, data, NULL); }
static void backend_depends_on_or_requires_thread(PkBackendJob *job, GVariant *params, gpointer user_data) { PkRoleEnum role; PkBitfield filters; gchar **package_ids; gboolean recursive; gchar *pi; g_variant_get(params, "(t^a&sb)", &filters, &package_ids, &recursive); role = pk_backend_job_get_role(job); pk_backend_job_set_allow_cancel(job, true); AptIntf *apt = static_cast<AptIntf*>(pk_backend_job_get_user_data(job)); if (!apt->init()) { g_debug("Failed to create apt cache"); return; } pk_backend_job_set_status(job, PK_STATUS_ENUM_QUERY); PkgList output; for (uint i = 0; i < g_strv_length(package_ids); ++i) { if (apt->cancelled()) { break; } pi = package_ids[i]; if (pk_package_id_check(pi) == false) { pk_backend_job_error_code(job, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "%s", pi); return; } const pkgCache::VerIterator &ver = apt->aptCacheFile()->resolvePkgID(pi); if (ver.end()) { pk_backend_job_error_code(job, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "Couldn't find package %s", pi); return; } if (role == PK_ROLE_ENUM_DEPENDS_ON) { apt->getDepends(output, ver, recursive); } else { apt->getRequires(output, ver, recursive); } } // It's faster to emit the packages here than in the matching part apt->emitPackages(output, filters); }
gboolean pk_backend_transaction_commit (PkBackend *self, GError **error) { alpm_list_t *data = NULL; gchar *prefix; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (alpm != NULL, FALSE); if (pk_backend_cancelled (self)) { return TRUE; } pk_backend_job_set_allow_cancel (self, FALSE); pk_backend_job_set_status (self, PK_STATUS_ENUM_RUNNING); if (alpm_trans_commit (alpm, &data) >= 0) { return TRUE; } switch (alpm_errno (alpm)) { case ALPM_ERR_FILE_CONFLICTS: prefix = alpm_fileconflict_build_list (data); alpm_list_free_inner (data, alpm_fileconflict_free); alpm_list_free (data); break; case ALPM_ERR_PKG_INVALID: case ALPM_ERR_DLT_INVALID: prefix = alpm_string_build_list (data); alpm_list_free (data); break; default: prefix = NULL; if (data != NULL) { g_warning ("unhandled error %d", alpm_errno (alpm)); } break; } if (prefix != NULL) { alpm_errno_t errno = alpm_errno (alpm); g_set_error (error, ALPM_ERROR, errno, "%s: %s", prefix, alpm_strerror (errno)); g_free (prefix); } else { alpm_errno_t errno = alpm_errno (alpm); g_set_error_literal (error, ALPM_ERROR, errno, alpm_strerror (errno)); } return FALSE; }
void pk_backend_start_job(PkBackend *backend, PkBackendJob *job) { gchar *db_filename = NULL; PkBackendKatjaJobData *job_data = g_new0(PkBackendKatjaJobData, 1); pk_backend_job_set_allow_cancel(job, TRUE); pk_backend_job_set_allow_cancel(job, FALSE); db_filename = g_build_filename(LOCALSTATEDIR, "cache", "PackageKit", "metadata", "metadata.db", NULL); if (sqlite3_open(db_filename, &job_data->db) == SQLITE_OK) { /* Some SQLite settings */ sqlite3_exec(job_data->db, "PRAGMA foreign_keys = ON", NULL, NULL, NULL); } else { pk_backend_job_error_code(job, PK_ERROR_ENUM_NO_CACHE, "%s: %s", db_filename, sqlite3_errmsg(job_data->db)); goto out; } pk_backend_job_set_user_data(job, job_data); pk_backend_job_set_status(job, PK_STATUS_ENUM_RUNNING); out: g_free(db_filename); }
/** * pk_backend_job_finished: **/ void pk_backend_job_finished (PkBackendJob *job) { const gchar *role_text; g_return_if_fail (PK_IS_BACKEND_JOB (job)); /* check we have not already finished */ if (job->priv->finished) { g_warning ("already finished"); return; } /* find out what we just did */ role_text = pk_role_enum_to_string (job->priv->role); /* ensure the same number of ::Files() were sent as packages for DownloadPackages */ if (!job->priv->set_error && job->priv->role == PK_ROLE_ENUM_DOWNLOAD_PACKAGES && job->priv->download_files == 0) { g_warning ("required multiple Files() for each package_id!"); } /* check we sent at least one status calls */ if (job->priv->set_error == FALSE && job->priv->status == PK_STATUS_ENUM_SETUP) { g_warning ("required status signals for %s!", role_text); } /* drop any inhibits */ pk_backend_job_set_allow_cancel (job, TRUE); /* mark as finished for the UI that might only be watching status */ pk_backend_job_set_status (job, PK_STATUS_ENUM_FINISHED); /* we can't ever be re-used */ job->priv->finished = TRUE; /* this wasn't set otherwise, assume success */ if (job->priv->exit == PK_EXIT_ENUM_UNKNOWN) pk_backend_job_set_exit_code (job, PK_EXIT_ENUM_SUCCESS); /* emit */ pk_backend_job_call_vfunc (job, PK_BACKEND_SIGNAL_FINISHED, GUINT_TO_POINTER (job->priv->exit), 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(); }
void pk_alpm_run (PkBackendJob *job, PkStatusEnum status, PkBackendJobThreadFunc func, gpointer data) { PkBackend *backend = pk_backend_job_get_backend (job); PkBackendAlpmPrivate *priv = pk_backend_get_user_data (backend); g_return_if_fail (func != NULL); if (priv->localdb_changed) { pk_backend_destroy (backend); pk_backend_initialize (NULL, backend); pk_backend_installed_db_changed (backend); } pk_backend_job_set_allow_cancel (job, TRUE); pk_backend_job_set_status (job, status); pk_backend_job_thread_create (job, func, data, NULL); }
static void backend_get_packages_thread(PkBackendJob *job, GVariant *params, gpointer user_data) { PkBitfield filters; g_variant_get(params, "(t)", &filters); pk_backend_job_set_allow_cancel(job, true); AptIntf *apt = static_cast<AptIntf*>(pk_backend_job_get_user_data(job)); if (!apt->init()) { g_debug("Failed to create apt cache"); return; } PkgList output; output = apt->getPackages(); // It's faster to emit the packages rather here than in the matching part apt->emitPackages(output, filters); }
void pk_backend_run (PkBackend *self, PkStatusEnum status, PkBackendThreadFunc func) { g_return_if_fail (self != NULL); g_return_if_fail (func != NULL); g_static_mutex_lock (&mutex); if (cancellable != NULL) { g_warning ("cancellable was not NULL"); g_object_unref (cancellable); } cancellable = g_cancellable_new (); g_static_mutex_unlock (&mutex); pk_backend_job_set_allow_cancel (self, TRUE); pk_backend_job_set_status (self, status); pk_backend_job_thread_create (self, func); }
static void pk_backend_resolve_thread(PkBackendJob *job, GVariant *params, gpointer user_data) { gchar **search; PkBitfield filters; g_variant_get(params, "(t^a&s)", &filters, &search); pk_backend_job_set_allow_cancel(job, true); AptIntf *apt = static_cast<AptIntf*>(pk_backend_job_get_user_data(job)); if (!apt->init()) { g_debug("Failed to create apt cache"); return; } PkgList pkgs = apt->resolvePackageIds(search); // It's faster to emit the packages here rather than in the matching part apt->emitPackages(pkgs, filters); }
static void backend_manage_packages_thread(PkBackendJob *job, GVariant *params, gpointer user_data) { // Transaction flags PkBitfield transaction_flags = 0; gboolean allow_deps = false; gboolean autoremove = false; bool fileInstall = false; gchar **full_paths = NULL; gchar **package_ids = NULL; // Get the transaction role since this method is called by install/remove/update/repair PkRoleEnum role = pk_backend_job_get_role(job); if (role == PK_ROLE_ENUM_INSTALL_FILES) { g_variant_get(params, "(t^a&s)", &transaction_flags, &full_paths); fileInstall = true; } else if (role == PK_ROLE_ENUM_REMOVE_PACKAGES) { g_variant_get(params, "(t^a&sbb)", &transaction_flags, &package_ids, &allow_deps, &autoremove); } else if (role == PK_ROLE_ENUM_INSTALL_PACKAGES) { g_variant_get(params, "(t^a&s)", &transaction_flags, &package_ids); } else if (role == PK_ROLE_ENUM_UPDATE_PACKAGES) { g_variant_get(params, "(t^a&s)", &transaction_flags, &package_ids); } // Check if we should only simulate the install (calculate dependencies) bool simulate; simulate = pk_bitfield_contain(transaction_flags, PK_TRANSACTION_FLAG_ENUM_SIMULATE); // Check if we should only download all the required packages for this transaction bool downloadOnly; downloadOnly = pk_bitfield_contain(transaction_flags, PK_TRANSACTION_FLAG_ENUM_ONLY_DOWNLOAD); // Check if we should fix broken packages bool fixBroken = false; if (role == PK_ROLE_ENUM_REPAIR_SYSTEM) { // On fix broken mode no package to remove/install is allowed fixBroken = true; } g_debug("FILE INSTALL: %i", fileInstall); pk_backend_job_set_allow_cancel(job, true); AptIntf *apt = static_cast<AptIntf*>(pk_backend_job_get_user_data(job)); if (!apt->init()) { g_debug("Failed to create apt cache"); return; } pk_backend_job_set_status(job, PK_STATUS_ENUM_QUERY); PkgList installPkgs, removePkgs; if (fileInstall) { // File installation EXPERIMENTAL // GDebi can not install more than one package at time if (g_strv_length(full_paths) > 1) { pk_backend_job_error_code(job, PK_ERROR_ENUM_NOT_SUPPORTED, "The backend can only process one file at time."); return; } // get the list of packages to install if (!apt->markFileForInstall(full_paths[0], installPkgs, removePkgs)) { return; } cout << "installPkgs.size: " << installPkgs.size() << endl; cout << "removePkgs.size: " << removePkgs.size() << endl; } else if (!fixBroken) { // Resolve the given packages if (role == PK_ROLE_ENUM_REMOVE_PACKAGES) { removePkgs = apt->resolvePackageIds(package_ids); } else { installPkgs = apt->resolvePackageIds(package_ids); } if (removePkgs.size() == 0 && installPkgs.size() == 0) { pk_backend_job_error_code(job, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "Could not find package(s)"); return; } } // Install/Update/Remove packages, or just simulate bool ret; ret = apt->runTransaction(installPkgs, removePkgs, fileInstall, // Mark newly installed packages as auto-installed // (they're dependencies of the new local package) fixBroken, transaction_flags, autoremove); if (!ret) { // Print transaction errors g_debug("AptIntf::runTransaction() failed: %i", _error->PendingError()); return; } if (fileInstall) { // Now perform the installation! gchar *path; for (uint i = 0; i < g_strv_length(full_paths); ++i) { if (apt->cancelled()) { break; } path = full_paths[i]; if (!apt->installFile(path, simulate)) { cout << "Installation of DEB file " << path << " failed." << endl; return; } } } }
static void backend_manage_packages_thread(PkBackendJob *job, GVariant *params, gpointer user_data) { // Transaction flags PkBitfield transaction_flags = 0; gboolean allow_deps = false; gboolean autoremove = false; bool fileInstall = false; gchar **full_paths = NULL; gchar **package_ids = NULL; // Get the transaction role since this method is called by install/remove/update/repair PkRoleEnum role = pk_backend_job_get_role(job); if (role == PK_ROLE_ENUM_INSTALL_FILES) { g_variant_get(params, "(t^a&s)", &transaction_flags, &full_paths); fileInstall = true; } else if (role == PK_ROLE_ENUM_REMOVE_PACKAGES) { g_variant_get(params, "(t^a&sbb)", &transaction_flags, &package_ids, &allow_deps, &autoremove); } else if (role == PK_ROLE_ENUM_INSTALL_PACKAGES) { g_variant_get(params, "(t^a&s)", &transaction_flags, &package_ids); } else if (role == PK_ROLE_ENUM_UPDATE_PACKAGES) { g_variant_get(params, "(t^a&s)", &transaction_flags, &package_ids); } // Check if we should only simulate the install (calculate dependencies) bool simulate; simulate = pk_bitfield_contain(transaction_flags, PK_TRANSACTION_FLAG_ENUM_SIMULATE); // Check if we should only download all the required packages for this transaction bool downloadOnly; downloadOnly = pk_bitfield_contain(transaction_flags, PK_TRANSACTION_FLAG_ENUM_ONLY_DOWNLOAD); // Check if we should fix broken packages bool fixBroken = false; if (role == PK_ROLE_ENUM_REPAIR_SYSTEM) { // On fix broken mode no package to remove/install is allowed fixBroken = true; } pk_backend_job_set_allow_cancel(job, true); AptIntf *apt = static_cast<AptIntf*>(pk_backend_job_get_user_data(job)); if (!apt->init(full_paths)) { g_debug("Failed to create apt cache"); return; } pk_backend_job_set_status(job, PK_STATUS_ENUM_QUERY); PkgList installPkgs, removePkgs, updatePkgs; if (!fixBroken) { // Resolve the given packages if (role == PK_ROLE_ENUM_REMOVE_PACKAGES) { removePkgs = apt->resolvePackageIds(package_ids); } else if (role == PK_ROLE_ENUM_INSTALL_PACKAGES) { installPkgs = apt->resolvePackageIds(package_ids); } else if (role == PK_ROLE_ENUM_UPDATE_PACKAGES) { updatePkgs = apt->resolvePackageIds(package_ids); } else if (role == PK_ROLE_ENUM_INSTALL_FILES) { installPkgs = apt->resolveLocalFiles(full_paths); } else { pk_backend_job_error_code(job, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "Could not figure out what to do to apply the change."); return; } if (removePkgs.size() == 0 && installPkgs.size() == 0 && updatePkgs.size() == 0) { pk_backend_job_error_code(job, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "Could not find package(s)"); return; } } // Install/Update/Remove packages, or just simulate bool ret = apt->runTransaction(installPkgs, removePkgs, updatePkgs, fixBroken, transaction_flags, autoremove); if (!ret) { // Print transaction errors g_debug("AptIntf::runTransaction() failed: %i", _error->PendingError()); return; } }
/** * pk_backend_download_packages_thread: */ static void pk_backend_download_packages_thread(PkBackendJob *job, GVariant *params, gpointer user_data) { gchar **package_ids; const gchar *tmpDir; string directory; g_variant_get(params, "(^a&ss)", &package_ids, &tmpDir); directory = _config->FindDir("Dir::Cache::archives"); pk_backend_job_set_allow_cancel(job, true); AptIntf *apt = static_cast<AptIntf*>(pk_backend_job_get_user_data(job)); if (!apt->init()) { g_debug("Failed to create apt cache"); return; } PkBackend *backend = PK_BACKEND(pk_backend_job_get_backend(job)); if (pk_backend_is_online(backend)) { pk_backend_job_set_status(job, PK_STATUS_ENUM_QUERY); // Create the progress AcqPackageKitStatus Stat(apt, job); // get a fetcher pkgAcquire fetcher(&Stat); gchar *pi; // TODO this might be useful when the item is in the cache // for (pkgAcquire::ItemIterator I = fetcher.ItemsBegin(); I < fetcher.ItemsEnd();) // { // if ((*I)->Local == true) // { // I++; // continue; // } // // // Close the item and check if it was found in cache // (*I)->Finished(); // if ((*I)->Complete == false) { // Transient = true; // } // // // Clear it out of the fetch list // delete *I; // I = fetcher.ItemsBegin(); // } for (uint i = 0; i < g_strv_length(package_ids); ++i) { pi = package_ids[i]; if (pk_package_id_check(pi) == false) { pk_backend_job_error_code(job, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "%s", pi); return; } if (apt->cancelled()) { break; } const pkgCache::VerIterator &ver = apt->aptCacheFile()->resolvePkgID(pi); // Ignore packages that could not be found or that exist only due to dependencies. if (ver.end()) { _error->Error("Can't find this package id \"%s\".", pi); continue; } else { if(!ver.Downloadable()) { _error->Error("No downloadable files for %s," "perhaps it is a local or obsolete" "package?", pi); continue; } string storeFileName; if (!apt->getArchive(&fetcher, ver, directory, storeFileName)) { return; } gchar **files = (gchar **) g_malloc(2 * sizeof(gchar *)); files[0] = g_strdup_printf("%s/%s", directory.c_str(), flNotDir(storeFileName).c_str()); files[1] = NULL; pk_backend_job_files(job, pi, files); g_strfreev(files); } } if (fetcher.Run() != pkgAcquire::Continue && apt->cancelled() == false) { // We failed and we did not cancel show_errors(job, PK_ERROR_ENUM_PACKAGE_DOWNLOAD_FAILED); return; } } else { pk_backend_job_error_code(job, PK_ERROR_ENUM_NO_NETWORK, "Cannot download packages whilst offline"); } }
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; }