static gboolean backend_remove_packages_thread (PkBackend *backend) { PacmanList *list; gboolean allow_deps; gboolean autoremove; PacmanTransaction *transaction = NULL; PacmanTransactionFlags flags = PACMAN_TRANSACTION_FLAGS_NONE; g_return_val_if_fail (backend != NULL, FALSE); allow_deps = pk_backend_get_bool (backend, "allow_deps"); autoremove = pk_backend_get_bool (backend, "autoremove"); /* remove packages that depend on those to be removed */ if (allow_deps) { flags |= PACMAN_TRANSACTION_FLAGS_REMOVE_CASCADE; } /* remove unneeded packages that were required by those to be removed */ if (autoremove) { flags |= PACMAN_TRANSACTION_FLAGS_REMOVE_RECURSIVE; } /* run the transaction */ list = backend_remove_list_targets (backend); if (list != NULL) { transaction = backend_transaction_run (backend, PACMAN_TRANSACTION_REMOVE, flags, list); pacman_list_free_full (list, g_free); } return backend_transaction_finished (backend, transaction); }
static gboolean pk_backend_install_files_thread (PkBackendJob *self) { gboolean only_trusted; GError *error = NULL; g_return_val_if_fail (self != NULL, FALSE); only_trusted = pk_backend_get_bool (self, "only_trusted"); if (!only_trusted && !pk_backend_disable_signatures (self, &error)) { goto out; } if (pk_backend_transaction_initialize (self, 0, &error) && pk_backend_transaction_add_targets (self, &error) && pk_backend_transaction_simulate (self, &error)) { pk_backend_transaction_commit (self, &error); } out: pk_backend_transaction_end (self, (error == NULL) ? &error : NULL); if (!only_trusted) { GError **e = (error == NULL) ? &error : NULL; pk_backend_enable_signatures (self, e); } return pk_backend_finish (self, error); }
static alpm_list_t * pk_backend_find_requirer (PkBackend *self, alpm_list_t *pkgs, const gchar *name, GError **error) { alpm_pkg_t *requirer; g_return_val_if_fail (self != NULL, pkgs); g_return_val_if_fail (name != NULL, pkgs); g_return_val_if_fail (localdb != NULL, pkgs); if (alpm_list_find_pkg (pkgs, name) != NULL) { return pkgs; } /* look for local requirers */ requirer = alpm_db_get_pkg (localdb, name); if (requirer != NULL) { pk_backend_pkg (self, requirer, PK_INFO_ENUM_INSTALLED); if (pk_backend_get_bool (self, "recursive")) { pkgs = alpm_list_add (pkgs, requirer); } } else { int code = ALPM_ERR_PKG_NOT_FOUND; g_set_error (error, ALPM_ERROR, code, "%s: %s", name, alpm_strerror (code)); } return pkgs; }
static gboolean backend_simulate_remove_packages_thread (PkBackend *backend) { PacmanList *list; gboolean autoremove; PacmanTransaction *transaction = NULL; PacmanTransactionFlags flags = PACMAN_TRANSACTION_FLAGS_REMOVE_CASCADE; g_return_val_if_fail (backend != NULL, FALSE); autoremove = pk_backend_get_bool (backend, "autoremove"); /* remove unneeded packages that were required by those to be removed */ if (autoremove) { flags |= PACMAN_TRANSACTION_FLAGS_REMOVE_RECURSIVE; } /* prepare the transaction */ list = backend_remove_list_targets (backend); if (list != NULL) { transaction = backend_transaction_simulate (backend, PACMAN_TRANSACTION_REMOVE, flags, list); pacman_list_free_full (list, g_free); if (transaction != NULL) { /* emit packages that would have been installed or removed */ backend_transaction_packages (backend, transaction); } } return backend_transaction_finished (backend, transaction); }
static gboolean backend_repo_enable_thread (PkBackend *backend) { GError *error = NULL; const gchar *repo; gboolean enabled; g_return_val_if_fail (pacman != NULL, FALSE); g_return_val_if_fail (disabled_repos != NULL, FALSE); g_return_val_if_fail (backend != NULL, FALSE); repo = pk_backend_get_string (backend, "repo_id"); enabled = pk_backend_get_bool (backend, "enabled"); g_return_val_if_fail (repo != NULL, FALSE); if (enabled) { /* check that repo is indeed disabled */ if (g_hash_table_remove (disabled_repos, repo)) { /* reload configuration to preserve the correct order */ if (disabled_repos_configure (disabled_repos, &error)) { pk_backend_repo_list_changed (backend); } else { backend_error (backend, error); pk_backend_thread_finished (backend); return FALSE; } } else { pk_backend_error_code (backend, PK_ERROR_ENUM_REPO_NOT_FOUND, "Could not find repo [%s]", repo); pk_backend_thread_finished (backend); return FALSE; } } else { PacmanDatabase *database = pacman_manager_find_sync_database (pacman, repo); if (database != NULL) { if (pacman_manager_unregister_database (pacman, database, &error)) { g_hash_table_insert (disabled_repos, g_strdup (repo), GINT_TO_POINTER (1)); } else { backend_error (backend, error); pk_backend_thread_finished (backend); return FALSE; } } else { pk_backend_error_code (backend, PK_ERROR_ENUM_REPO_NOT_FOUND, "Could not find repo [%s]", repo); pk_backend_thread_finished (backend); return FALSE; } } pk_backend_thread_finished (backend); return TRUE; }
static gboolean pk_backend_refresh_cache_thread (PkBackend *self) { gint force; GError *error = NULL; g_return_val_if_fail (self != NULL, FALSE); /* download databases even if they are older than current */ force = (gint) pk_backend_get_bool (self, "force"); pk_backend_update_databases (self, force, &error); return pk_backend_finish (self, error); }
static gboolean backend_refresh_cache_thread (PkBackend *backend) { gboolean force; PacmanTransaction *transaction = NULL; PacmanTransactionFlags flags = PACMAN_TRANSACTION_FLAGS_NONE; g_return_val_if_fail (backend != NULL, FALSE); force = pk_backend_get_bool (backend, "force"); /* download databases even if they are older than current */ if (force) { flags |= PACMAN_TRANSACTION_FLAGS_UPDATE_ALLOW_DOWNGRADE; } /* run the transaction */ transaction = backend_transaction_run (backend, PACMAN_TRANSACTION_UPDATE, flags, NULL); return backend_transaction_finished (backend, transaction); }
static alpm_list_t * pk_backend_find_provider (PkBackend *self, alpm_list_t *pkgs, const gchar *depend, GError **error) { PkBitfield filters; gboolean recursive, skip_local, skip_remote; alpm_pkg_t *provider; alpm_list_t *pkgcache, *syncdbs; g_return_val_if_fail (self != NULL, pkgs); g_return_val_if_fail (depend != NULL, pkgs); g_return_val_if_fail (alpm != NULL, pkgs); g_return_val_if_fail (localdb != NULL, pkgs); recursive = pk_backend_get_bool (self, "recursive"); filters = pk_backend_get_uint (self, "filters"); skip_local = pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED); skip_remote = pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED); if (alpm_find_satisfier (pkgs, depend) != NULL) { return pkgs; } /* look for local dependencies */ pkgcache = alpm_db_get_pkgcache (localdb); provider = alpm_find_satisfier (pkgcache, depend); if (provider != NULL) { if (!skip_local) { pk_backend_pkg (self, provider, PK_INFO_ENUM_INSTALLED); /* assume later dependencies will also be local */ if (recursive) { pkgs = alpm_list_add (pkgs, provider); } } return pkgs; } /* look for remote dependencies */ syncdbs = alpm_get_syncdbs (alpm); provider = alpm_find_dbs_satisfier (alpm, syncdbs, depend); if (provider != NULL) { if (!skip_remote) { pk_backend_pkg (self, provider, PK_INFO_ENUM_AVAILABLE); } /* keep looking for local dependencies */ if (recursive) { pkgs = alpm_list_add (pkgs, provider); } } else { int code = ALPM_ERR_UNSATISFIED_DEPS; g_set_error (error, ALPM_ERROR, code, "%s: %s", depend, alpm_strerror (code)); } return pkgs; }
static gboolean backend_search_package_thread (PkBackend *backend) { const gchar *search; PkBitfield filters; search = pk_backend_get_string (backend, "search"); filters = (PkBitfield) pk_backend_get_uint (backend, "filters"); pk_backend_set_percentage (backend, PK_BACKEND_PERCENTAGE_INVALID); pk_backend_set_allow_cancel (backend, true); matcher *m_matcher = new matcher(string(search)); if (m_matcher->hasError()) { egg_debug("Regex compilation error"); delete m_matcher; pk_backend_finished (backend); return false; } aptcc *m_apt = new aptcc(backend, _cancel); pk_backend_set_pointer(backend, "aptcc_obj", m_apt); if (m_apt->init()) { egg_debug ("Failed to create apt cache"); delete m_matcher; delete m_apt; pk_backend_finished (backend); return false; } if (_error->PendingError() == true) { delete m_matcher; delete m_apt; pk_backend_finished (backend); return false; } pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY); pkgDepCache::Policy Plcy; vector<pair<pkgCache::PkgIterator, pkgCache::VerIterator> > output; if (pk_backend_get_bool (backend, "search_details")) { for (pkgCache::PkgIterator pkg = m_apt->packageCache->PkgBegin(); !pkg.end(); ++pkg) { if (_cancel) { break; } // Ignore packages that exist only due to dependencies. if (pkg.VersionList().end() && pkg.ProvidesList().end()) { continue; } if (m_matcher->matches(pkg.Name())) { // Don't insert virtual packages instead add what it provides pkgCache::VerIterator ver = m_apt->find_ver(pkg); if (ver.end() == false) { output.push_back(pair<pkgCache::PkgIterator, pkgCache::VerIterator>(pkg, ver)); } else { // iterate over the provides list for (pkgCache::PrvIterator Prv = pkg.ProvidesList(); Prv.end() == false; Prv++) { ver = m_apt->find_ver(Prv.OwnerPkg()); // check to see if the provided package isn't virtual too if (ver.end() == false) { // we add the package now because we will need to // remove duplicates later anyway output.push_back(pair<pkgCache::PkgIterator, pkgCache::VerIterator>(Prv.OwnerPkg(), ver)); } } } } else { // Don't insert virtual packages instead add what it provides pkgCache::VerIterator ver = m_apt->find_ver(pkg); if (ver.end() == false) { if (m_matcher->matches(get_default_short_description(ver, m_apt->packageRecords)) || m_matcher->matches(get_default_long_description(ver, m_apt->packageRecords)) || m_matcher->matches(get_short_description(ver, m_apt->packageRecords)) || m_matcher->matches(get_long_description(ver, m_apt->packageRecords))) { output.push_back(pair<pkgCache::PkgIterator, pkgCache::VerIterator>(pkg, ver)); } } else { // iterate over the provides list for (pkgCache::PrvIterator Prv = pkg.ProvidesList(); Prv.end() == false; Prv++) { ver = m_apt->find_ver(Prv.OwnerPkg()); // check to see if the provided package isn't virtual too if (ver.end() == false) { // we add the package now because we will need to // remove duplicates later anyway if (m_matcher->matches(Prv.OwnerPkg().Name()) || m_matcher->matches(get_default_short_description(ver, m_apt->packageRecords)) || m_matcher->matches(get_default_long_description(ver, m_apt->packageRecords)) || m_matcher->matches(get_short_description(ver, m_apt->packageRecords)) || m_matcher->matches(get_long_description(ver, m_apt->packageRecords))) { output.push_back(pair<pkgCache::PkgIterator, pkgCache::VerIterator>(Prv.OwnerPkg(), ver)); } } } } } } } else { for (pkgCache::PkgIterator pkg = m_apt->packageCache->PkgBegin(); !pkg.end(); ++pkg) { if (_cancel) { break; } // Ignore packages that exist only due to dependencies. if (pkg.VersionList().end() && pkg.ProvidesList().end()) { continue; } if (m_matcher->matches(pkg.Name())) { // Don't insert virtual packages instead add what it provides pkgCache::VerIterator ver = m_apt->find_ver(pkg); if (ver.end() == false) { output.push_back(pair<pkgCache::PkgIterator, pkgCache::VerIterator>(pkg, ver)); } else { // iterate over the provides list for (pkgCache::PrvIterator Prv = pkg.ProvidesList(); Prv.end() == false; Prv++) { ver = m_apt->find_ver(Prv.OwnerPkg()); // check to see if the provided package isn't virtual too if (ver.end() == false) { // we add the package now because we will need to // remove duplicates later anyway output.push_back(pair<pkgCache::PkgIterator, pkgCache::VerIterator>(Prv.OwnerPkg(), ver)); } } } } } } // It's faster to emmit the packages here than in the matching part m_apt->emit_packages(output, filters); delete m_matcher; delete m_apt; pk_backend_set_percentage (backend, 100); pk_backend_finished (backend); return true; }
static gboolean backend_get_or_update_system_thread (PkBackend *backend) { PkBitfield filters; bool getUpdates; filters = (PkBitfield) pk_backend_get_uint (backend, "filters"); getUpdates = pk_backend_get_bool(backend, "getUpdates"); pk_backend_set_allow_cancel (backend, true); aptcc *m_apt = new aptcc(backend, _cancel); pk_backend_set_pointer(backend, "aptcc_obj", m_apt); if (m_apt->init()) { egg_debug ("Failed to create apt cache"); delete m_apt; pk_backend_finished (backend); return false; } pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY); pkgCacheFile Cache; OpTextProgress Prog(*_config); int timeout = 10; // TODO test this while (Cache.Open(Prog, !getUpdates) == false) { // failed to open cache, try checkDeps then.. // || Cache.CheckDeps(CmdL.FileSize() != 1) == false if (getUpdates == true || (timeout <= 0)) { pk_backend_error_code(backend, PK_ERROR_ENUM_NO_CACHE, "Could not open package cache."); return false; } else { pk_backend_set_status (backend, PK_STATUS_ENUM_WAITING_FOR_LOCK); sleep(1); timeout--; } } pk_backend_set_status (backend, PK_STATUS_ENUM_RUNNING); if (pkgDistUpgrade(*Cache) == false) { show_broken(backend, Cache, false); egg_debug ("Internal error, DistUpgrade broke stuff"); delete m_apt; pk_backend_finished (backend); return false; } bool res = true; if (getUpdates) { vector<pair<pkgCache::PkgIterator, pkgCache::VerIterator> > update, kept; for(pkgCache::PkgIterator pkg=m_apt->packageCache->PkgBegin(); !pkg.end(); ++pkg) { if((*Cache)[pkg].Upgrade() == true && (*Cache)[pkg].NewInstall() == false) { update.push_back( pair<pkgCache::PkgIterator, pkgCache::VerIterator>(pkg, m_apt->find_candidate_ver(pkg))); } else if ((*Cache)[pkg].Upgradable() == true && pkg->CurrentVer != 0 && (*Cache)[pkg].Delete() == false) { kept.push_back( pair<pkgCache::PkgIterator, pkgCache::VerIterator>(pkg, m_apt->find_candidate_ver(pkg))); } } m_apt->emitUpdates(update, filters); m_apt->emit_packages(kept, filters, PK_INFO_ENUM_BLOCKED); } else { res = m_apt->installPackages(Cache); } delete m_apt; pk_backend_finished (backend); return res; }
static gboolean backend_get_details_thread (PkBackend *backend) { gchar **package_ids; gchar *pi; bool updateDetail = pk_backend_get_bool (backend, "updateDetail"); package_ids = pk_backend_get_strv (backend, "package_ids"); if (package_ids == NULL) { pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "Invalid package id"); pk_backend_finished (backend); return false; } aptcc *m_apt = new aptcc(backend, _cancel); pk_backend_set_pointer(backend, "aptcc_obj", m_apt); if (m_apt->init()) { egg_debug ("Failed to create apt cache"); delete m_apt; pk_backend_finished (backend); return false; } pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY); for (uint i = 0; i < g_strv_length(package_ids); i++) { pi = package_ids[i]; if (pk_package_id_check(pi) == false) { pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, pi); delete m_apt; pk_backend_finished (backend); return false; } pair<pkgCache::PkgIterator, pkgCache::VerIterator> pkg_ver; pkg_ver = m_apt->find_package_id(pi); if (pkg_ver.second.end() == true) { pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "couldn't find package"); delete m_apt; pk_backend_finished (backend); return false; } if (updateDetail) { m_apt->emit_update_detail(pkg_ver.first); } else { m_apt->emit_details(pkg_ver.first); } } delete m_apt; pk_backend_finished (backend); return true; }
static gboolean backend_get_depends_or_requires_thread (PkBackend *backend) { gchar **package_ids; PkBitfield filters; gchar *pi; bool recursive; package_ids = pk_backend_get_strv (backend, "package_ids"); filters = (PkBitfield) pk_backend_get_uint (backend, "filters"); recursive = pk_backend_get_bool (backend, "recursive"); pk_backend_set_allow_cancel (backend, true); aptcc *m_apt = new aptcc(backend, _cancel); pk_backend_set_pointer(backend, "aptcc_obj", m_apt); if (m_apt->init()) { egg_debug ("Failed to create apt cache"); delete m_apt; pk_backend_finished (backend); return false; } bool depends = pk_backend_get_bool(backend, "get_depends"); pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY); vector<pair<pkgCache::PkgIterator, pkgCache::VerIterator> > output; for (uint i = 0; i < g_strv_length(package_ids); i++) { if (_cancel) { break; } pi = package_ids[i]; if (pk_package_id_check(pi) == false) { pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, pi); delete m_apt; pk_backend_finished (backend); return false; } pair<pkgCache::PkgIterator, pkgCache::VerIterator> pkg_ver; pkg_ver = m_apt->find_package_id(pi); if (pkg_ver.second.end() == true) { pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "Couldn't find package"); delete m_apt; pk_backend_finished (backend); return false; } if (depends) { m_apt->get_depends(output, pkg_ver.first, recursive); } else { m_apt->get_requires(output, pkg_ver.first, recursive); } } // It's faster to emmit the packages here than in the matching part m_apt->emit_packages(output, filters); delete m_apt; pk_backend_finished (backend); return true; }
static gboolean backend_repo_manager_thread (PkBackend *backend) { // list PkBitfield filters; bool notDevelopment; // enable const gchar *repo_id; bool enabled; bool found = false; // generic const char *const salt = "$1$/iSaq7rB$EoUw5jJPPvAPECNaaWzMK/"; bool list = pk_backend_get_bool(backend, "list"); if (list) { pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY); filters = (PkBitfield) pk_backend_get_uint(backend, "filters"); notDevelopment = pk_bitfield_contain(filters, PK_FILTER_ENUM_NOT_DEVELOPMENT); } else { pk_backend_set_status (backend, PK_STATUS_ENUM_REQUEST); repo_id = pk_backend_get_string(backend, "repo_id"); enabled = pk_backend_get_bool(backend, "enabled"); } SourcesList _lst; if (_lst.ReadSources() == false) { _error-> Warning("Ignoring invalid record(s) in sources.list file!"); //return false; } if (_lst.ReadVendors() == false) { _error->Error("Cannot read vendors.list file"); show_errors(backend, PK_ERROR_ENUM_FAILED_CONFIG_PARSING); pk_backend_finished (backend); return false; } for (SourcesListIter it = _lst.SourceRecords.begin(); it != _lst.SourceRecords.end(); it++) { if ((*it)->Type & SourcesList::Comment) { continue; } string Sections; for (unsigned int J = 0; J < (*it)->NumSections; J++) { Sections += (*it)->Sections[J]; Sections += " "; } if (notDevelopment && ((*it)->Type & SourcesList::DebSrc || (*it)->Type & SourcesList::RpmSrc || (*it)->Type & SourcesList::RpmSrcDir || (*it)->Type & SourcesList::RepomdSrc)) { continue; } string repo; repo = (*it)->GetType(); repo += " " + (*it)->VendorID; repo += " " + (*it)->URI; repo += " " + (*it)->Dist; repo += " " + Sections; gchar *hash; const gchar allowedChars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; hash = crypt(repo.c_str(), salt); g_strcanon(hash, allowedChars, 'D'); string repoId(hash); if (list) { pk_backend_repo_detail(backend, repoId.c_str(), repo.c_str(), !((*it)->Type & SourcesList::Disabled)); } else { if (repoId.compare(repo_id) == 0) { if (enabled) { (*it)->Type = (*it)->Type & ~SourcesList::Disabled; } else { (*it)->Type |= SourcesList::Disabled; } found = true; break; } } } if (!list) { if (!found) { _error->Error("Could not found the repositorie"); show_errors(backend, PK_ERROR_ENUM_REPO_NOT_AVAILABLE); } else if (!_lst.UpdateSources()) { _error->Error("Could not update sources file"); show_errors(backend, PK_ERROR_ENUM_CANNOT_WRITE_REPO_CONFIG); } } pk_backend_finished (backend); return true; }
static gboolean backend_manage_packages_thread (PkBackend *backend) { gchar **package_ids; gchar *pi; bool simulate; bool remove; package_ids = pk_backend_get_strv (backend, "package_ids"); simulate = pk_backend_get_bool (backend, "simulate"); remove = pk_backend_get_bool (backend, "remove"); pk_backend_set_allow_cancel (backend, true); aptcc *m_apt = new aptcc(backend, _cancel); pk_backend_set_pointer(backend, "aptcc_obj", m_apt); if (m_apt->init()) { egg_debug ("Failed to create apt cache"); delete m_apt; pk_backend_finished (backend); return false; } pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY); vector<pair<pkgCache::PkgIterator, pkgCache::VerIterator> > pkgs; for (uint i = 0; i < g_strv_length(package_ids); i++) { if (_cancel) { break; } pi = package_ids[i]; if (pk_package_id_check(pi) == false) { pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, pi); delete m_apt; pk_backend_finished (backend); return false; } pair<pkgCache::PkgIterator, pkgCache::VerIterator> pkg_ver; pkg_ver = m_apt->find_package_id(pi); // Ignore packages that could not be found or that exist only due to dependencies. if (pkg_ver.second.end() == true) { pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "couldn't find package"); delete m_apt; pk_backend_finished (backend); return false; } else { pkgs.push_back(pkg_ver); } } if (!m_apt->runTransaction(pkgs, simulate, remove)) { // Print transaction errors cout << "runTransaction failed" << endl; delete m_apt; pk_backend_finished (backend); return false; } delete m_apt; pk_backend_finished (backend); return true; }