diff options
author | Daniel Nicoletti <dantti12@gmail.com> | 2012-04-15 11:50:12 -0300 |
---|---|---|
committer | Daniel Nicoletti <dantti12@gmail.com> | 2012-04-15 11:50:43 -0300 |
commit | 851c7b33506481884ef958f4250dda5dc17d7219 (patch) | |
tree | c563fd6cb32dd3ae7e63d16d7968916d8edf7959 | |
parent | cfe98c7ac7033feafa2fb4bc5e73b36fb9c2d188 (diff) |
aptcc: Add AptCacheFile to handle all pkg cache openings
-rw-r--r-- | backends/aptcc/AptCacheFile.cpp | 47 | ||||
-rw-r--r-- | backends/aptcc/AptCacheFile.h | 41 | ||||
-rw-r--r-- | backends/aptcc/Makefile.am | 3 | ||||
-rw-r--r-- | backends/aptcc/apt-intf.cpp | 78 | ||||
-rw-r--r-- | backends/aptcc/apt-intf.h | 24 | ||||
-rw-r--r-- | backends/aptcc/pk-backend-aptcc.cpp | 38 |
6 files changed, 164 insertions, 67 deletions
diff --git a/backends/aptcc/AptCacheFile.cpp b/backends/aptcc/AptCacheFile.cpp new file mode 100644 index 000000000..17e40cf75 --- /dev/null +++ b/backends/aptcc/AptCacheFile.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2012 Daniel Nicoletti <dantti12@gmail.com> + * Copyright (c) 2012 Matthias Klumpp <matthias@tenstral.net> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#include "AptCacheFile.h" + +AptCacheFile::AptCacheFile() +{ +} + +bool AptCacheFile::open(bool withLock) +{ + // TODO maybe subclass this to show more info when opening + OpTextProgress opTextProgress(*_config); + if (pkgCacheFile::Open(&opTextProgress, withLock) == false) { + return false; + } + + // Generate it and map it + // TODO for what we need this??? +// bool Res = pkgMakeStatusCache(GetSourceList(), opTextProgress, &Map, true); +// Progress.Done(); +// if(!Res) { +// return false; +// //"The package lists or status file could not be parsed or opened." +// } + + // Create the text record parser + m_packageRecords = new pkgRecords(*this); +} + + diff --git a/backends/aptcc/AptCacheFile.h b/backends/aptcc/AptCacheFile.h new file mode 100644 index 000000000..f782551ac --- /dev/null +++ b/backends/aptcc/AptCacheFile.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2012 Daniel Nicoletti <dantti12@gmail.com> + * Copyright (c) 2012 Matthias Klumpp <matthias@tenstral.net> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef APTCACHEFILE_H +#define APTCACHEFILE_H + +#include <apt-pkg/cachefile.h> + +class AptCacheFile : public pkgCacheFile +{ +public: + AptCacheFile(); + + /** + * Inits the package cache returning false if it can't open + */ + bool open(bool withLock = false); + + inline pkgRecords* GetPkgRecords() { BuildDepCache(); return m_packageRecords; } + +private: + pkgRecords *m_packageRecords; +}; + +#endif // APTCACHEFILE_H diff --git a/backends/aptcc/Makefile.am b/backends/aptcc/Makefile.am index 0a4f5cd43..25b36a53b 100644 --- a/backends/aptcc/Makefile.am +++ b/backends/aptcc/Makefile.am @@ -13,6 +13,7 @@ libpk_backend_aptcc_la_SOURCES = pkg_acqfile.cpp \ apt-utils.cpp \ apt-sourceslist.cpp \ apt-intf.cpp \ + AptCacheFile.cpp \ pk-backend-aptcc.cpp libpk_backend_aptcc_la_LIBADD = -lcrypt -lapt-pkg -lapt-inst $(PK_PLUGIN_LIBS) libpk_backend_aptcc_la_LDFLAGS = -module -avoid-version $(APTCC_LIBS) $(GSTREAMER_LIBS) @@ -31,7 +32,7 @@ EXTRA_DIST = 20packagekit \ deb-file.h \ apt-messages.h \ acqpkitstatus.h \ - pkg_dpkgpm.h \ + AptCacheFile.h \ pkg_acqfile.h helperdir = $(datadir)/PackageKit/helpers/aptcc diff --git a/backends/aptcc/apt-intf.cpp b/backends/aptcc/apt-intf.cpp index bd3661372..2a781b5a3 100644 --- a/backends/aptcc/apt-intf.cpp +++ b/backends/aptcc/apt-intf.cpp @@ -182,14 +182,12 @@ void AptIntf::cancel() } } -pkgCache::VerIterator AptIntf::findPackageId(const gchar *package_id, bool &found) +pkgCache::VerIterator AptIntf::findPackageId(const gchar *packageId) { gchar **parts; pkgCache::PkgIterator pkg; - found = true; - - parts = pk_package_id_split (package_id); + parts = pk_package_id_split(packageId); gchar *pkgNameArch; pkgNameArch = g_strdup_printf("%s:%s", parts[PK_PACKAGE_ID_NAME], parts[PK_PACKAGE_ID_ARCH]); pkg = packageCache->FindPkg(pkgNameArch); @@ -202,7 +200,7 @@ pkgCache::VerIterator AptIntf::findPackageId(const gchar *package_id, bool &foun return pkgCache::VerIterator(); } - const pkgCache::VerIterator &ver = find_ver(pkg); + const pkgCache::VerIterator &ver = findVer(pkg); // check to see if the provided package isn't virtual too if (ver.end() == false && strcmp(ver.VerStr(), parts[PK_PACKAGE_ID_VERSION]) == 0) { @@ -210,7 +208,7 @@ pkgCache::VerIterator AptIntf::findPackageId(const gchar *package_id, bool &foun return ver; } - const pkgCache::VerIterator &candidateVer = find_candidate_ver(pkg); + const pkgCache::VerIterator &candidateVer = findCandidateVer(pkg); // check to see if the provided package isn't virtual too if (candidateVer.end() == false && strcmp(candidateVer.VerStr(), parts[PK_PACKAGE_ID_VERSION]) == 0) { @@ -218,19 +216,12 @@ pkgCache::VerIterator AptIntf::findPackageId(const gchar *package_id, bool &foun return candidateVer; } - found = false; g_strfreev (parts); return ver; } -pkgCache::VerIterator AptIntf::find_candidate_ver(const pkgCache::PkgIterator &pkg) -{ - // get the candidate version iterator - return (*packageDepCache)[pkg].CandidateVerIter(*packageDepCache); -} - -pkgCache::VerIterator AptIntf::find_ver(const pkgCache::PkgIterator &pkg) +pkgCache::VerIterator AptIntf::findVer(const pkgCache::PkgIterator &pkg) { // if the package is installed return the current version if (!pkg.CurrentVer().end()) { @@ -238,7 +229,7 @@ pkgCache::VerIterator AptIntf::find_ver(const pkgCache::PkgIterator &pkg) } // Else get the candidate version iterator - const pkgCache::VerIterator &candidateVer = find_candidate_ver(pkg); + const pkgCache::VerIterator &candidateVer = findCandidateVer(pkg); if (!candidateVer.end()) { return candidateVer; } @@ -247,6 +238,12 @@ pkgCache::VerIterator AptIntf::find_ver(const pkgCache::PkgIterator &pkg) return pkg.VersionList(); } +pkgCache::VerIterator AptIntf::findCandidateVer(const pkgCache::PkgIterator &pkg) +{ + // get the candidate version iterator + return (*packageDepCache)[pkg].CandidateVerIter(*packageDepCache); +} + bool AptIntf::matchPackage(const pkgCache::VerIterator &ver, PkBitfield filters) { if (filters != 0) { @@ -491,9 +488,9 @@ void AptIntf::providesCodec(PkgList &output, gchar **values) // TODO search in updates packages // Ignore virtual packages - pkgCache::VerIterator ver = find_ver(pkg); + pkgCache::VerIterator ver = findVer(pkg); if (ver.end() == true) { - ver = find_candidate_ver(pkg); + ver = findCandidateVer(pkg); if (ver.end() == true) { continue; } @@ -563,9 +560,9 @@ void AptIntf::providesLibrary(PkgList &output, gchar **values) } // TODO: Ignore virtual packages - pkgCache::VerIterator ver = find_ver (pkg); + pkgCache::VerIterator ver = findVer (pkg); if (ver.end() == true) { - ver = find_candidate_ver(pkg); + ver = findCandidateVer(pkg); if (ver.end() == true) { continue; } @@ -647,7 +644,7 @@ void AptIntf::emitUpdateDetails(const pkgCache::VerIterator &version) { const pkgCache::PkgIterator &pkg = version.ParentPkg(); // Get the version of the current package - const pkgCache::VerIterator &currver = find_ver(pkg); + const pkgCache::VerIterator &currver = findVer(pkg); const pkgCache::VerFileIterator &currvf = currver.FileList(); // Build a package_id from the current version gchar *current_package_id; @@ -661,7 +658,7 @@ void AptIntf::emitUpdateDetails(const pkgCache::VerIterator &version) if (version.end() == false) { candver = version; } else { - candver = find_candidate_ver(pkg); + candver = findCandidateVer(pkg); } pkgCache::VerFileIterator vf = candver.FileList(); @@ -904,7 +901,7 @@ void AptIntf::getDepends(PkgList &output, break; } - const pkgCache::VerIterator &ver = find_ver(dep.TargetPkg()); + const pkgCache::VerIterator &ver = findVer(dep.TargetPkg()); // Ignore packages that exist only due to dependencies. if (ver.end()) { dep++; @@ -941,7 +938,7 @@ void AptIntf::getRequires(PkgList &output, } // Don't insert virtual packages instead add what it provides - const pkgCache::VerIterator &parentVer = find_ver(parentPkg); + const pkgCache::VerIterator &parentVer = findVer(parentPkg); if (parentVer.end() == false) { PkgList deps; getDepends(deps, parentVer, false); @@ -1357,16 +1354,16 @@ void AptIntf::emitChangedPackages(pkgCacheFile &Cache) for (pkgCache::PkgIterator pkg = Cache->PkgBegin(); ! pkg.end(); ++pkg) { if (Cache[pkg].NewInstall() == true) { // installing - installing.push_back(find_candidate_ver(pkg)); + installing.push_back(findCandidateVer(pkg)); } else if (Cache[pkg].Delete() == true) { // removing - removing.push_back(find_ver(pkg)); + removing.push_back(findVer(pkg)); } else if (Cache[pkg].Upgrade() == true) { // updating - updating.push_back(find_candidate_ver(pkg)); + updating.push_back(findCandidateVer(pkg)); } else if (Cache[pkg].Downgrade() == true) { // downgrading - downgrading.push_back(find_candidate_ver(pkg)); + downgrading.push_back(findCandidateVer(pkg)); } } @@ -1382,16 +1379,16 @@ void AptIntf::populateInternalPackages(pkgCacheFile &Cache) for (pkgCache::PkgIterator pkg = Cache->PkgBegin(); ! pkg.end(); ++pkg) { if (Cache[pkg].NewInstall() == true) { // installing - m_pkgs.push_back(find_candidate_ver(pkg)); + m_pkgs.push_back(findCandidateVer(pkg)); } else if (Cache[pkg].Delete() == true) { // removing - m_pkgs.push_back(find_ver(pkg)); + m_pkgs.push_back(findVer(pkg)); } else if (Cache[pkg].Upgrade() == true) { // updating - m_pkgs.push_back(find_candidate_ver(pkg)); + m_pkgs.push_back(findCandidateVer(pkg)); } else if (Cache[pkg].Downgrade() == true) { // downgrading - m_pkgs.push_back(find_candidate_ver(pkg)); + m_pkgs.push_back(findCandidateVer(pkg)); } } } @@ -1412,13 +1409,13 @@ void AptIntf::emitTransactionPackage(string name, PkInfoEnum state) return; } - const pkgCache::VerIterator &ver = find_ver(pkg); + const pkgCache::VerIterator &ver = findVer(pkg); // check to see if the provided package isn't virtual too if (ver.end() == false) { emitPackage(ver, PK_FILTER_ENUM_NONE, state); } - const pkgCache::VerIterator &candidateVer = find_candidate_ver(pkg); + const pkgCache::VerIterator &candidateVer = findCandidateVer(pkg); // check to see if we found the package if (candidateVer.end() == false) { emitPackage(candidateVer, PK_FILTER_ENUM_NONE, state); @@ -1791,13 +1788,13 @@ PkgList AptIntf::resolvePI(gchar **package_ids, PkBitfield filters) continue; } - const pkgCache::VerIterator &ver = find_ver(pkg); + const pkgCache::VerIterator &ver = findVer(pkg); // check to see if the provided package isn't virtual too if (ver.end() == false) { ret.push_back(ver); } - const pkgCache::VerIterator &candidateVer = find_candidate_ver(pkg); + const pkgCache::VerIterator &candidateVer = findCandidateVer(pkg); // check to see if the provided package isn't virtual too if (candidateVer.end() == false) { ret.push_back(candidateVer); @@ -1810,23 +1807,22 @@ PkgList AptIntf::resolvePI(gchar **package_ids, PkBitfield filters) continue; } - const pkgCache::VerIterator &ver = find_ver(pkg); + const pkgCache::VerIterator &ver = findVer(pkg); // check to see if the provided package isn't virtual too if (ver.end() == false) { ret.push_back(ver); } - const pkgCache::VerIterator &candidateVer = find_candidate_ver(pkg); + const pkgCache::VerIterator &candidateVer = findCandidateVer(pkg); // check to see if the provided package isn't virtual too if (candidateVer.end() == false) { ret.push_back(candidateVer); } } } else { - bool found; - const pkgCache::VerIterator &ver = findPackageId(pi, found); + const pkgCache::VerIterator &ver = findPackageId(pi); // check to see if we found the package - if (found) { + if (!ver.end()) { ret.push_back(ver); } } @@ -2220,7 +2216,7 @@ bool AptIntf::installPackages(pkgCacheFile &Cache, bool simulating) } pkgCache::VerIterator ver = Cache[pkg].InstVerIter(Cache); - if (ver.end() && (ver = find_candidate_ver(pkg))) { + if (ver.end() && (ver = findCandidateVer(pkg))) { // Ignore invalid versions continue; } diff --git a/backends/aptcc/apt-intf.h b/backends/aptcc/apt-intf.h index d4feae11d..f3735608a 100644 --- a/backends/aptcc/apt-intf.h +++ b/backends/aptcc/apt-intf.h @@ -59,11 +59,25 @@ public: bool init(); void cancel(); - // Check the returned VerIterator.end() - // if it's true we could not find it - pkgCache::VerIterator findPackageId(const gchar *package_id, bool &found); - pkgCache::VerIterator find_ver(const pkgCache::PkgIterator &pkg); - pkgCache::VerIterator find_candidate_ver(const pkgCache::PkgIterator &pkg); + /** + * Tries to find a package with the given packageId + * @returns pkgCache::VerIterator that if .end() is true the package could not be found + */ + pkgCache::VerIterator findPackageId(const gchar *packageId); + + /** + * Tries to find the current version of a package + * if it can't find it will return the candidate + * TODO check if we really need the candidate version + * @returns pkgCache::VerIterator that if .end() is true the version could not be found + */ + pkgCache::VerIterator findVer(const pkgCache::PkgIterator &pkg); + + /** + * Tries to find the candidate version of a package + * @returns pkgCache::VerIterator that if .end() is true the version could not be found + */ + pkgCache::VerIterator findCandidateVer(const pkgCache::PkgIterator &pkg); PkgList resolvePI(gchar **package_ids, PkBitfield filters = PK_FILTER_ENUM_NONE); bool markFileForInstall(const gchar *file, PkgList &install, PkgList &remove); diff --git a/backends/aptcc/pk-backend-aptcc.cpp b/backends/aptcc/pk-backend-aptcc.cpp index 2d38dea05..f66cdf130 100644 --- a/backends/aptcc/pk-backend-aptcc.cpp +++ b/backends/aptcc/pk-backend-aptcc.cpp @@ -30,6 +30,7 @@ #include <pk-backend-spawn.h> #include "apt-intf.h" +#include "AptCacheFile.h" #include "apt-utils.h" #include "matcher.h" #include "apt-messages.h" @@ -178,7 +179,7 @@ static gboolean backend_get_depends_or_requires_thread(PkBackend *backend) bool depends = pk_backend_get_bool(backend, "get_depends"); - pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY); + pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); PkgList output; for (uint i = 0; i < g_strv_length(package_ids); ++i) { if (_cancel) { @@ -193,9 +194,8 @@ static gboolean backend_get_depends_or_requires_thread(PkBackend *backend) return false; } - bool found; - const pkgCache::VerIterator &ver = m_apt->findPackageId(pi, found); - if (!found) { + const pkgCache::VerIterator &ver = m_apt->findPackageId(pi); + if (ver.end()) { pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "Couldn't find package"); @@ -278,9 +278,8 @@ static gboolean backend_get_files_thread(PkBackend *backend) return false; } - bool found; - m_apt->findPackageId(pi, found); - if (!found) { + const pkgCache::VerIterator &ver = m_apt->findPackageId(pi); + if (ver.end()) { pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "Couldn't find package"); delete m_apt; return false; @@ -414,11 +413,11 @@ static gboolean backend_get_or_update_system_thread (PkBackend *backend) ++pkg) { if ((*Cache)[pkg].Upgrade() == true && (*Cache)[pkg].NewInstall() == false) { - update.push_back(m_apt->find_candidate_ver(pkg)); + update.push_back(m_apt->findCandidateVer(pkg)); } else if ((*Cache)[pkg].Upgradable() == true && pkg->CurrentVer != 0 && (*Cache)[pkg].Delete() == false) { - kept.push_back(m_apt->find_candidate_ver(pkg)); + kept.push_back(m_apt->findCandidateVer(pkg)); } } @@ -506,7 +505,7 @@ static gboolean backend_what_provides_thread(PkBackend *backend) if (pkg.end() == true) { continue; } - const pkgCache::VerIterator &ver = m_apt->find_ver(pkg); + const pkgCache::VerIterator &ver = m_apt->findVer(pkg); if (ver.end() == true) { continue; } @@ -619,10 +618,9 @@ static gboolean pk_backend_download_packages_thread(PkBackend *backend) break; } - bool found; - const pkgCache::VerIterator &ver = m_apt->findPackageId(pi, found); + const pkgCache::VerIterator &ver = m_apt->findPackageId(pi); // Ignore packages that could not be found or that exist only due to dependencies. - if (!found) { + if (ver.end()) { _error->Error("Can't find this package id \"%s\".", pi); continue; } else { @@ -803,7 +801,7 @@ static gboolean pk_backend_search_files_thread(PkBackend *backend) if (pkg.end() == true) { continue; } - const pkgCache::VerIterator &ver = m_apt->find_ver(pkg); + const pkgCache::VerIterator &ver = m_apt->findVer(pkg); if (ver.end() == true) { continue; } @@ -871,7 +869,7 @@ static gboolean backend_search_groups_thread (PkBackend *backend) } // Ignore virtual packages - const pkgCache::VerIterator &ver = m_apt->find_ver(pkg); + const pkgCache::VerIterator &ver = m_apt->findVer(pkg); if (ver.end() == false) { string section = pkg.VersionList().Section() == NULL ? "" : pkg.VersionList().Section(); @@ -957,7 +955,7 @@ static gboolean backend_search_package_thread(PkBackend *backend) continue; } - const pkgCache::VerIterator &ver = m_apt->find_ver(pkg); + const pkgCache::VerIterator &ver = m_apt->findVer(pkg); if (ver.end() == false) { if (m_matcher->matches(pkg.Name()) || m_matcher->matches(get_long_description(ver, m_apt->packageRecords))) { @@ -970,7 +968,7 @@ static gboolean backend_search_package_thread(PkBackend *backend) // iterate over the provides list for (pkgCache::PrvIterator Prv = pkg.ProvidesList(); Prv.end() == false; ++Prv) { - const pkgCache::VerIterator &ownerVer = m_apt->find_ver(Prv.OwnerPkg()); + const pkgCache::VerIterator &ownerVer = m_apt->findVer(Prv.OwnerPkg()); // check to see if the provided package isn't virtual too if (ownerVer.end() == false) { @@ -993,13 +991,13 @@ static gboolean backend_search_package_thread(PkBackend *backend) if (m_matcher->matches(pkg.Name())) { // Don't insert virtual packages instead add what it provides - const pkgCache::VerIterator &ver = m_apt->find_ver(pkg); + const pkgCache::VerIterator &ver = m_apt->findVer(pkg); if (ver.end() == false) { output.push_back(ver); } else { // iterate over the provides list for (pkgCache::PrvIterator Prv = pkg.ProvidesList(); Prv.end() == false; ++Prv) { - const pkgCache::VerIterator &ownerVer = m_apt->find_ver(Prv.OwnerPkg()); + const pkgCache::VerIterator &ownerVer = m_apt->findVer(Prv.OwnerPkg()); // check to see if the provided package isn't virtual too if (ownerVer.end() == false) @@ -1362,7 +1360,7 @@ static gboolean backend_get_packages_thread(PkBackend *backend) } // Don't insert virtual packages as they don't have all kinds of info - const pkgCache::VerIterator &ver = m_apt->find_ver(pkg); + const pkgCache::VerIterator &ver = m_apt->findVer(pkg); if (ver.end() == false) { output.push_back(ver); } |