summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Nicoletti <dantti12@gmail.com>2012-04-16 01:43:36 -0300
committerDaniel Nicoletti <dantti12@gmail.com>2012-04-16 01:43:36 -0300
commit6e57f354aeca30538351acdc2fca7ddd76c0b8ad (patch)
tree5f41796afd8e6adb7cfeb8090b18e619a179df12
parent3edfc7d9c81df85e1244781abb1890ad9332877d (diff)
aptcc: Improve classes readability, and fix a crash caused by an invalid package
-rw-r--r--backends/aptcc/acqpkitstatus.cpp6
-rw-r--r--backends/aptcc/apt-intf.cpp213
-rw-r--r--backends/aptcc/apt-intf.h132
-rw-r--r--backends/aptcc/pk-backend-aptcc.cpp156
4 files changed, 277 insertions, 230 deletions
diff --git a/backends/aptcc/acqpkitstatus.cpp b/backends/aptcc/acqpkitstatus.cpp
index fb6a47cb..3e306871 100644
--- a/backends/aptcc/acqpkitstatus.cpp
+++ b/backends/aptcc/acqpkitstatus.cpp
@@ -20,6 +20,8 @@
#include "acqpkitstatus.h"
+#include "pkg_acqfile.h"
+
#include <apt-pkg/acquire-item.h>
#include <apt-pkg/acquire-worker.h>
#include <apt-pkg/strutl.h>
@@ -248,9 +250,7 @@ void AcqPackageKitStatus::emit_package(const string &name, bool finished)
// try to see if any package matches
if (name.compare(it->ParentPkg().Name()) == 0) {
- m_apt->emitPackage(*it,
- PK_INFO_ENUM_UNKNOWN,
- finished ? PK_INFO_ENUM_FINISHED : PK_INFO_ENUM_DOWNLOADING);
+ m_apt->emitPackage(*it, finished ? PK_INFO_ENUM_FINISHED : PK_INFO_ENUM_DOWNLOADING);
last_package_name = name;
// Find the downloading item
diff --git a/backends/aptcc/apt-intf.cpp b/backends/aptcc/apt-intf.cpp
index d6a030ba..2b27262c 100644
--- a/backends/aptcc/apt-intf.cpp
+++ b/backends/aptcc/apt-intf.cpp
@@ -178,11 +178,7 @@ pkgCache::VerIterator AptIntf::findVer(const pkgCache::PkgIterator &pkg)
pkgCache::VerIterator AptIntf::findCandidateVer(const pkgCache::PkgIterator &pkg)
{
// get the candidate version iterator
- pkgCache::VerIterator ret;
- if (m_cache.open()) {
- ret = m_cache[pkg].CandidateVerIter(m_cache);
- }
- return ret;
+ return (*m_cache.GetDepCache())[pkg].CandidateVerIter(m_cache);
}
bool AptIntf::matchPackage(const pkgCache::VerIterator &ver, PkBitfield filters)
@@ -309,14 +305,8 @@ PkgList AptIntf::filterPackages(PkgList &packages, PkBitfield filters)
// used to emit packages it collects all the needed info
void AptIntf::emitPackage(const pkgCache::VerIterator &ver,
- PkBitfield filters,
PkInfoEnum state)
{
- // Check if the filters match the package
- if (!matchPackage(ver, filters)) {
- return;
- }
-
const pkgCache::PkgIterator &pkg = ver.ParentPkg();
// check the state enum to see if it was not set.
@@ -343,9 +333,7 @@ void AptIntf::emitPackage(const pkgCache::VerIterator &ver,
g_free(package_id);
}
-void AptIntf::emit_packages(PkgList &output,
- PkBitfield filters,
- PkInfoEnum state)
+void AptIntf::emitPackages(PkgList &output, PkBitfield filters, PkInfoEnum state)
{
// Sort so we can remove the duplicated entries
sort(output.begin(), output.end(), compare());
@@ -361,7 +349,9 @@ void AptIntf::emit_packages(PkgList &output,
break;
}
- emitPackage(*it, filters, state);
+ if (matchPackage(*it, filters)) {
+ emitPackage(*it, state);
+ }
}
}
@@ -381,6 +371,10 @@ void AptIntf::emitUpdates(PkgList &output, PkBitfield filters)
break;
}
+ if (!matchPackage(*i, filters)) {
+ continue;
+ }
+
// the default update info
state = PK_INFO_ENUM_NORMAL;
@@ -404,7 +398,7 @@ void AptIntf::emitUpdates(PkgList &output, PkBitfield filters)
state = PK_INFO_ENUM_ENHANCEMENT;
}
- emitPackage(*i, filters, state);
+ emitPackage(*i, state);
}
}
@@ -456,7 +450,7 @@ void AptIntf::providesLibrary(PkgList &output, gchar **values)
bool ret = false;
// Quick-check for library names
for (uint i = 0; i < g_strv_length(values); i++) {
- if (g_str_has_prefix (values[i], "lib")) {
+ if (g_str_has_prefix(values[i], "lib")) {
ret = true;
break;
}
@@ -502,9 +496,9 @@ void AptIntf::providesLibrary(PkgList &output, gchar **values)
// TODO: Ignore virtual packages
pkgCache::VerIterator ver = findVer (pkg);
- if (ver.end() == true) {
+ if (ver.end()) {
ver = findCandidateVer(pkg);
- if (ver.end() == true) {
+ if (ver.end()) {
continue;
}
}
@@ -607,12 +601,13 @@ bool AptIntf::getArchive(pkgAcquire *Owner,
}
// used to emit packages it collects all the needed info
-void AptIntf::emitDetails(const pkgCache::VerIterator &ver)
+void AptIntf::emitPackageDetail(const pkgCache::VerIterator &ver)
{
- const pkgCache::PkgIterator &pkg = ver.ParentPkg();
if (ver.end() == true) {
return;
}
+
+ const pkgCache::PkgIterator &pkg = ver.ParentPkg();
std::string section = ver.Section() == NULL ? "" : ver.Section();
size_t found;
@@ -655,19 +650,26 @@ void AptIntf::emitDetails(PkgList &pkgs)
pkgs.erase(unique(pkgs.begin(), pkgs.end(), result_equality()),
pkgs.end());
- for(PkgList::iterator i = pkgs.begin(); i != pkgs.end(); ++i) {
+ for (PkgList::iterator i = pkgs.begin(); i != pkgs.end(); ++i) {
if (m_cancel) {
break;
}
- emitDetails(*i);
+ emitPackageDetail(*i);
}
}
// used to emit packages it collects all the needed info
-void AptIntf::emitUpdateDetails(const pkgCache::VerIterator &version)
+void AptIntf::emitUpdateDetail(const pkgCache::VerIterator &candver)
{
- const pkgCache::PkgIterator &pkg = version.ParentPkg();
+ // Verify if our update version is valid
+ if (candver.end()) {
+ // No candidate version was provided
+ return;
+ }
+
+ const pkgCache::PkgIterator &pkg = candver.ParentPkg();
+
// Get the version of the current package
const pkgCache::VerIterator &currver = findVer(pkg);
const pkgCache::VerFileIterator &currvf = currver.FileList();
@@ -678,14 +680,6 @@ void AptIntf::emitUpdateDetails(const pkgCache::VerIterator &version)
currver.Arch(),
currvf.File().Archive() == NULL ? "" : currvf.File().Archive());
- // Get the update version
- pkgCache::VerIterator candver;
- if (version.end() == false) {
- candver = version;
- } else {
- candver = findCandidateVer(pkg);
- }
-
pkgCache::VerFileIterator vf = candver.FileList();
string origin = vf.File().Origin() == NULL ? "" : vf.File().Origin();
pkgRecords::Parser &rec = m_cache.GetPkgRecords()->Lookup(candver.FileList());
@@ -907,12 +901,12 @@ void AptIntf::emitUpdateDetails(const pkgCache::VerIterator &version)
void AptIntf::emitUpdateDetails(PkgList &pkgs)
{
- for(PkgList::iterator i = pkgs.begin(); i != pkgs.end(); ++i) {
+ for (PkgList::iterator it = pkgs.begin(); it != pkgs.end(); ++it) {
if (m_cancel) {
break;
}
- emitUpdateDetails(*i);
+ emitUpdateDetail(*it);
}
}
@@ -934,13 +928,10 @@ void AptIntf::getDepends(PkgList &output,
} else if (dep->Type == pkgCache::Dep::Depends) {
if (recursive) {
if (!contains(output, dep.TargetPkg())) {
- // TODO is this still working
- // output.push_back(PkgPair(dep.TargetPkg(), ver));
output.push_back(ver);
getDepends(output, ver, recursive);
}
} else {
- // output.push_back(PkgPair(dep.TargetPkg(), ver));
output.push_back(ver);
}
}
@@ -968,16 +959,13 @@ void AptIntf::getRequires(PkgList &output,
PkgList deps;
getDepends(deps, parentVer, false);
for (PkgList::iterator it = deps.begin(); it != deps.end(); ++it) {
- // if (i->ParentPkg() == ver) { TODO make sure this works!!!!
if (*it == ver) {
if (recursive) {
if (!contains(output, parentPkg)) {
- // output.push_back(PkgPair(parentPkg, ver));
output.push_back(parentVer);
getRequires(output, parentVer, recursive);
}
} else {
- // output.push_back(PkgPair(parentPkg, ver));
output.push_back(parentVer);
}
break;
@@ -1010,9 +998,26 @@ PkgList AptIntf::getPackages()
return output;
}
-PkgList AptIntf::getPackagesFromGroup(vector<PkGroupEnum> &groups)
+PkgList AptIntf::getPackagesFromGroup(gchar **values)
{
PkgList output;
+ vector<PkGroupEnum> groups;
+
+ int len = g_strv_length(values);
+ for (uint i = 0; i < len; i++) {
+ if (values[i] == NULL) {
+ pk_backend_error_code(m_backend,
+ PK_ERROR_ENUM_GROUP_NOT_FOUND,
+ values[i]);
+ pk_backend_finished(m_backend);
+ return output;
+ } else {
+ groups.push_back(pk_group_enum_from_string(values[i]));
+ }
+ }
+
+ pk_backend_set_allow_cancel(m_backend, true);
+
for (pkgCache::PkgIterator pkg = m_cache.GetPkgCache()->PkgBegin(); !pkg.end(); ++pkg) {
if (m_cancel) {
break;
@@ -1095,7 +1100,7 @@ PkgList AptIntf::searchPackageDetails(Matcher *matcher)
const pkgCache::VerIterator &ver = findVer(pkg);
if (ver.end() == false) {
if (matcher->matches(pkg.Name()) ||
- matcher->matches(getPackageLongDescription(ver))) {
+ matcher->matches(get_long_description(ver, m_cache.GetPkgRecords()))) {
// The package matched
output.push_back(ver);
}
@@ -1119,15 +1124,11 @@ PkgList AptIntf::searchPackageDetails(Matcher *matcher)
return output;
}
-string AptIntf::getPackageLongDescription(const pkgCache::VerIterator &ver)
-{
- return get_long_description(ver, m_cache.GetPkgRecords());
-}
-
// used to return files it reads, using the info from the files in /var/lib/dpkg/info/
-vector<string> search_files (PkBackend *backend, gchar **values, bool &m_cancel)
+PkgList AptIntf::searchPackageFiles(gchar **values)
{
- vector<string> packageList;
+ PkgList output;
+ vector<string> packages;
regex_t re;
gchar *search;
gchar *values_str;
@@ -1139,7 +1140,7 @@ vector<string> search_files (PkBackend *backend, gchar **values, bool &m_cancel)
if(regcomp(&re, search, REG_NOSUB) != 0) {
g_debug("Regex compilation error");
g_free(search);
- return vector<string>();
+ return output;
}
g_free(search);
@@ -1148,7 +1149,7 @@ vector<string> search_files (PkBackend *backend, gchar **values, bool &m_cancel)
if (!(dp = opendir("/var/lib/dpkg/info/"))) {
g_debug ("Error opening /var/lib/dpkg/info/\n");
regfree(&re);
- return vector<string>();
+ return output;
}
string line;
@@ -1166,7 +1167,7 @@ vector<string> search_files (PkBackend *backend, gchar **values, bool &m_cancel)
getline(in, line);
if (regexec(&re, line.c_str(), (size_t)0, NULL, 0) == 0) {
string file(dirp->d_name);
- packageList.push_back(file.erase(file.size() - 5, file.size()));
+ packages.push_back(file.erase(file.size() - 5, file.size()));
break;
}
}
@@ -1174,13 +1175,30 @@ vector<string> search_files (PkBackend *backend, gchar **values, bool &m_cancel)
}
closedir(dp);
regfree(&re);
- return packageList;
+
+ // Resolve the package names now
+ for (vector<string>::iterator it = packages.begin();
+ it != packages.end(); ++it) {
+ if (m_cancel) {
+ break;
+ }
+ const pkgCache::PkgIterator &pkg = findPackage(*it);
+ if (pkg.end() == true) {
+ continue;
+ }
+ const pkgCache::VerIterator &ver = findVer(pkg);
+ if (ver.end() == true) {
+ continue;
+ }
+ output.push_back(ver);
+ }
+
+ return output;
}
// used to return files it reads, using the info from the files in /var/lib/dpkg/info/
-vector<string> searchMimeType (PkBackend *backend, gchar **values, bool &error, bool &m_cancel)
+void AptIntf::providesMimeType(PkgList &output, gchar **values)
{
- vector<string> packageList;
regex_t re;
gchar *value;
gchar *values_str;
@@ -1193,7 +1211,7 @@ vector<string> searchMimeType (PkBackend *backend, gchar **values, bool &error,
if(regcomp(&re, value, REG_NOSUB) != 0) {
g_debug("Regex compilation error");
g_free(value);
- return vector<string>();
+ return;
}
g_free(value);
@@ -1202,10 +1220,10 @@ vector<string> searchMimeType (PkBackend *backend, gchar **values, bool &error,
if (!(dp = opendir("/usr/share/app-install/desktop/"))) {
g_debug ("Error opening /usr/share/app-install/desktop/\n");
regfree(&re);
- error = true;
- return vector<string>();
+ return;
}
+ vector<string> packages;
string line;
while ((dirp = readdir(dp)) != NULL) {
if (m_cancel) {
@@ -1223,7 +1241,7 @@ vector<string> searchMimeType (PkBackend *backend, gchar **values, bool &error,
if (getName) {
if (starts_with(line, "X-AppInstall-Package=")) {
// Remove the X-AppInstall-Package=
- packageList.push_back(line.substr(21));
+ packages.push_back(line.substr(21));
break;
}
} else {
@@ -1238,17 +1256,33 @@ vector<string> searchMimeType (PkBackend *backend, gchar **values, bool &error,
closedir(dp);
regfree(&re);
- return packageList;
+
+ // resolve the package names
+ for (vector<string>::iterator it = packages.begin();
+ it != packages.end(); ++it) {
+ if (m_cancel) {
+ break;
+ }
+ const pkgCache::PkgIterator &pkg = findPackage(*it);
+ if (pkg.end() == true) {
+ continue;
+ }
+ const pkgCache::VerIterator &ver = findVer(pkg);
+ if (ver.end() == true) {
+ continue;
+ }
+ output.push_back(ver);
+ }
}
// used to emit files it reads the info directly from the files
-void AptIntf::emitFiles(PkBackend *backend, const gchar *pi)
+void AptIntf::emitPackageFiles(const gchar *pi)
{
static string filelist;
string line;
gchar **parts;
- parts = pk_package_id_split (pi);
+ parts = pk_package_id_split(pi);
filelist.erase(filelist.begin(), filelist.end());
string fName;
@@ -1288,7 +1322,7 @@ void AptIntf::emitFiles(PkBackend *backend, const gchar *pi)
}
if (!filelist.empty()) {
- pk_backend_files (backend, pi, filelist.c_str());
+ pk_backend_files(m_backend, pi, filelist.c_str());
}
}
}
@@ -1346,7 +1380,7 @@ bool AptIntf::checkTrusted(pkgAcquire &fetcher, bool simulating)
if (untrusted.empty()) {
return true;
} else if (simulating) {
- emit_packages(untrusted, PK_FILTER_ENUM_NONE, PK_INFO_ENUM_UNTRUSTED);
+ emitPackages(untrusted, PK_FILTER_ENUM_NONE, PK_INFO_ENUM_UNTRUSTED);
}
if (pk_backend_get_bool(m_backend, "only_trusted") == false ||
@@ -1512,28 +1546,39 @@ void AptIntf::emitChangedPackages(AptCacheFile &cache)
PkgList updating;
PkgList downgrading;
- string VersionsList;
for (pkgCache::PkgIterator pkg = cache->PkgBegin(); ! pkg.end(); ++pkg) {
if (cache[pkg].NewInstall() == true) {
- // installing
- installing.push_back(findCandidateVer(pkg));
+ // installing;
+ const pkgCache::VerIterator &ver = findCandidateVer(pkg);
+ if (!ver.end()) {
+ installing.push_back(ver);
+ }
} else if (cache[pkg].Delete() == true) {
// removing
- removing.push_back(findVer(pkg));
+ const pkgCache::VerIterator &ver = findVer(pkg);
+ if (!ver.end()) {
+ removing.push_back(ver);
+ }
} else if (cache[pkg].Upgrade() == true) {
// updating
- updating.push_back(findCandidateVer(pkg));
+ const pkgCache::VerIterator &ver = findCandidateVer(pkg);
+ if (!ver.end()) {
+ updating.push_back(ver);
+ }
} else if (cache[pkg].Downgrade() == true) {
// downgrading
- downgrading.push_back(findCandidateVer(pkg));
+ const pkgCache::VerIterator &ver = findVer(pkg);
+ if (!ver.end()) {
+ downgrading.push_back(ver);
+ }
}
}
// emit packages that have changes
- emit_packages(removing, PK_FILTER_ENUM_NONE, PK_INFO_ENUM_REMOVING);
- emit_packages(downgrading, PK_FILTER_ENUM_NONE, PK_INFO_ENUM_DOWNGRADING);
- emit_packages(installing, PK_FILTER_ENUM_NONE, PK_INFO_ENUM_INSTALLING);
- emit_packages(updating, PK_FILTER_ENUM_NONE, PK_INFO_ENUM_UPDATING);
+ emitPackages(removing, PK_FILTER_ENUM_NONE, PK_INFO_ENUM_REMOVING);
+ emitPackages(downgrading, PK_FILTER_ENUM_NONE, PK_INFO_ENUM_DOWNGRADING);
+ emitPackages(installing, PK_FILTER_ENUM_NONE, PK_INFO_ENUM_INSTALLING);
+ emitPackages(updating, PK_FILTER_ENUM_NONE, PK_INFO_ENUM_UPDATING);
}
void AptIntf::populateInternalPackages(AptCacheFile &cache)
@@ -1557,9 +1602,9 @@ void AptIntf::populateInternalPackages(AptCacheFile &cache)
void AptIntf::emitTransactionPackage(string name, PkInfoEnum state)
{
- for (PkgList::iterator i = m_pkgs.begin(); i != m_pkgs.end(); ++i) {
- if (i->ParentPkg().Name() == name) {
- emitPackage(*i, PK_FILTER_ENUM_NONE, state);
+ for (PkgList::iterator it = m_pkgs.begin(); it != m_pkgs.end(); ++it) {
+ if (it->ParentPkg().Name() == name) {
+ emitPackage(*it, state);
return;
}
}
@@ -1574,13 +1619,13 @@ void AptIntf::emitTransactionPackage(string name, PkInfoEnum state)
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);
+ emitPackage(ver, state);
}
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);
+ emitPackage(candidateVer, state);
}
}
@@ -1718,6 +1763,7 @@ void AptIntf::updateInterface(int fd, int writeFd)
// TODO we need a DPKG patch to use debconf
g_debug("Failed to write");
}
+ g_free(confmsg);
}
} else if (strstr(status, "pmstatus") != NULL) {
// INSTALL & UPDATE
@@ -1909,7 +1955,7 @@ bool AptIntf::doAutomaticRemove(AptCacheFile &cache)
return true;
}
-PkgList AptIntf::resolvePI(gchar **package_ids, PkBitfield filters)
+PkgList AptIntf::resolvePackageIds(gchar **package_ids, PkBitfield filters)
{
gchar *pi;
PkgList ret;
@@ -2079,7 +2125,7 @@ bool AptIntf::markFileForInstall(const gchar *file, PkgList &install, PkgList &r
PK_FILTER_ENUM_NOT_INSTALLED,
PK_FILTER_ENUM_ARCH,
-1);
- install = resolvePI(installPkgs, intallFilters);
+ install = resolvePackageIds(installPkgs, intallFilters);
// Resolve the packages to remove
PkBitfield removeFilters;
@@ -2087,8 +2133,7 @@ bool AptIntf::markFileForInstall(const gchar *file, PkgList &install, PkgList &r
PK_FILTER_ENUM_INSTALLED,
PK_FILTER_ENUM_ARCH,
-1);
- remove = resolvePI(removePkgs, removeFilters);
- m_localDebFile = file;
+ remove = resolvePackageIds(removePkgs, removeFilters);
g_strfreev(lines);
g_strfreev(installPkgs);
diff --git a/backends/aptcc/apt-intf.h b/backends/aptcc/apt-intf.h
index add4f7df..4da7ba9e 100644
--- a/backends/aptcc/apt-intf.h
+++ b/backends/aptcc/apt-intf.h
@@ -37,23 +37,12 @@
using namespace std;
-/**
- * returns a list of packages names
- */
-vector<string> search_files (PkBackend *backend, gchar **values, bool &_cancel);
-
-/**
- * returns a list of packages names
- */
-vector<string> searchMimeType (PkBackend *backend, gchar **values, bool &error, bool &_cancel);
-
typedef vector<pkgCache::VerIterator> PkgList;
class pkgProblemResolver;
class Matcher;
class AptIntf
{
-
public:
AptIntf(PkBackend *backend, bool &cancel);
~AptIntf();
@@ -62,20 +51,20 @@ public:
void cancel();
/**
- * Tries to find a package with the given packageId
- * @returns pkgCache::VerIterator that if .end() is true the package could not be found
+ * Tries to find a package with the given package name
+ * @returns pkgCache::VerIterator, if .end() is true the package could not be found
*/
pkgCache::PkgIterator findPackage(const std::string &name);
/**
- * Tries to find a package with the given packageId
- * @returns pkgCache::VerIterator that if .end() is true the package could not be found
+ * Tries to find a package with the given package name and arch
+ * @returns pkgCache::VerIterator, if .end() is true the package could not be found
*/
pkgCache::PkgIterator findPackageArch(const std::string &name, const std::string &arch = std::string());
/**
* Tries to find a package with the given packageId
- * @returns pkgCache::VerIterator that if .end() is true the package could not be found
+ * @returns pkgCache::VerIterator, if .end() is true the package could not be found
*/
pkgCache::VerIterator findPackageId(const gchar *packageId);
@@ -83,22 +72,38 @@ public:
* 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
+ * @returns pkgCache::VerIterator, 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
+ * @returns pkgCache::VerIterator, 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);
+ /**
+ * Tries to find a list of packages mathing the package ids
+ * @returns a list of pkgCache::VerIterator, if the list is empty no package was found
+ */
+ PkgList resolvePackageIds(gchar **package_ids, PkBitfield filters = PK_FILTER_ENUM_NONE);
+ /**
+ * Refreshes the sources of packages
+ */
void refreshCache();
+ /**
+ * Tries to resolve a pkg file installation of the given \sa file
+ * @param install is where the packages to be installed will be stored
+ * @param remove is where the packages to be removed will be stored
+ * @returns true if the package can be installed
+ */
bool markFileForInstall(const gchar *file, PkgList &install, PkgList &remove);
+ /**
+ * Marks the given packages as auto installed
+ */
bool markAutoInstalled(AptCacheFile &cache, PkgList &pkgs, bool flag);
/**
@@ -112,65 +117,101 @@ public:
bool runTransaction(PkgList &install, PkgList &remove, bool simulate, bool markAuto = false);
/**
- * Get depends
+ * Get package depends
*/
void getDepends(PkgList &output,
const pkgCache::VerIterator &ver,
bool recursive);
/**
- * Get requires
+ * Get package requires
*/
void getRequires(PkgList &output,
const pkgCache::VerIterator &ver,
bool recursive);
+ /**
+ * Returns a list of all packages in the cache
+ */
PkgList getPackages();
- PkgList getPackagesFromGroup(vector<PkGroupEnum> &groups);
+
+ /**
+ * Returns a list of all packages in the given groups
+ */
+ PkgList getPackagesFromGroup(gchar **values);
+
+ /**
+ * Returns a list of all packages that matched their names with matcher
+ */
PkgList searchPackageName(Matcher *matcher);
+
+ /**
+ * Returns a list of all packages that matched their description with matcher
+ */
PkgList searchPackageDetails(Matcher *matcher);
/**
- * Get the long description of a package
+ * Returns a list of all packages that matched contains the given files
*/
- string getPackageLongDescription(const pkgCache::VerIterator &ver);
+ PkgList searchPackageFiles(gchar **values);
/**
- * Emits a package if it match the filters
+ * Emits a package with the given state
*/
void emitPackage(const pkgCache::VerIterator &ver,
- PkBitfield filters = PK_FILTER_ENUM_NONE,
PkInfoEnum state = PK_INFO_ENUM_UNKNOWN);
+ /**
+ * Emits a list of packages that matches the given filters
+ */
+ void emitPackages(PkgList &output,
+ PkBitfield filters = PK_FILTER_ENUM_NONE,
+ PkInfoEnum state = PK_INFO_ENUM_UNKNOWN);
+
+ /**
+ * Emits a list of updates that matches the given filters
+ */
+ void emitUpdates(PkgList &output, PkBitfield filters = PK_FILTER_ENUM_NONE);
+
+ /**
+ * Checks if a given package matches the filters
+ * @returns true if it passed the filters
+ */
bool matchPackage(const pkgCache::VerIterator &ver, PkBitfield filters);
- PkgList filterPackages(PkgList &packages, PkBitfield filters);
- void emit_packages(PkgList &output,
- PkBitfield filters = PK_FILTER_ENUM_NONE,
- PkInfoEnum state = PK_INFO_ENUM_UNKNOWN);
+ /**
+ * Returns the list of packages with the ones that passed the given filters
+ */
+ PkgList filterPackages(PkgList &packages, PkBitfield filters);
- void emitUpdates(PkgList &output, PkBitfield filters = PK_FILTER_ENUM_NONE);
+ /**
+ * Emits details of the given package
+ */
+ void emitPackageDetail(const pkgCache::VerIterator &ver);
/**
- * Emits details
- */
- void emitDetails(const pkgCache::VerIterator &ver);
+ * Emits details of the given package list
+ */
void emitDetails(PkgList &pkgs);
/**
- * Emits update detail
- */
- void emitUpdateDetails(const pkgCache::VerIterator &version);
+ * Emits update detail
+ */
+ void emitUpdateDetail(const pkgCache::VerIterator &candver);
+
+ /**
+ * Emits update datails for the given list
+ */
void emitUpdateDetails(PkgList &pkgs);
/**
- * Emits files of packages
- */
- void emitFiles(PkBackend *backend, const gchar *pi);
+ * Emits the files of a package
+ */
+ void emitPackageFiles(const gchar *pi);
/**
- * Download and install packages
- */
+ * Download and install packages
+ */
bool installPackages(AptCacheFile &cache, bool simulating);
/**
@@ -192,6 +233,11 @@ public:
*/
void providesLibrary(PkgList &output, gchar **values);
+ /**
+ * returns a list of packages names
+ */
+ void providesMimeType(PkgList &output, gchar **values);
+
/** Like pkgAcqArchive, but uses generic File objects to download to
* the cwd (and copies from file:/ URLs).
*/
@@ -222,13 +268,11 @@ private:
bool m_isMultiArch;
PkgList m_pkgs;
- string m_localDebFile;
void populateInternalPackages(AptCacheFile &cache);
void emitTransactionPackage(string name, PkInfoEnum state);
time_t m_lastTermAction;
string m_lastPackage;
uint m_lastSubProgress;
- PkInfoEnum m_state;
bool m_startCounting;
// when the internal terminal timesout after no activity
diff --git a/backends/aptcc/pk-backend-aptcc.cpp b/backends/aptcc/pk-backend-aptcc.cpp
index 154e3d0c..99a31ac2 100644
--- a/backends/aptcc/pk-backend-aptcc.cpp
+++ b/backends/aptcc/pk-backend-aptcc.cpp
@@ -211,7 +211,7 @@ static gboolean backend_get_depends_or_requires_thread(PkBackend *backend)
}
// It's faster to emmit the packages here than in the matching part
- m_apt->emit_packages(output, filters);
+ m_apt->emitPackages(output, filters);
delete m_apt;
return true;
@@ -285,7 +285,7 @@ static gboolean backend_get_files_thread(PkBackend *backend)
return false;
}
- m_apt->emitFiles(backend, pi);
+ m_apt->emitPackageFiles(pi);
}
delete m_apt;
@@ -306,11 +306,11 @@ static gboolean backend_get_details_thread(PkBackend *backend)
PkRoleEnum role = pk_backend_get_role (backend);
bool updateDetail = role == PK_ROLE_ENUM_GET_UPDATE_DETAIL ? true : false;
- package_ids = pk_backend_get_strv (backend, "package_ids");
+ 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_error_code(backend,
+ PK_ERROR_ENUM_PACKAGE_ID_INVALID,
+ "Invalid package id");
pk_backend_finished (backend);
return false;
}
@@ -329,8 +329,8 @@ static gboolean backend_get_details_thread(PkBackend *backend)
pkgInitSystem(*_config, _system);
}
- pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
- PkgList pkgs = m_apt->resolvePI(package_ids);
+ pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
+ PkgList pkgs = m_apt->resolvePackageIds(package_ids);
if (updateDetail) {
m_apt->emitUpdateDetails(pkgs);
@@ -404,24 +404,29 @@ static gboolean backend_get_or_update_system_thread (PkBackend *backend)
bool res = true;
if (getUpdates) {
- PkgList update;
+ PkgList updates;
PkgList kept;
-
for (pkgCache::PkgIterator pkg = cache.GetPkgCache()->PkgBegin();
!pkg.end();
++pkg) {
- if ((*cache)[pkg].Upgrade() == true &&
- (*cache)[pkg].NewInstall() == false) {
- update.push_back(m_apt->findCandidateVer(pkg));
- } else if ((*cache)[pkg].Upgradable() == true &&
+ if (cache[pkg].Upgrade() == true &&
+ cache[pkg].NewInstall() == false) {
+ const pkgCache::VerIterator &ver = m_apt->findCandidateVer(pkg);
+ if (!ver.end()) {
+ updates.push_back(ver);
+ }
+ } else if (cache[pkg].Upgradable() == true &&
pkg->CurrentVer != 0 &&
- (*cache)[pkg].Delete() == false) {
- kept.push_back(m_apt->findCandidateVer(pkg));
+ cache[pkg].Delete() == false) {
+ const pkgCache::VerIterator &ver = m_apt->findCandidateVer(pkg);
+ if (!ver.end()) {
+ kept.push_back(ver);
+ }
}
}
- m_apt->emitUpdates(update, filters);
- m_apt->emit_packages(kept, filters, PK_INFO_ENUM_BLOCKED);
+ m_apt->emitUpdates(updates, filters);
+ m_apt->emitPackages(kept, filters, PK_INFO_ENUM_BLOCKED);
} else {
// TODO there should be a simulate upgrade system,
// tho afaik Apper and GPK don't use this
@@ -479,64 +484,46 @@ static gboolean backend_what_provides_thread(PkBackend *backend)
}
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
- vector<string> packages;
- PkgList output;
+ PkgList output;
if (provides == PK_PROVIDES_ENUM_SHARED_LIB) {
m_apt->providesLibrary(output, values);
} else if (provides == PK_PROVIDES_ENUM_MIMETYPE) {
- packages = searchMimeType(backend, values, error, _cancel);
+ m_apt->providesMimeType(output, values);
} else if (provides == PK_PROVIDES_ENUM_CODEC) {
m_apt->providesCodec(output, values);
} else {
// PK_PROVIDES_ENUM_ANY, just search for everything a package can provide
m_apt->providesLibrary(output, values);
m_apt->providesCodec(output, values);
- packages = searchMimeType(backend, values, error, _cancel);
+ m_apt->providesMimeType(output, values);
}
- for (vector<string>::iterator it = packages.begin();
- it != packages.end(); ++it) {
- if (_cancel) {
- break;
- }
- const pkgCache::PkgIterator &pkg = m_apt->findPackage(*it);
- if (pkg.end() == true) {
- continue;
- }
- const pkgCache::VerIterator &ver = m_apt->findVer(pkg);
- if (ver.end() == true) {
- continue;
- }
- output.push_back(ver);
- }
-
- if (error && provides == PK_PROVIDES_ENUM_MIMETYPE) {
+ if (output.empty() && provides == PK_PROVIDES_ENUM_MIMETYPE) {
// check if app-install-data is installed
pkgCache::PkgIterator pkg;
pkg = m_apt->findPackage("app-install-data");
if (pkg->CurrentState != pkgCache::State::Installed) {
- pk_backend_error_code (backend,
- PK_ERROR_ENUM_INTERNAL_ERROR,
- "You need the app-install-data "
- "package to be able to look for "
- "applications that can handle "
- "this kind of file");
+ pk_backend_error_code(backend,
+ PK_ERROR_ENUM_INTERNAL_ERROR,
+ "You need the app-install-data "
+ "package to be able to look for "
+ "applications that can handle "
+ "this kind of file");
}
} else {
- // It's faster to emmit the packages here rather than in the matching part
- m_apt->emit_packages(output, filters);
+ // It's faster to emit the packages here rather than in the matching part
+ m_apt->emitPackages(output, filters);
}
delete m_apt;
-
} else {
- provides_text = pk_provides_enum_to_string (provides);
- pk_backend_error_code (backend,
- PK_ERROR_ENUM_NOT_SUPPORTED,
- "Provides %s not supported",
- provides_text);
- pk_backend_finished (backend);
+ provides_text = pk_provides_enum_to_string(provides);
+ pk_backend_error_code(backend,
+ PK_ERROR_ENUM_NOT_SUPPORTED,
+ "Provides %s not supported",
+ provides_text);
+ pk_backend_finished(backend);
}
return true;
@@ -745,10 +732,10 @@ static gboolean pk_backend_resolve_thread(PkBackend *backend)
return false;
}
- PkgList pkgs = m_apt->resolvePI(package_ids);
+ PkgList pkgs = m_apt->resolvePackageIds(package_ids);
// It's faster to emmit the packages here rather than in the matching part
- m_apt->emit_packages(pkgs, filters);
+ m_apt->emitPackages(pkgs, filters);
delete m_apt;
return true;
@@ -783,29 +770,15 @@ static gboolean pk_backend_search_files_thread(PkBackend *backend)
}
pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
- vector<string> packages = search_files(backend, values, _cancel);
PkgList output;
- for(vector<string>::iterator it = packages.begin();
- it != packages.end(); ++it) {
- if (_cancel) {
- break;
- }
- const pkgCache::PkgIterator &pkg = m_apt->findPackage(*it);
- if (pkg.end() == true) {
- continue;
- }
- const pkgCache::VerIterator &ver = m_apt->findVer(pkg);
- if (ver.end() == true) {
- continue;
- }
- output.push_back(ver);
- }
- // It's faster to emmit the packages here rather than in the matching part
- m_apt->emit_packages(output, filters);
+ output = m_apt->searchPackageFiles(values);
+
+ // It's faster to emit the packages here rather than in the matching part
+ m_apt->emitPackages(output, filters);
delete m_apt;
} else {
- pk_backend_finished (backend);
+ pk_backend_finished(backend);
}
return true;
@@ -823,24 +796,9 @@ static gboolean backend_search_groups_thread (PkBackend *backend)
{
gchar **values;
PkBitfield filters;
- vector<PkGroupEnum> groups;
values = pk_backend_get_strv(backend, "search");
- filters = (PkBitfield) pk_backend_get_uint (backend, "filters");
- pk_backend_set_allow_cancel(backend, true);
-
- int len = g_strv_length(values);
- for (uint i = 0; i < len; i++) {
- if (values[i] == NULL) {
- pk_backend_error_code(backend,
- PK_ERROR_ENUM_GROUP_NOT_FOUND,
- values[i]);
- pk_backend_finished(backend);
- return false;
- } else {
- groups.push_back(pk_group_enum_from_string(values[i]));
- }
- }
+ filters = (PkBitfield) pk_backend_get_uint(backend, "filters");
AptIntf *m_apt = new AptIntf(backend, _cancel);
pk_backend_set_pointer(backend, "aptcc_obj", m_apt);
@@ -850,14 +808,14 @@ static gboolean backend_search_groups_thread (PkBackend *backend)
return false;
}
- pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
+ pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
// It's faster to emmit the packages here rather than in the matching part
PkgList output;
- output = m_apt->getPackagesFromGroup(groups);
- m_apt->emit_packages(output, filters);
+ output = m_apt->getPackagesFromGroup(values);
+ m_apt->emitPackages(output, filters);
- pk_backend_set_percentage (backend, 100);
+ pk_backend_set_percentage(backend, 100);
delete m_apt;
return true;
}
@@ -916,7 +874,7 @@ static gboolean backend_search_package_thread(PkBackend *backend)
}
// It's faster to emmit the packages here than in the matching part
- m_apt->emit_packages(output, filters);
+ m_apt->emitPackages(output, filters);
delete matcher;
pk_backend_set_percentage(backend, 100);
@@ -1009,9 +967,9 @@ static gboolean backend_manage_packages_thread(PkBackend *backend)
// Resolve the given packages
gchar **package_ids = pk_backend_get_strv(backend, "package_ids");
if (remove) {
- removePkgs = m_apt->resolvePI(package_ids);
+ removePkgs = m_apt->resolvePackageIds(package_ids);
} else {
- installPkgs = m_apt->resolvePI(package_ids);
+ installPkgs = m_apt->resolvePackageIds(package_ids);
}
if (removePkgs.size() == 0 && installPkgs.size() == 0) {
@@ -1254,7 +1212,7 @@ static gboolean backend_get_packages_thread(PkBackend *backend)
output = m_apt->getPackages();
// It's faster to emmit the packages rather here than in the matching part
- m_apt->emit_packages(output, filters);
+ m_apt->emitPackages(output, filters);
delete m_apt;
return true;