From d3814b27a7ba26236835180c37de72e6afbdffb2 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 14 Jul 2010 22:59:43 +0200 Subject: * apt-pkg/depcache.cc: - handle "circular" conflicts for "all" packages correctly --- apt-pkg/depcache.cc | 8 ++++---- debian/changelog | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 05127fe18..bc663a8e9 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -338,7 +338,7 @@ bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res) /* Check simple depends. A depends -should- never self match but we allow it anyhow because dpkg does. Technically it is a packaging bug. Conflicts may never self match */ - if (Dep.TargetPkg() != Dep.ParentPkg() || + if (Dep.TargetPkg()->Group != Dep.ParentPkg()->Group || (Dep->Type != Dep::Conflicts && Dep->Type != Dep::DpkgBreaks && Dep->Type != Dep::Obsoletes)) { PkgIterator Pkg = Dep.TargetPkg(); @@ -367,9 +367,9 @@ bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res) PkgIterator Pkg = Dep.ParentPkg(); for (; P.end() != true; P++) { - /* Provides may never be applied against the same package if it is - a conflicts. See the comment above. */ - if (P.OwnerPkg() == Pkg && + /* Provides may never be applied against the same package (or group) + if it is a conflicts. See the comment above. */ + if (P.OwnerPkg()->Group == Pkg->Group && (Dep->Type == Dep::Conflicts || Dep->Type == Dep::DpkgBreaks)) continue; diff --git a/debian/changelog b/debian/changelog index 0f87ce60f..76354aad7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +apt (0.7.26~exp11) experimental; urgency=low + + [ David Kalnischkies ] + * apt-pkg/depcache.cc: + - handle "circular" conflicts for "all" packages correctly + + -- David Kalnischkies Wed, 14 Jul 2010 22:58:08 +0200 + apt (0.7.26~exp10) experimental; urgency=low [ David Kalnischkies ] -- cgit v1.2.3 From fe1af091b871f9af715d729e515f2e3a62802c6f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 16 Jul 2010 17:42:54 +0200 Subject: * cmdline/apt-cache.cc: - be able to omit dependency types in (r)depends (Closes: #319006) --- cmdline/apt-cache.cc | 77 ++++++++++++++++++++++++++++++++++++++++++---------- debian/changelog | 2 ++ doc/apt-cache.8.xml | 14 ++++++++++ 3 files changed, 78 insertions(+), 15 deletions(-) diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 338be7029..557996693 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -569,9 +569,18 @@ bool Depends(CommandLine &CmdL) for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) Colours[Pkg->ID] = 1; - bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false); - bool Installed = _config->FindB("APT::Cache::Installed",false); - bool Important = _config->FindB("APT::Cache::Important",false); + bool const Recurse = _config->FindB("APT::Cache::RecurseDepends", false); + bool const Installed = _config->FindB("APT::Cache::Installed", false); + bool const Important = _config->FindB("APT::Cache::Important", false); + bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType",true); + bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true); + bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true); + bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false); + bool const ShowSuggests = _config->FindB("APT::Cache::ShowSuggests", Important == false); + bool const ShowReplaces = _config->FindB("APT::Cache::ShowReplaces", Important == false); + bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false); + bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false); + bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false); bool DidSomething; do { @@ -594,12 +603,17 @@ bool Depends(CommandLine &CmdL) for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++) { - // Important deps only - if (Important == true) - if (D->Type != pkgCache::Dep::PreDepends && - D->Type != pkgCache::Dep::Depends) - continue; - + switch (D->Type) { + case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break; + case pkgCache::Dep::Depends: if (!ShowDepends) continue; break; + case pkgCache::Dep::Recommends: if (!ShowRecommends) continue; break; + case pkgCache::Dep::Suggests: if (!ShowSuggests) continue; break; + case pkgCache::Dep::Replaces: if (!ShowReplaces) continue; break; + case pkgCache::Dep::Conflicts: if (!ShowConflicts) continue; break; + case pkgCache::Dep::DpkgBreaks: if (!ShowBreaks) continue; break; + case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break; + } + pkgCache::PkgIterator Trg = D.TargetPkg(); if((Installed && Trg->CurrentVer != 0) || !Installed) @@ -611,10 +625,12 @@ bool Depends(CommandLine &CmdL) cout << " "; // Show the package + if (ShowDepType == true) + cout << D.DepType() << ": "; if (Trg->VersionList == 0) - cout << D.DepType() << ": <" << Trg.FullName(true) << ">" << endl; + cout << "<" << Trg.FullName(true) << ">" << endl; else - cout << D.DepType() << ": " << Trg.FullName(true) << endl; + cout << Trg.FullName(true) << endl; if (Recurse == true) Colours[D.TargetPkg()->ID]++; @@ -660,8 +676,18 @@ bool RDepends(CommandLine &CmdL) for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) Colours[Pkg->ID] = 1; - bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false); - bool Installed = _config->FindB("APT::Cache::Installed",false); + bool const Recurse = _config->FindB("APT::Cache::RecurseDepends",false); + bool const Installed = _config->FindB("APT::Cache::Installed",false); + bool const Important = _config->FindB("APT::Cache::Important", false); + bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType",false); + bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true); + bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true); + bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false); + bool const ShowSuggests = _config->FindB("APT::Cache::ShowSuggests", Important == false); + bool const ShowReplaces = _config->FindB("APT::Cache::ShowReplaces", Important == false); + bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false); + bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false); + bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false); bool DidSomething; do { @@ -684,7 +710,18 @@ bool RDepends(CommandLine &CmdL) cout << "Reverse Depends:" << endl; for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false; D++) - { + { + switch (D->Type) { + case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break; + case pkgCache::Dep::Depends: if (!ShowDepends) continue; break; + case pkgCache::Dep::Recommends: if (!ShowRecommends) continue; break; + case pkgCache::Dep::Suggests: if (!ShowSuggests) continue; break; + case pkgCache::Dep::Replaces: if (!ShowReplaces) continue; break; + case pkgCache::Dep::Conflicts: if (!ShowConflicts) continue; break; + case pkgCache::Dep::DpkgBreaks: if (!ShowBreaks) continue; break; + case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break; + } + // Show the package pkgCache::PkgIterator Trg = D.ParentPkg(); @@ -696,8 +733,10 @@ bool RDepends(CommandLine &CmdL) else cout << " "; + if (ShowDepType == true) + cout << D.DepType() << ": "; if (Trg->VersionList == 0) - cout << D.DepType() << ": <" << Trg.FullName(true) << ">" << endl; + cout << "<" << Trg.FullName(true) << ">" << endl; else cout << Trg.FullName(true) << endl; @@ -1820,6 +1859,14 @@ int main(int argc,const char *argv[]) /*{{{*/ {'c',"config-file",0,CommandLine::ConfigFile}, {'o',"option",0,CommandLine::ArbItem}, {0,"installed","APT::Cache::Installed",0}, + {0,"pre-depends","APT::Cache::ShowPreDepends",0}, + {0,"depends","APT::Cache::ShowDepends",0}, + {0,"recommends","APT::Cache::ShowRecommends",0}, + {0,"suggests","APT::Cache::ShowSuggests",0}, + {0,"replaces","APT::Cache::ShowReplaces",0}, + {0,"breaks","APT::Cache::ShowBreaks",0}, + {0,"conflicts","APT::Cache::ShowConflicts",0}, + {0,"enhances","APT::Cache::ShowEnhances",0}, {0,0,0,0}}; CommandLine::Dispatch CmdsA[] = {{"help",&ShowHelp}, {"add",&DoAdd}, diff --git a/debian/changelog b/debian/changelog index 76354aad7..128309b51 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,8 @@ apt (0.7.26~exp11) experimental; urgency=low [ David Kalnischkies ] * apt-pkg/depcache.cc: - handle "circular" conflicts for "all" packages correctly + * cmdline/apt-cache.cc: + - be able to omit dependency types in (r)depends (Closes: #319006) -- David Kalnischkies Wed, 14 Jul 2010 22:58:08 +0200 diff --git a/doc/apt-cache.8.xml b/doc/apt-cache.8.xml index 538de3c27..9a63421a8 100644 --- a/doc/apt-cache.8.xml +++ b/doc/apt-cache.8.xml @@ -309,6 +309,20 @@ Reverse Provides: Configuration Item: APT::Cache::Important. + + + + + + + + + Per default the depends and + rdepends print all dependencies. This can be twicked with + these flags which will omit the specified dependency type. + Configuration Item: APT::Cache::ShowDependencyType + e.g. APT::Cache::ShowRecommends. + Print full package records when searching. Configuration Item: APT::Cache::ShowFull. -- cgit v1.2.3 From 9ba5aa3b01f1f7c08c74f5d0a21971db221d30f1 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 17 Jul 2010 19:07:00 +0200 Subject: factor regex package name matches into newly created cachefilter classes --- apt-pkg/cachefilter.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ apt-pkg/cachefilter.h | 29 +++++++++++++++++++++++++++ apt-pkg/makefile | 5 +++-- cmdline/cacheset.cc | 18 +++++------------ 4 files changed, 91 insertions(+), 15 deletions(-) create mode 100644 apt-pkg/cachefilter.cc create mode 100644 apt-pkg/cachefilter.h diff --git a/apt-pkg/cachefilter.cc b/apt-pkg/cachefilter.cc new file mode 100644 index 000000000..8f0725ea3 --- /dev/null +++ b/apt-pkg/cachefilter.cc @@ -0,0 +1,54 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/** \file cachefilter.h + Collection of functor classes */ + /*}}}*/ +// Include Files /*{{{*/ +#include +#include +#include + +#include + +#include + +#include + /*}}}*/ +namespace APT { +namespace CacheFilter { +PackageNameMatchesRegEx::PackageNameMatchesRegEx(std::string const &Pattern) {/*{{{*/ + pattern = new regex_t; + int const Res = regcomp(pattern, Pattern.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB); + if (Res == 0) + return; + + delete pattern; + pattern = NULL; + char Error[300]; + regerror(Res, pattern, Error, sizeof(Error)); + _error->Error(_("Regex compilation error - %s"), Error); +} + /*}}}*/ +bool PackageNameMatchesRegEx::operator() (pkgCache::PkgIterator const &Pkg) {/*{{{*/ + if (unlikely(pattern == NULL)) + return false; + else + return regexec(pattern, Pkg.Name(), 0, 0, 0) == 0; +} + /*}}}*/ +bool PackageNameMatchesRegEx::operator() (pkgCache::GrpIterator const &Grp) {/*{{{*/ + if (unlikely(pattern == NULL)) + return false; + else + return regexec(pattern, Grp.Name(), 0, 0, 0) == 0; +} + /*}}}*/ +PackageNameMatchesRegEx::~PackageNameMatchesRegEx() { /*{{{*/ + if (pattern == NULL) + return; + regfree(pattern); + delete pattern; +} + /*}}}*/ +} +} diff --git a/apt-pkg/cachefilter.h b/apt-pkg/cachefilter.h new file mode 100644 index 000000000..e7ab1723f --- /dev/null +++ b/apt-pkg/cachefilter.h @@ -0,0 +1,29 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/** \file cachefilter.h + Collection of functor classes */ + /*}}}*/ +#ifndef APT_CACHEFILTER_H +#define APT_CACHEFILTER_H +// Include Files /*{{{*/ +#include + +#include + +#include + /*}}}*/ +namespace APT { +namespace CacheFilter { +// PackageNameMatchesRegEx /*{{{*/ +class PackageNameMatchesRegEx { + regex_t* pattern; +public: + PackageNameMatchesRegEx(std::string const &Pattern); + bool operator() (pkgCache::PkgIterator const &Pkg); + bool operator() (pkgCache::GrpIterator const &Grp); + ~PackageNameMatchesRegEx(); +}; + /*}}}*/ +} +} +#endif diff --git a/apt-pkg/makefile b/apt-pkg/makefile index 2a7958536..e9e5651b0 100644 --- a/apt-pkg/makefile +++ b/apt-pkg/makefile @@ -35,14 +35,15 @@ SOURCE+= pkgcache.cc version.cc depcache.cc \ srcrecords.cc cachefile.cc versionmatch.cc policy.cc \ pkgsystem.cc indexfile.cc pkgcachegen.cc acquire-item.cc \ indexrecords.cc vendor.cc vendorlist.cc cdrom.cc indexcopy.cc \ - aptconfiguration.cc + aptconfiguration.cc cachefilter.cc HEADERS+= algorithms.h depcache.h pkgcachegen.h cacheiterators.h \ orderlist.h sourcelist.h packagemanager.h tagfile.h \ init.h pkgcache.h version.h progress.h pkgrecords.h \ acquire.h acquire-worker.h acquire-item.h acquire-method.h \ clean.h srcrecords.h cachefile.h versionmatch.h policy.h \ pkgsystem.h indexfile.h metaindex.h indexrecords.h vendor.h \ - vendorlist.h cdrom.h indexcopy.h aptconfiguration.h + vendorlist.h cdrom.h indexcopy.h aptconfiguration.h \ + cachefilter.h # Source code for the debian specific components # In theory the deb headers do not need to be exported.. diff --git a/cmdline/cacheset.cc b/cmdline/cacheset.cc index 78c9d3f6c..0b099f442 100644 --- a/cmdline/cacheset.cc +++ b/cmdline/cacheset.cc @@ -10,6 +10,7 @@ /*}}}*/ // Include Files /*{{{*/ #include +#include #include #include #include @@ -97,22 +98,14 @@ PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, Cache arch = "native"; } - regex_t Pattern; - int Res; - if ((Res = regcomp(&Pattern, pattern.c_str() , REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0) { - char Error[300]; - regerror(Res, &Pattern, Error, sizeof(Error)); - _error->Error(_("Regex compilation error - %s"), Error); - return PackageSet(REGEX); - } - if (unlikely(Cache.GetPkgCache() == 0)) return PackageSet(REGEX); + APT::CacheFilter::PackageNameMatchesRegEx regexfilter(pattern); + PackageSet pkgset(REGEX); - for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) - { - if (regexec(&Pattern, Grp.Name(), 0, 0, 0) != 0) + for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) { + if (regexfilter(Grp) == false) continue; pkgCache::PkgIterator Pkg = Grp.FindPkg(arch); if (Pkg.end() == true) { @@ -128,7 +121,6 @@ PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, Cache pkgset.insert(Pkg); } - regfree(&Pattern); if (pkgset.empty() == true) return helper.canNotFindRegEx(Cache, pattern); -- cgit v1.2.3 From 8fde723961709118837153cdf94f150c680e10e9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 17 Jul 2010 20:04:44 +0200 Subject: * apt-pkg/cacheset.cc: - move them back to the library as they look stable now --- apt-pkg/cacheset.cc | 506 ++++++++++++++++++++++++++++++++++++++++++++++++++ apt-pkg/cacheset.h | 375 +++++++++++++++++++++++++++++++++++++ apt-pkg/makefile | 4 +- cmdline/apt-cache.cc | 3 +- cmdline/apt-get.cc | 2 +- cmdline/cacheset.cc | 507 --------------------------------------------------- cmdline/cacheset.h | 375 ------------------------------------- cmdline/makefile | 4 +- debian/changelog | 4 +- 9 files changed, 890 insertions(+), 890 deletions(-) create mode 100644 apt-pkg/cacheset.cc create mode 100644 apt-pkg/cacheset.h delete mode 100644 cmdline/cacheset.cc delete mode 100644 cmdline/cacheset.h diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc new file mode 100644 index 000000000..df7e99fd0 --- /dev/null +++ b/apt-pkg/cacheset.cc @@ -0,0 +1,506 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/* ###################################################################### + + Simple wrapper around a std::set to provide a similar interface to + a set of cache structures as to the complete set of all structures + in the pkgCache. Currently only Package is supported. + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include + /*}}}*/ +namespace APT { +// FromTask - Return all packages in the cache from a specific task /*{{{*/ +PackageSet PackageSet::FromTask(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { + size_t const archfound = pattern.find_last_of(':'); + std::string arch = "native"; + if (archfound != std::string::npos) { + arch = pattern.substr(archfound+1); + pattern.erase(archfound); + } + + if (pattern[pattern.length() -1] != '^') + return APT::PackageSet(TASK); + pattern.erase(pattern.length()-1); + + if (unlikely(Cache.GetPkgCache() == 0 || Cache.GetDepCache() == 0)) + return APT::PackageSet(TASK); + + PackageSet pkgset(TASK); + // get the records + pkgRecords Recs(Cache); + + // build regexp for the task + regex_t Pattern; + char S[300]; + snprintf(S, sizeof(S), "^Task:.*[, ]%s([, ]|$)", pattern.c_str()); + if(regcomp(&Pattern,S, REG_EXTENDED | REG_NOSUB | REG_NEWLINE) != 0) { + _error->Error("Failed to compile task regexp"); + return pkgset; + } + + for (pkgCache::GrpIterator Grp = Cache->GrpBegin(); Grp.end() == false; ++Grp) { + pkgCache::PkgIterator Pkg = Grp.FindPkg(arch); + if (Pkg.end() == true) + continue; + pkgCache::VerIterator ver = Cache[Pkg].CandidateVerIter(Cache); + if(ver.end() == true) + continue; + + pkgRecords::Parser &parser = Recs.Lookup(ver.FileList()); + const char *start, *end; + parser.GetRec(start,end); + unsigned int const length = end - start; + char buf[length]; + strncpy(buf, start, length); + buf[length-1] = '\0'; + if (regexec(&Pattern, buf, 0, 0, 0) != 0) + continue; + + pkgset.insert(Pkg); + } + regfree(&Pattern); + + if (pkgset.empty() == true) + return helper.canNotFindTask(Cache, pattern); + + helper.showTaskSelection(pkgset, pattern); + return pkgset; +} + /*}}}*/ +// FromRegEx - Return all packages in the cache matching a pattern /*{{{*/ +PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { + static const char * const isregex = ".?+*|[^$"; + if (pattern.find_first_of(isregex) == std::string::npos) + return PackageSet(REGEX); + + size_t archfound = pattern.find_last_of(':'); + std::string arch = "native"; + if (archfound != std::string::npos) { + arch = pattern.substr(archfound+1); + if (arch.find_first_of(isregex) == std::string::npos) + pattern.erase(archfound); + else + arch = "native"; + } + + if (unlikely(Cache.GetPkgCache() == 0)) + return PackageSet(REGEX); + + APT::CacheFilter::PackageNameMatchesRegEx regexfilter(pattern); + + PackageSet pkgset(REGEX); + for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) { + if (regexfilter(Grp) == false) + continue; + pkgCache::PkgIterator Pkg = Grp.FindPkg(arch); + if (Pkg.end() == true) { + if (archfound == std::string::npos) { + std::vector archs = APT::Configuration::getArchitectures(); + for (std::vector::const_iterator a = archs.begin(); + a != archs.end() && Pkg.end() != true; ++a) + Pkg = Grp.FindPkg(*a); + } + if (Pkg.end() == true) + continue; + } + + pkgset.insert(Pkg); + } + + if (pkgset.empty() == true) + return helper.canNotFindRegEx(Cache, pattern); + + helper.showRegExSelection(pkgset, pattern); + return pkgset; +} + /*}}}*/ +// FromName - Returns the package defined by this string /*{{{*/ +pkgCache::PkgIterator PackageSet::FromName(pkgCacheFile &Cache, + std::string const &str, CacheSetHelper &helper) { + std::string pkg = str; + size_t archfound = pkg.find_last_of(':'); + std::string arch; + if (archfound != std::string::npos) { + arch = pkg.substr(archfound+1); + pkg.erase(archfound); + } + + if (Cache.GetPkgCache() == 0) + return pkgCache::PkgIterator(Cache, 0); + + pkgCache::PkgIterator Pkg(Cache, 0); + if (arch.empty() == true) { + pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(pkg); + if (Grp.end() == false) + Pkg = Grp.FindPreferredPkg(); + } else + Pkg = Cache.GetPkgCache()->FindPkg(pkg, arch); + + if (Pkg.end() == true) + return helper.canNotFindPkgName(Cache, str); + return Pkg; +} + /*}}}*/ +// GroupedFromCommandLine - Return all versions specified on commandline/*{{{*/ +std::map PackageSet::GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback, CacheSetHelper &helper) { + std::map pkgsets; + for (const char **I = cmdline; *I != 0; ++I) { + unsigned short modID = fallback; + std::string str = *I; + bool modifierPresent = false; + for (std::list::const_iterator mod = mods.begin(); + mod != mods.end(); ++mod) { + size_t const alength = strlen(mod->Alias); + switch(mod->Pos) { + case PackageSet::Modifier::POSTFIX: + if (str.compare(str.length() - alength, alength, + mod->Alias, 0, alength) != 0) + continue; + str.erase(str.length() - alength); + modID = mod->ID; + break; + case PackageSet::Modifier::PREFIX: + continue; + case PackageSet::Modifier::NONE: + continue; + } + modifierPresent = true; + break; + } + if (modifierPresent == true) { + bool const errors = helper.showErrors(false); + pkgCache::PkgIterator Pkg = FromName(Cache, *I, helper); + helper.showErrors(errors); + if (Pkg.end() == false) { + pkgsets[fallback].insert(Pkg); + continue; + } + } + pkgsets[modID].insert(PackageSet::FromString(Cache, str, helper)); + } + return pkgsets; +} + /*}}}*/ +// FromCommandLine - Return all packages specified on commandline /*{{{*/ +PackageSet PackageSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) { + PackageSet pkgset; + for (const char **I = cmdline; *I != 0; ++I) { + PackageSet pset = FromString(Cache, *I, helper); + pkgset.insert(pset.begin(), pset.end()); + } + return pkgset; +} + /*}}}*/ +// FromString - Return all packages matching a specific string /*{{{*/ +PackageSet PackageSet::FromString(pkgCacheFile &Cache, std::string const &str, CacheSetHelper &helper) { + _error->PushToStack(); + + PackageSet pkgset; + pkgCache::PkgIterator Pkg = FromName(Cache, str, helper); + if (Pkg.end() == false) + pkgset.insert(Pkg); + else { + pkgset = FromTask(Cache, str, helper); + if (pkgset.empty() == true) { + pkgset = FromRegEx(Cache, str, helper); + if (pkgset.empty() == true) + pkgset = helper.canNotFindPackage(Cache, str); + } + } + + if (pkgset.empty() == false) + _error->RevertToStack(); + else + _error->MergeWithStack(); + return pkgset; +} + /*}}}*/ +// GroupedFromCommandLine - Return all versions specified on commandline/*{{{*/ +std::map VersionSet::GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback, CacheSetHelper &helper) { + std::map versets; + for (const char **I = cmdline; *I != 0; ++I) { + unsigned short modID = fallback; + VersionSet::Version select = VersionSet::NEWEST; + std::string str = *I; + bool modifierPresent = false; + for (std::list::const_iterator mod = mods.begin(); + mod != mods.end(); ++mod) { + if (modID == fallback && mod->ID == fallback) + select = mod->SelectVersion; + size_t const alength = strlen(mod->Alias); + switch(mod->Pos) { + case VersionSet::Modifier::POSTFIX: + if (str.compare(str.length() - alength, alength, + mod->Alias, 0, alength) != 0) + continue; + str.erase(str.length() - alength); + modID = mod->ID; + select = mod->SelectVersion; + break; + case VersionSet::Modifier::PREFIX: + continue; + case VersionSet::Modifier::NONE: + continue; + } + modifierPresent = true; + break; + } + + if (modifierPresent == true) { + bool const errors = helper.showErrors(false); + VersionSet const vset = VersionSet::FromString(Cache, std::string(*I), select, helper, true); + helper.showErrors(errors); + if (vset.empty() == false) { + versets[fallback].insert(vset); + continue; + } + } + versets[modID].insert(VersionSet::FromString(Cache, str, select , helper)); + } + return versets; +} + /*}}}*/ +// FromCommandLine - Return all versions specified on commandline /*{{{*/ +APT::VersionSet VersionSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline, + APT::VersionSet::Version const &fallback, CacheSetHelper &helper) { + VersionSet verset; + for (const char **I = cmdline; *I != 0; ++I) + verset.insert(VersionSet::FromString(Cache, *I, fallback, helper)); + return verset; +} + /*}}}*/ +// FromString - Returns all versions spedcified by a string /*{{{*/ +APT::VersionSet VersionSet::FromString(pkgCacheFile &Cache, std::string pkg, + APT::VersionSet::Version const &fallback, CacheSetHelper &helper, + bool const &onlyFromName) { + std::string ver; + bool verIsRel = false; + size_t const vertag = pkg.find_last_of("/="); + if (vertag != string::npos) { + ver = pkg.substr(vertag+1); + verIsRel = (pkg[vertag] == '/'); + pkg.erase(vertag); + } + PackageSet pkgset; + if (onlyFromName == false) + pkgset = PackageSet::FromString(Cache, pkg, helper); + else { + pkgset.insert(PackageSet::FromName(Cache, pkg, helper)); + } + + VersionSet verset; + bool errors = true; + if (pkgset.getConstructor() != PackageSet::UNKNOWN) + errors = helper.showErrors(false); + for (PackageSet::const_iterator P = pkgset.begin(); + P != pkgset.end(); ++P) { + if (vertag == string::npos) { + verset.insert(VersionSet::FromPackage(Cache, P, fallback, helper)); + continue; + } + pkgCache::VerIterator V; + if (ver == "installed") + V = getInstalledVer(Cache, P, helper); + else if (ver == "candidate") + V = getCandidateVer(Cache, P, helper); + else { + pkgVersionMatch Match(ver, (verIsRel == true ? pkgVersionMatch::Release : + pkgVersionMatch::Version)); + V = Match.Find(P); + if (V.end() == true) { + if (verIsRel == true) + _error->Error(_("Release '%s' for '%s' was not found"), + ver.c_str(), P.FullName(true).c_str()); + else + _error->Error(_("Version '%s' for '%s' was not found"), + ver.c_str(), P.FullName(true).c_str()); + continue; + } + } + if (V.end() == true) + continue; + helper.showSelectedVersion(P, V, ver, verIsRel); + verset.insert(V); + } + if (pkgset.getConstructor() != PackageSet::UNKNOWN) + helper.showErrors(errors); + return verset; +} + /*}}}*/ +// FromPackage - versions from package based on fallback /*{{{*/ +VersionSet VersionSet::FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, + VersionSet::Version const &fallback, CacheSetHelper &helper) { + VersionSet verset; + pkgCache::VerIterator V; + bool showErrors; + switch(fallback) { + case VersionSet::ALL: + if (P->VersionList != 0) + for (V = P.VersionList(); V.end() != true; ++V) + verset.insert(V); + else + verset.insert(helper.canNotFindAllVer(Cache, P)); + break; + case VersionSet::CANDANDINST: + verset.insert(getInstalledVer(Cache, P, helper)); + verset.insert(getCandidateVer(Cache, P, helper)); + break; + case VersionSet::CANDIDATE: + verset.insert(getCandidateVer(Cache, P, helper)); + break; + case VersionSet::INSTALLED: + verset.insert(getInstalledVer(Cache, P, helper)); + break; + case VersionSet::CANDINST: + showErrors = helper.showErrors(false); + V = getCandidateVer(Cache, P, helper); + if (V.end() == true) + V = getInstalledVer(Cache, P, helper); + helper.showErrors(showErrors); + if (V.end() == false) + verset.insert(V); + else + verset.insert(helper.canNotFindInstCandVer(Cache, P)); + break; + case VersionSet::INSTCAND: + showErrors = helper.showErrors(false); + V = getInstalledVer(Cache, P, helper); + if (V.end() == true) + V = getCandidateVer(Cache, P, helper); + helper.showErrors(showErrors); + if (V.end() == false) + verset.insert(V); + else + verset.insert(helper.canNotFindInstCandVer(Cache, P)); + break; + case VersionSet::NEWEST: + if (P->VersionList != 0) + verset.insert(P.VersionList()); + else + verset.insert(helper.canNotFindNewestVer(Cache, P)); + break; + } + return verset; +} + /*}}}*/ +// getCandidateVer - Returns the candidate version of the given package /*{{{*/ +pkgCache::VerIterator VersionSet::getCandidateVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) { + pkgCache::VerIterator Cand; + if (Cache.IsPolicyBuilt() == true || Cache.IsDepCacheBuilt() == false) + { + if (unlikely(Cache.GetPolicy() == 0)) + return pkgCache::VerIterator(Cache); + Cand = Cache.GetPolicy()->GetCandidateVer(Pkg); + } else { + Cand = Cache[Pkg].CandidateVerIter(Cache); + } + if (Cand.end() == true) + return helper.canNotFindCandidateVer(Cache, Pkg); + return Cand; +} + /*}}}*/ +// getInstalledVer - Returns the installed version of the given package /*{{{*/ +pkgCache::VerIterator VersionSet::getInstalledVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) { + if (Pkg->CurrentVer == 0) + return helper.canNotFindInstalledVer(Cache, Pkg); + return Pkg.CurrentVer(); +} + /*}}}*/ +// canNotFindPkgName - handle the case no package has this name /*{{{*/ +pkgCache::PkgIterator CacheSetHelper::canNotFindPkgName(pkgCacheFile &Cache, + std::string const &str) { + if (ShowError == true) + _error->Error(_("Unable to locate package %s"), str.c_str()); + return pkgCache::PkgIterator(Cache, 0); +} + /*}}}*/ +// canNotFindTask - handle the case no package is found for a task /*{{{*/ +PackageSet CacheSetHelper::canNotFindTask(pkgCacheFile &Cache, std::string pattern) { + if (ShowError == true) + _error->Error(_("Couldn't find task '%s'"), pattern.c_str()); + return PackageSet(); +} + /*}}}*/ +// canNotFindRegEx - handle the case no package is found by a regex /*{{{*/ +PackageSet CacheSetHelper::canNotFindRegEx(pkgCacheFile &Cache, std::string pattern) { + if (ShowError == true) + _error->Error(_("Couldn't find any package by regex '%s'"), pattern.c_str()); + return PackageSet(); +} + /*}}}*/ +// canNotFindPackage - handle the case no package is found from a string/*{{{*/ +PackageSet CacheSetHelper::canNotFindPackage(pkgCacheFile &Cache, std::string const &str) { + return PackageSet(); +} + /*}}}*/ +// canNotFindAllVer /*{{{*/ +VersionSet CacheSetHelper::canNotFindAllVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg) { + if (ShowError == true) + _error->Error(_("Can't select versions from package '%s' as it purely virtual"), Pkg.FullName(true).c_str()); + return VersionSet(); +} + /*}}}*/ +// canNotFindInstCandVer /*{{{*/ +VersionSet CacheSetHelper::canNotFindInstCandVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg) { + if (ShowError == true) + _error->Error(_("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str()); + return VersionSet(); +} + /*}}}*/ +// canNotFindInstCandVer /*{{{*/ +VersionSet CacheSetHelper::canNotFindCandInstVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg) { + if (ShowError == true) + _error->Error(_("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str()); + return VersionSet(); +} + /*}}}*/ +// canNotFindNewestVer /*{{{*/ +pkgCache::VerIterator CacheSetHelper::canNotFindNewestVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg) { + if (ShowError == true) + _error->Error(_("Can't select newest version from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str()); + return pkgCache::VerIterator(Cache, 0); +} + /*}}}*/ +// canNotFindCandidateVer /*{{{*/ +pkgCache::VerIterator CacheSetHelper::canNotFindCandidateVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg) { + if (ShowError == true) + _error->Error(_("Can't select candidate version from package %s as it has no candidate"), Pkg.FullName(true).c_str()); + return pkgCache::VerIterator(Cache, 0); +} + /*}}}*/ +// canNotFindInstalledVer /*{{{*/ +pkgCache::VerIterator CacheSetHelper::canNotFindInstalledVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg) { + if (ShowError == true) + _error->Error(_("Can't select installed version from package %s as it is not installed"), Pkg.FullName(true).c_str()); + return pkgCache::VerIterator(Cache, 0); +} + /*}}}*/ +} diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h new file mode 100644 index 000000000..c8c3dd096 --- /dev/null +++ b/apt-pkg/cacheset.h @@ -0,0 +1,375 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/** \file cacheset.h + Wrappers around std::set to have set::iterators which behave + similar to the Iterators of the cache structures. + + Provides also a few helper methods which work with these sets */ + /*}}}*/ +#ifndef APT_CACHESET_H +#define APT_CACHESET_H +// Include Files /*{{{*/ +#include +#include +#include +#include +#include +#include + +#include +#include + /*}}}*/ +namespace APT { +class PackageSet; +class VersionSet; +class CacheSetHelper { /*{{{*/ +/** \class APT::CacheSetHelper + Simple base class with a lot of virtual methods which can be overridden + to alter the behavior or the output of the CacheSets. + + This helper is passed around by the static methods in the CacheSets and + used every time they hit an error condition or something could be + printed out. +*/ +public: /*{{{*/ + CacheSetHelper(bool const &ShowError = true) : ShowError(ShowError) {}; + virtual ~CacheSetHelper() {}; + + virtual void showTaskSelection(PackageSet const &pkgset, string const &pattern) {}; + virtual void showRegExSelection(PackageSet const &pkgset, string const &pattern) {}; + virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver, + string const &ver, bool const &verIsRel) {}; + + virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str); + virtual PackageSet canNotFindTask(pkgCacheFile &Cache, std::string pattern); + virtual PackageSet canNotFindRegEx(pkgCacheFile &Cache, std::string pattern); + virtual PackageSet canNotFindPackage(pkgCacheFile &Cache, std::string const &str); + virtual VersionSet canNotFindAllVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); + virtual VersionSet canNotFindInstCandVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg); + virtual VersionSet canNotFindCandInstVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg); + virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg); + virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg); + virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg); + + bool showErrors() const { return ShowError; }; + bool showErrors(bool const &newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); }; + /*}}}*/ +protected: + bool ShowError; +}; /*}}}*/ +class PackageSet : public std::set { /*{{{*/ +/** \class APT::PackageSet + + Simple wrapper around a std::set to provide a similar interface to + a set of packages as to the complete set of all packages in the + pkgCache. */ +public: /*{{{*/ + /** \brief smell like a pkgCache::PkgIterator */ + class const_iterator : public std::set::const_iterator {/*{{{*/ + public: + const_iterator(std::set::const_iterator x) : + std::set::const_iterator(x) {} + + operator pkgCache::PkgIterator(void) { return **this; } + + inline const char *Name() const {return (**this).Name(); } + inline std::string FullName(bool const &Pretty) const { return (**this).FullName(Pretty); } + inline std::string FullName() const { return (**this).FullName(); } + inline const char *Section() const {return (**this).Section(); } + inline bool Purge() const {return (**this).Purge(); } + inline const char *Arch() const {return (**this).Arch(); } + inline pkgCache::GrpIterator Group() const { return (**this).Group(); } + inline pkgCache::VerIterator VersionList() const { return (**this).VersionList(); } + inline pkgCache::VerIterator CurrentVer() const { return (**this).CurrentVer(); } + inline pkgCache::DepIterator RevDependsList() const { return (**this).RevDependsList(); } + inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); } + inline pkgCache::PkgIterator::OkState State() const { return (**this).State(); } + inline const char *CandVersion() const { return (**this).CandVersion(); } + inline const char *CurVersion() const { return (**this).CurVersion(); } + inline pkgCache *Cache() const { return (**this).Cache(); }; + inline unsigned long Index() const {return (**this).Index();}; + // we have only valid iterators here + inline bool end() const { return false; }; + + friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, (*i)); } + + inline pkgCache::Package const * operator->() const { + return &***this; + }; + }; + // 103. set::iterator is required to be modifiable, but this allows modification of keys + typedef APT::PackageSet::const_iterator iterator; + /*}}}*/ + + using std::set::insert; + inline void insert(pkgCache::PkgIterator const &P) { if (P.end() == false) std::set::insert(P); }; + inline void insert(PackageSet const &pkgset) { insert(pkgset.begin(), pkgset.end()); }; + + /** \brief returns all packages in the cache who belong to the given task + + A simple helper responsible for search for all members of a task + in the cache. Optional it prints a a notice about the + packages chosen cause of the given task. + \param Cache the packages are in + \param pattern name of the task + \param helper responsible for error and message handling */ + static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); + static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string const &pattern) { + CacheSetHelper helper; + return APT::PackageSet::FromTask(Cache, pattern, helper); + } + + /** \brief returns all packages in the cache whose name matchs a given pattern + + A simple helper responsible for executing a regular expression on all + package names in the cache. Optional it prints a a notice about the + packages chosen cause of the given package. + \param Cache the packages are in + \param pattern regular expression for package names + \param helper responsible for error and message handling */ + static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); + static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string const &pattern) { + CacheSetHelper helper; + return APT::PackageSet::FromRegEx(Cache, pattern, helper); + } + + /** \brief returns all packages specified by a string + + \param Cache the packages are in + \param string String the package name(s) should be extracted from + \param helper responsible for error and message handling */ + static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string, CacheSetHelper &helper); + static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string) { + CacheSetHelper helper; + return APT::PackageSet::FromString(Cache, string, helper); + } + + /** \brief returns a package specified by a string + + \param Cache the package is in + \param string String the package name should be extracted from + \param helper responsible for error and message handling */ + static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &string, CacheSetHelper &helper); + static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &string) { + CacheSetHelper helper; + return APT::PackageSet::FromName(Cache, string, helper); + } + + /** \brief returns all packages specified on the commandline + + Get all package names from the commandline and executes regex's if needed. + No special package command is supported, just plain names. + \param Cache the packages are in + \param cmdline Command line the package names should be extracted from + \param helper responsible for error and message handling */ + static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper); + static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { + CacheSetHelper helper; + return APT::PackageSet::FromCommandLine(Cache, cmdline, helper); + } + + struct Modifier { + enum Position { NONE, PREFIX, POSTFIX }; + unsigned short ID; + const char * const Alias; + Position Pos; + Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {}; + }; + + /** \brief group packages by a action modifiers + + At some point it is needed to get from the same commandline + different package sets grouped by a modifier. Take + apt-get install apt awesome- + as an example. + \param Cache the packages are in + \param cmdline Command line the package names should be extracted from + \param mods list of modifiers the method should accept + \param fallback the default modifier group for a package + \param helper responsible for error and message handling */ + static std::map GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback, CacheSetHelper &helper); + static std::map GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback) { + CacheSetHelper helper; + return APT::PackageSet::GroupedFromCommandLine(Cache, cmdline, + mods, fallback, helper); + } + + enum Constructor { UNKNOWN, REGEX, TASK }; + Constructor getConstructor() const { return ConstructedBy; }; + + PackageSet() : ConstructedBy(UNKNOWN) {}; + PackageSet(Constructor const &by) : ConstructedBy(by) {}; + /*}}}*/ +private: /*{{{*/ + Constructor ConstructedBy; + /*}}}*/ +}; /*}}}*/ +class VersionSet : public std::set { /*{{{*/ +/** \class APT::VersionSet + + Simple wrapper around a std::set to provide a similar interface to + a set of versions as to the complete set of all versions in the + pkgCache. */ +public: /*{{{*/ + /** \brief smell like a pkgCache::VerIterator */ + class const_iterator : public std::set::const_iterator {/*{{{*/ + public: + const_iterator(std::set::const_iterator x) : + std::set::const_iterator(x) {} + + operator pkgCache::VerIterator(void) { return **this; } + + inline pkgCache *Cache() const { return (**this).Cache(); }; + inline unsigned long Index() const {return (**this).Index();}; + // we have only valid iterators here + inline bool end() const { return false; }; + + inline pkgCache::Version const * operator->() const { + return &***this; + }; + + inline int CompareVer(const pkgCache::VerIterator &B) const { return (**this).CompareVer(B); }; + inline const char *VerStr() const { return (**this).VerStr(); }; + inline const char *Section() const { return (**this).Section(); }; + inline const char *Arch() const { return (**this).Arch(); }; + inline const char *Arch(bool const pseudo) const { return (**this).Arch(pseudo); }; + inline pkgCache::PkgIterator ParentPkg() const { return (**this).ParentPkg(); }; + inline pkgCache::DescIterator DescriptionList() const { return (**this).DescriptionList(); }; + inline pkgCache::DescIterator TranslatedDescription() const { return (**this).TranslatedDescription(); }; + inline pkgCache::DepIterator DependsList() const { return (**this).DependsList(); }; + inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); }; + inline pkgCache::VerFileIterator FileList() const { return (**this).FileList(); }; + inline bool Downloadable() const { return (**this).Downloadable(); }; + inline const char *PriorityType() const { return (**this).PriorityType(); }; + inline string RelStr() const { return (**this).RelStr(); }; + inline bool Automatic() const { return (**this).Automatic(); }; + inline bool Pseudo() const { return (**this).Pseudo(); }; + inline pkgCache::VerFileIterator NewestFile() const { return (**this).NewestFile(); }; + }; + /*}}}*/ + // 103. set::iterator is required to be modifiable, but this allows modification of keys + typedef APT::VersionSet::const_iterator iterator; + + using std::set::insert; + inline void insert(pkgCache::VerIterator const &V) { if (V.end() == false) std::set::insert(V); }; + inline void insert(VersionSet const &verset) { insert(verset.begin(), verset.end()); }; + + /** \brief specifies which version(s) will be returned if non is given */ + enum Version { + /** All versions */ + ALL, + /** Candidate and installed version */ + CANDANDINST, + /** Candidate version */ + CANDIDATE, + /** Installed version */ + INSTALLED, + /** Candidate or if non installed version */ + CANDINST, + /** Installed or if non candidate version */ + INSTCAND, + /** Newest version */ + NEWEST + }; + + /** \brief returns all versions specified on the commandline + + Get all versions from the commandline, uses given default version if + non specifically requested and executes regex's if needed on names. + \param Cache the packages and versions are in + \param cmdline Command line the versions should be extracted from + \param helper responsible for error and message handling */ + static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, + APT::VersionSet::Version const &fallback, CacheSetHelper &helper); + static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, + APT::VersionSet::Version const &fallback) { + CacheSetHelper helper; + return APT::VersionSet::FromCommandLine(Cache, cmdline, fallback, helper); + } + static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { + return APT::VersionSet::FromCommandLine(Cache, cmdline, CANDINST); + } + + static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, + APT::VersionSet::Version const &fallback, CacheSetHelper &helper, + bool const &onlyFromName = false); + static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, + APT::VersionSet::Version const &fallback) { + CacheSetHelper helper; + return APT::VersionSet::FromString(Cache, pkg, fallback, helper); + } + static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg) { + return APT::VersionSet::FromString(Cache, pkg, CANDINST); + } + + /** \brief returns all versions specified for the package + + \param Cache the package and versions are in + \param P the package in question + \param fallback the version(s) you want to get + \param helper the helper used for display and error handling */ + static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, + VersionSet::Version const &fallback, CacheSetHelper &helper); + static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, + APT::VersionSet::Version const &fallback) { + CacheSetHelper helper; + return APT::VersionSet::FromPackage(Cache, P, fallback, helper); + } + static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) { + return APT::VersionSet::FromPackage(Cache, P, CANDINST); + } + + struct Modifier { + enum Position { NONE, PREFIX, POSTFIX }; + unsigned short ID; + const char * const Alias; + Position Pos; + VersionSet::Version SelectVersion; + Modifier (unsigned short const &id, const char * const alias, Position const &pos, + VersionSet::Version const &select) : ID(id), Alias(alias), Pos(pos), + SelectVersion(select) {}; + }; + + static std::map GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback, CacheSetHelper &helper); + static std::map GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback) { + CacheSetHelper helper; + return APT::VersionSet::GroupedFromCommandLine(Cache, cmdline, + mods, fallback, helper); + } + /*}}}*/ +protected: /*{{{*/ + + /** \brief returns the candidate version of the package + + \param Cache to be used to query for information + \param Pkg we want the candidate version from this package */ + static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); + + /** \brief returns the installed version of the package + + \param Cache to be used to query for information + \param Pkg we want the installed version from this package */ + static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); + /*}}}*/ +}; /*}}}*/ +} +#endif diff --git a/apt-pkg/makefile b/apt-pkg/makefile index e9e5651b0..4e5ec107f 100644 --- a/apt-pkg/makefile +++ b/apt-pkg/makefile @@ -35,7 +35,7 @@ SOURCE+= pkgcache.cc version.cc depcache.cc \ srcrecords.cc cachefile.cc versionmatch.cc policy.cc \ pkgsystem.cc indexfile.cc pkgcachegen.cc acquire-item.cc \ indexrecords.cc vendor.cc vendorlist.cc cdrom.cc indexcopy.cc \ - aptconfiguration.cc cachefilter.cc + aptconfiguration.cc cachefilter.cc cacheset.cc HEADERS+= algorithms.h depcache.h pkgcachegen.h cacheiterators.h \ orderlist.h sourcelist.h packagemanager.h tagfile.h \ init.h pkgcache.h version.h progress.h pkgrecords.h \ @@ -43,7 +43,7 @@ HEADERS+= algorithms.h depcache.h pkgcachegen.h cacheiterators.h \ clean.h srcrecords.h cachefile.h versionmatch.h policy.h \ pkgsystem.h indexfile.h metaindex.h indexrecords.h vendor.h \ vendorlist.h cdrom.h indexcopy.h aptconfiguration.h \ - cachefilter.h + cachefilter.h cacheset.h # Source code for the debian specific components # In theory the deb headers do not need to be exported.. diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 557996693..1a1ddcb8c 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -30,8 +31,6 @@ #include #include -#include "cacheset.h" - #include #include diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 7cf760c27..eaa982856 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,6 @@ #include #include "acqprogress.h" -#include "cacheset.h" #include #include diff --git a/cmdline/cacheset.cc b/cmdline/cacheset.cc deleted file mode 100644 index 0b099f442..000000000 --- a/cmdline/cacheset.cc +++ /dev/null @@ -1,507 +0,0 @@ -// -*- mode: cpp; mode: fold -*- -// Description /*{{{*/ -/* ###################################################################### - - Simple wrapper around a std::set to provide a similar interface to - a set of cache structures as to the complete set of all structures - in the pkgCache. Currently only Package is supported. - - ##################################################################### */ - /*}}}*/ -// Include Files /*{{{*/ -#include -#include -#include -#include -#include - -#include - -#include "cacheset.h" - -#include - -#include - /*}}}*/ -namespace APT { -// FromTask - Return all packages in the cache from a specific task /*{{{*/ -PackageSet PackageSet::FromTask(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { - size_t const archfound = pattern.find_last_of(':'); - std::string arch = "native"; - if (archfound != std::string::npos) { - arch = pattern.substr(archfound+1); - pattern.erase(archfound); - } - - if (pattern[pattern.length() -1] != '^') - return APT::PackageSet(TASK); - pattern.erase(pattern.length()-1); - - if (unlikely(Cache.GetPkgCache() == 0 || Cache.GetDepCache() == 0)) - return APT::PackageSet(TASK); - - PackageSet pkgset(TASK); - // get the records - pkgRecords Recs(Cache); - - // build regexp for the task - regex_t Pattern; - char S[300]; - snprintf(S, sizeof(S), "^Task:.*[, ]%s([, ]|$)", pattern.c_str()); - if(regcomp(&Pattern,S, REG_EXTENDED | REG_NOSUB | REG_NEWLINE) != 0) { - _error->Error("Failed to compile task regexp"); - return pkgset; - } - - for (pkgCache::GrpIterator Grp = Cache->GrpBegin(); Grp.end() == false; ++Grp) { - pkgCache::PkgIterator Pkg = Grp.FindPkg(arch); - if (Pkg.end() == true) - continue; - pkgCache::VerIterator ver = Cache[Pkg].CandidateVerIter(Cache); - if(ver.end() == true) - continue; - - pkgRecords::Parser &parser = Recs.Lookup(ver.FileList()); - const char *start, *end; - parser.GetRec(start,end); - unsigned int const length = end - start; - char buf[length]; - strncpy(buf, start, length); - buf[length-1] = '\0'; - if (regexec(&Pattern, buf, 0, 0, 0) != 0) - continue; - - pkgset.insert(Pkg); - } - regfree(&Pattern); - - if (pkgset.empty() == true) - return helper.canNotFindTask(Cache, pattern); - - helper.showTaskSelection(pkgset, pattern); - return pkgset; -} - /*}}}*/ -// FromRegEx - Return all packages in the cache matching a pattern /*{{{*/ -PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { - static const char * const isregex = ".?+*|[^$"; - if (pattern.find_first_of(isregex) == std::string::npos) - return PackageSet(REGEX); - - size_t archfound = pattern.find_last_of(':'); - std::string arch = "native"; - if (archfound != std::string::npos) { - arch = pattern.substr(archfound+1); - if (arch.find_first_of(isregex) == std::string::npos) - pattern.erase(archfound); - else - arch = "native"; - } - - if (unlikely(Cache.GetPkgCache() == 0)) - return PackageSet(REGEX); - - APT::CacheFilter::PackageNameMatchesRegEx regexfilter(pattern); - - PackageSet pkgset(REGEX); - for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) { - if (regexfilter(Grp) == false) - continue; - pkgCache::PkgIterator Pkg = Grp.FindPkg(arch); - if (Pkg.end() == true) { - if (archfound == std::string::npos) { - std::vector archs = APT::Configuration::getArchitectures(); - for (std::vector::const_iterator a = archs.begin(); - a != archs.end() && Pkg.end() != true; ++a) - Pkg = Grp.FindPkg(*a); - } - if (Pkg.end() == true) - continue; - } - - pkgset.insert(Pkg); - } - - if (pkgset.empty() == true) - return helper.canNotFindRegEx(Cache, pattern); - - helper.showRegExSelection(pkgset, pattern); - return pkgset; -} - /*}}}*/ -// FromName - Returns the package defined by this string /*{{{*/ -pkgCache::PkgIterator PackageSet::FromName(pkgCacheFile &Cache, - std::string const &str, CacheSetHelper &helper) { - std::string pkg = str; - size_t archfound = pkg.find_last_of(':'); - std::string arch; - if (archfound != std::string::npos) { - arch = pkg.substr(archfound+1); - pkg.erase(archfound); - } - - if (Cache.GetPkgCache() == 0) - return pkgCache::PkgIterator(Cache, 0); - - pkgCache::PkgIterator Pkg(Cache, 0); - if (arch.empty() == true) { - pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(pkg); - if (Grp.end() == false) - Pkg = Grp.FindPreferredPkg(); - } else - Pkg = Cache.GetPkgCache()->FindPkg(pkg, arch); - - if (Pkg.end() == true) - return helper.canNotFindPkgName(Cache, str); - return Pkg; -} - /*}}}*/ -// GroupedFromCommandLine - Return all versions specified on commandline/*{{{*/ -std::map PackageSet::GroupedFromCommandLine( - pkgCacheFile &Cache, const char **cmdline, - std::list const &mods, - unsigned short const &fallback, CacheSetHelper &helper) { - std::map pkgsets; - for (const char **I = cmdline; *I != 0; ++I) { - unsigned short modID = fallback; - std::string str = *I; - bool modifierPresent = false; - for (std::list::const_iterator mod = mods.begin(); - mod != mods.end(); ++mod) { - size_t const alength = strlen(mod->Alias); - switch(mod->Pos) { - case PackageSet::Modifier::POSTFIX: - if (str.compare(str.length() - alength, alength, - mod->Alias, 0, alength) != 0) - continue; - str.erase(str.length() - alength); - modID = mod->ID; - break; - case PackageSet::Modifier::PREFIX: - continue; - case PackageSet::Modifier::NONE: - continue; - } - modifierPresent = true; - break; - } - if (modifierPresent == true) { - bool const errors = helper.showErrors(false); - pkgCache::PkgIterator Pkg = FromName(Cache, *I, helper); - helper.showErrors(errors); - if (Pkg.end() == false) { - pkgsets[fallback].insert(Pkg); - continue; - } - } - pkgsets[modID].insert(PackageSet::FromString(Cache, str, helper)); - } - return pkgsets; -} - /*}}}*/ -// FromCommandLine - Return all packages specified on commandline /*{{{*/ -PackageSet PackageSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) { - PackageSet pkgset; - for (const char **I = cmdline; *I != 0; ++I) { - PackageSet pset = FromString(Cache, *I, helper); - pkgset.insert(pset.begin(), pset.end()); - } - return pkgset; -} - /*}}}*/ -// FromString - Return all packages matching a specific string /*{{{*/ -PackageSet PackageSet::FromString(pkgCacheFile &Cache, std::string const &str, CacheSetHelper &helper) { - _error->PushToStack(); - - PackageSet pkgset; - pkgCache::PkgIterator Pkg = FromName(Cache, str, helper); - if (Pkg.end() == false) - pkgset.insert(Pkg); - else { - pkgset = FromTask(Cache, str, helper); - if (pkgset.empty() == true) { - pkgset = FromRegEx(Cache, str, helper); - if (pkgset.empty() == true) - pkgset = helper.canNotFindPackage(Cache, str); - } - } - - if (pkgset.empty() == false) - _error->RevertToStack(); - else - _error->MergeWithStack(); - return pkgset; -} - /*}}}*/ -// GroupedFromCommandLine - Return all versions specified on commandline/*{{{*/ -std::map VersionSet::GroupedFromCommandLine( - pkgCacheFile &Cache, const char **cmdline, - std::list const &mods, - unsigned short const &fallback, CacheSetHelper &helper) { - std::map versets; - for (const char **I = cmdline; *I != 0; ++I) { - unsigned short modID = fallback; - VersionSet::Version select = VersionSet::NEWEST; - std::string str = *I; - bool modifierPresent = false; - for (std::list::const_iterator mod = mods.begin(); - mod != mods.end(); ++mod) { - if (modID == fallback && mod->ID == fallback) - select = mod->SelectVersion; - size_t const alength = strlen(mod->Alias); - switch(mod->Pos) { - case VersionSet::Modifier::POSTFIX: - if (str.compare(str.length() - alength, alength, - mod->Alias, 0, alength) != 0) - continue; - str.erase(str.length() - alength); - modID = mod->ID; - select = mod->SelectVersion; - break; - case VersionSet::Modifier::PREFIX: - continue; - case VersionSet::Modifier::NONE: - continue; - } - modifierPresent = true; - break; - } - - if (modifierPresent == true) { - bool const errors = helper.showErrors(false); - VersionSet const vset = VersionSet::FromString(Cache, std::string(*I), select, helper, true); - helper.showErrors(errors); - if (vset.empty() == false) { - versets[fallback].insert(vset); - continue; - } - } - versets[modID].insert(VersionSet::FromString(Cache, str, select , helper)); - } - return versets; -} - /*}}}*/ -// FromCommandLine - Return all versions specified on commandline /*{{{*/ -APT::VersionSet VersionSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline, - APT::VersionSet::Version const &fallback, CacheSetHelper &helper) { - VersionSet verset; - for (const char **I = cmdline; *I != 0; ++I) - verset.insert(VersionSet::FromString(Cache, *I, fallback, helper)); - return verset; -} - /*}}}*/ -// FromString - Returns all versions spedcified by a string /*{{{*/ -APT::VersionSet VersionSet::FromString(pkgCacheFile &Cache, std::string pkg, - APT::VersionSet::Version const &fallback, CacheSetHelper &helper, - bool const &onlyFromName) { - std::string ver; - bool verIsRel = false; - size_t const vertag = pkg.find_last_of("/="); - if (vertag != string::npos) { - ver = pkg.substr(vertag+1); - verIsRel = (pkg[vertag] == '/'); - pkg.erase(vertag); - } - PackageSet pkgset; - if (onlyFromName == false) - pkgset = PackageSet::FromString(Cache, pkg, helper); - else { - pkgset.insert(PackageSet::FromName(Cache, pkg, helper)); - } - - VersionSet verset; - bool errors = true; - if (pkgset.getConstructor() != PackageSet::UNKNOWN) - errors = helper.showErrors(false); - for (PackageSet::const_iterator P = pkgset.begin(); - P != pkgset.end(); ++P) { - if (vertag == string::npos) { - verset.insert(VersionSet::FromPackage(Cache, P, fallback, helper)); - continue; - } - pkgCache::VerIterator V; - if (ver == "installed") - V = getInstalledVer(Cache, P, helper); - else if (ver == "candidate") - V = getCandidateVer(Cache, P, helper); - else { - pkgVersionMatch Match(ver, (verIsRel == true ? pkgVersionMatch::Release : - pkgVersionMatch::Version)); - V = Match.Find(P); - if (V.end() == true) { - if (verIsRel == true) - _error->Error(_("Release '%s' for '%s' was not found"), - ver.c_str(), P.FullName(true).c_str()); - else - _error->Error(_("Version '%s' for '%s' was not found"), - ver.c_str(), P.FullName(true).c_str()); - continue; - } - } - if (V.end() == true) - continue; - helper.showSelectedVersion(P, V, ver, verIsRel); - verset.insert(V); - } - if (pkgset.getConstructor() != PackageSet::UNKNOWN) - helper.showErrors(errors); - return verset; -} - /*}}}*/ -// FromPackage - versions from package based on fallback /*{{{*/ -VersionSet VersionSet::FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, - VersionSet::Version const &fallback, CacheSetHelper &helper) { - VersionSet verset; - pkgCache::VerIterator V; - bool showErrors; - switch(fallback) { - case VersionSet::ALL: - if (P->VersionList != 0) - for (V = P.VersionList(); V.end() != true; ++V) - verset.insert(V); - else - verset.insert(helper.canNotFindAllVer(Cache, P)); - break; - case VersionSet::CANDANDINST: - verset.insert(getInstalledVer(Cache, P, helper)); - verset.insert(getCandidateVer(Cache, P, helper)); - break; - case VersionSet::CANDIDATE: - verset.insert(getCandidateVer(Cache, P, helper)); - break; - case VersionSet::INSTALLED: - verset.insert(getInstalledVer(Cache, P, helper)); - break; - case VersionSet::CANDINST: - showErrors = helper.showErrors(false); - V = getCandidateVer(Cache, P, helper); - if (V.end() == true) - V = getInstalledVer(Cache, P, helper); - helper.showErrors(showErrors); - if (V.end() == false) - verset.insert(V); - else - verset.insert(helper.canNotFindInstCandVer(Cache, P)); - break; - case VersionSet::INSTCAND: - showErrors = helper.showErrors(false); - V = getInstalledVer(Cache, P, helper); - if (V.end() == true) - V = getCandidateVer(Cache, P, helper); - helper.showErrors(showErrors); - if (V.end() == false) - verset.insert(V); - else - verset.insert(helper.canNotFindInstCandVer(Cache, P)); - break; - case VersionSet::NEWEST: - if (P->VersionList != 0) - verset.insert(P.VersionList()); - else - verset.insert(helper.canNotFindNewestVer(Cache, P)); - break; - } - return verset; -} - /*}}}*/ -// getCandidateVer - Returns the candidate version of the given package /*{{{*/ -pkgCache::VerIterator VersionSet::getCandidateVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) { - pkgCache::VerIterator Cand; - if (Cache.IsPolicyBuilt() == true || Cache.IsDepCacheBuilt() == false) - { - if (unlikely(Cache.GetPolicy() == 0)) - return pkgCache::VerIterator(Cache); - Cand = Cache.GetPolicy()->GetCandidateVer(Pkg); - } else { - Cand = Cache[Pkg].CandidateVerIter(Cache); - } - if (Cand.end() == true) - return helper.canNotFindCandidateVer(Cache, Pkg); - return Cand; -} - /*}}}*/ -// getInstalledVer - Returns the installed version of the given package /*{{{*/ -pkgCache::VerIterator VersionSet::getInstalledVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) { - if (Pkg->CurrentVer == 0) - return helper.canNotFindInstalledVer(Cache, Pkg); - return Pkg.CurrentVer(); -} - /*}}}*/ -// canNotFindPkgName - handle the case no package has this name /*{{{*/ -pkgCache::PkgIterator CacheSetHelper::canNotFindPkgName(pkgCacheFile &Cache, - std::string const &str) { - if (ShowError == true) - _error->Error(_("Unable to locate package %s"), str.c_str()); - return pkgCache::PkgIterator(Cache, 0); -} - /*}}}*/ -// canNotFindTask - handle the case no package is found for a task /*{{{*/ -PackageSet CacheSetHelper::canNotFindTask(pkgCacheFile &Cache, std::string pattern) { - if (ShowError == true) - _error->Error(_("Couldn't find task '%s'"), pattern.c_str()); - return PackageSet(); -} - /*}}}*/ -// canNotFindRegEx - handle the case no package is found by a regex /*{{{*/ -PackageSet CacheSetHelper::canNotFindRegEx(pkgCacheFile &Cache, std::string pattern) { - if (ShowError == true) - _error->Error(_("Couldn't find any package by regex '%s'"), pattern.c_str()); - return PackageSet(); -} - /*}}}*/ -// canNotFindPackage - handle the case no package is found from a string/*{{{*/ -PackageSet CacheSetHelper::canNotFindPackage(pkgCacheFile &Cache, std::string const &str) { - return PackageSet(); -} - /*}}}*/ -// canNotFindAllVer /*{{{*/ -VersionSet CacheSetHelper::canNotFindAllVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg) { - if (ShowError == true) - _error->Error(_("Can't select versions from package '%s' as it purely virtual"), Pkg.FullName(true).c_str()); - return VersionSet(); -} - /*}}}*/ -// canNotFindInstCandVer /*{{{*/ -VersionSet CacheSetHelper::canNotFindInstCandVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg) { - if (ShowError == true) - _error->Error(_("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str()); - return VersionSet(); -} - /*}}}*/ -// canNotFindInstCandVer /*{{{*/ -VersionSet CacheSetHelper::canNotFindCandInstVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg) { - if (ShowError == true) - _error->Error(_("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str()); - return VersionSet(); -} - /*}}}*/ -// canNotFindNewestVer /*{{{*/ -pkgCache::VerIterator CacheSetHelper::canNotFindNewestVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg) { - if (ShowError == true) - _error->Error(_("Can't select newest version from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str()); - return pkgCache::VerIterator(Cache, 0); -} - /*}}}*/ -// canNotFindCandidateVer /*{{{*/ -pkgCache::VerIterator CacheSetHelper::canNotFindCandidateVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg) { - if (ShowError == true) - _error->Error(_("Can't select candidate version from package %s as it has no candidate"), Pkg.FullName(true).c_str()); - return pkgCache::VerIterator(Cache, 0); -} - /*}}}*/ -// canNotFindInstalledVer /*{{{*/ -pkgCache::VerIterator CacheSetHelper::canNotFindInstalledVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg) { - if (ShowError == true) - _error->Error(_("Can't select installed version from package %s as it is not installed"), Pkg.FullName(true).c_str()); - return pkgCache::VerIterator(Cache, 0); -} - /*}}}*/ -} diff --git a/cmdline/cacheset.h b/cmdline/cacheset.h deleted file mode 100644 index c8c3dd096..000000000 --- a/cmdline/cacheset.h +++ /dev/null @@ -1,375 +0,0 @@ -// -*- mode: cpp; mode: fold -*- -// Description /*{{{*/ -/** \file cacheset.h - Wrappers around std::set to have set::iterators which behave - similar to the Iterators of the cache structures. - - Provides also a few helper methods which work with these sets */ - /*}}}*/ -#ifndef APT_CACHESET_H -#define APT_CACHESET_H -// Include Files /*{{{*/ -#include -#include -#include -#include -#include -#include - -#include -#include - /*}}}*/ -namespace APT { -class PackageSet; -class VersionSet; -class CacheSetHelper { /*{{{*/ -/** \class APT::CacheSetHelper - Simple base class with a lot of virtual methods which can be overridden - to alter the behavior or the output of the CacheSets. - - This helper is passed around by the static methods in the CacheSets and - used every time they hit an error condition or something could be - printed out. -*/ -public: /*{{{*/ - CacheSetHelper(bool const &ShowError = true) : ShowError(ShowError) {}; - virtual ~CacheSetHelper() {}; - - virtual void showTaskSelection(PackageSet const &pkgset, string const &pattern) {}; - virtual void showRegExSelection(PackageSet const &pkgset, string const &pattern) {}; - virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver, - string const &ver, bool const &verIsRel) {}; - - virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str); - virtual PackageSet canNotFindTask(pkgCacheFile &Cache, std::string pattern); - virtual PackageSet canNotFindRegEx(pkgCacheFile &Cache, std::string pattern); - virtual PackageSet canNotFindPackage(pkgCacheFile &Cache, std::string const &str); - virtual VersionSet canNotFindAllVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); - virtual VersionSet canNotFindInstCandVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg); - virtual VersionSet canNotFindCandInstVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg); - virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg); - virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg); - virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg); - - bool showErrors() const { return ShowError; }; - bool showErrors(bool const &newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); }; - /*}}}*/ -protected: - bool ShowError; -}; /*}}}*/ -class PackageSet : public std::set { /*{{{*/ -/** \class APT::PackageSet - - Simple wrapper around a std::set to provide a similar interface to - a set of packages as to the complete set of all packages in the - pkgCache. */ -public: /*{{{*/ - /** \brief smell like a pkgCache::PkgIterator */ - class const_iterator : public std::set::const_iterator {/*{{{*/ - public: - const_iterator(std::set::const_iterator x) : - std::set::const_iterator(x) {} - - operator pkgCache::PkgIterator(void) { return **this; } - - inline const char *Name() const {return (**this).Name(); } - inline std::string FullName(bool const &Pretty) const { return (**this).FullName(Pretty); } - inline std::string FullName() const { return (**this).FullName(); } - inline const char *Section() const {return (**this).Section(); } - inline bool Purge() const {return (**this).Purge(); } - inline const char *Arch() const {return (**this).Arch(); } - inline pkgCache::GrpIterator Group() const { return (**this).Group(); } - inline pkgCache::VerIterator VersionList() const { return (**this).VersionList(); } - inline pkgCache::VerIterator CurrentVer() const { return (**this).CurrentVer(); } - inline pkgCache::DepIterator RevDependsList() const { return (**this).RevDependsList(); } - inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); } - inline pkgCache::PkgIterator::OkState State() const { return (**this).State(); } - inline const char *CandVersion() const { return (**this).CandVersion(); } - inline const char *CurVersion() const { return (**this).CurVersion(); } - inline pkgCache *Cache() const { return (**this).Cache(); }; - inline unsigned long Index() const {return (**this).Index();}; - // we have only valid iterators here - inline bool end() const { return false; }; - - friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, (*i)); } - - inline pkgCache::Package const * operator->() const { - return &***this; - }; - }; - // 103. set::iterator is required to be modifiable, but this allows modification of keys - typedef APT::PackageSet::const_iterator iterator; - /*}}}*/ - - using std::set::insert; - inline void insert(pkgCache::PkgIterator const &P) { if (P.end() == false) std::set::insert(P); }; - inline void insert(PackageSet const &pkgset) { insert(pkgset.begin(), pkgset.end()); }; - - /** \brief returns all packages in the cache who belong to the given task - - A simple helper responsible for search for all members of a task - in the cache. Optional it prints a a notice about the - packages chosen cause of the given task. - \param Cache the packages are in - \param pattern name of the task - \param helper responsible for error and message handling */ - static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); - static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string const &pattern) { - CacheSetHelper helper; - return APT::PackageSet::FromTask(Cache, pattern, helper); - } - - /** \brief returns all packages in the cache whose name matchs a given pattern - - A simple helper responsible for executing a regular expression on all - package names in the cache. Optional it prints a a notice about the - packages chosen cause of the given package. - \param Cache the packages are in - \param pattern regular expression for package names - \param helper responsible for error and message handling */ - static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); - static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string const &pattern) { - CacheSetHelper helper; - return APT::PackageSet::FromRegEx(Cache, pattern, helper); - } - - /** \brief returns all packages specified by a string - - \param Cache the packages are in - \param string String the package name(s) should be extracted from - \param helper responsible for error and message handling */ - static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string, CacheSetHelper &helper); - static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string) { - CacheSetHelper helper; - return APT::PackageSet::FromString(Cache, string, helper); - } - - /** \brief returns a package specified by a string - - \param Cache the package is in - \param string String the package name should be extracted from - \param helper responsible for error and message handling */ - static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &string, CacheSetHelper &helper); - static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &string) { - CacheSetHelper helper; - return APT::PackageSet::FromName(Cache, string, helper); - } - - /** \brief returns all packages specified on the commandline - - Get all package names from the commandline and executes regex's if needed. - No special package command is supported, just plain names. - \param Cache the packages are in - \param cmdline Command line the package names should be extracted from - \param helper responsible for error and message handling */ - static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper); - static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { - CacheSetHelper helper; - return APT::PackageSet::FromCommandLine(Cache, cmdline, helper); - } - - struct Modifier { - enum Position { NONE, PREFIX, POSTFIX }; - unsigned short ID; - const char * const Alias; - Position Pos; - Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {}; - }; - - /** \brief group packages by a action modifiers - - At some point it is needed to get from the same commandline - different package sets grouped by a modifier. Take - apt-get install apt awesome- - as an example. - \param Cache the packages are in - \param cmdline Command line the package names should be extracted from - \param mods list of modifiers the method should accept - \param fallback the default modifier group for a package - \param helper responsible for error and message handling */ - static std::map GroupedFromCommandLine( - pkgCacheFile &Cache, const char **cmdline, - std::list const &mods, - unsigned short const &fallback, CacheSetHelper &helper); - static std::map GroupedFromCommandLine( - pkgCacheFile &Cache, const char **cmdline, - std::list const &mods, - unsigned short const &fallback) { - CacheSetHelper helper; - return APT::PackageSet::GroupedFromCommandLine(Cache, cmdline, - mods, fallback, helper); - } - - enum Constructor { UNKNOWN, REGEX, TASK }; - Constructor getConstructor() const { return ConstructedBy; }; - - PackageSet() : ConstructedBy(UNKNOWN) {}; - PackageSet(Constructor const &by) : ConstructedBy(by) {}; - /*}}}*/ -private: /*{{{*/ - Constructor ConstructedBy; - /*}}}*/ -}; /*}}}*/ -class VersionSet : public std::set { /*{{{*/ -/** \class APT::VersionSet - - Simple wrapper around a std::set to provide a similar interface to - a set of versions as to the complete set of all versions in the - pkgCache. */ -public: /*{{{*/ - /** \brief smell like a pkgCache::VerIterator */ - class const_iterator : public std::set::const_iterator {/*{{{*/ - public: - const_iterator(std::set::const_iterator x) : - std::set::const_iterator(x) {} - - operator pkgCache::VerIterator(void) { return **this; } - - inline pkgCache *Cache() const { return (**this).Cache(); }; - inline unsigned long Index() const {return (**this).Index();}; - // we have only valid iterators here - inline bool end() const { return false; }; - - inline pkgCache::Version const * operator->() const { - return &***this; - }; - - inline int CompareVer(const pkgCache::VerIterator &B) const { return (**this).CompareVer(B); }; - inline const char *VerStr() const { return (**this).VerStr(); }; - inline const char *Section() const { return (**this).Section(); }; - inline const char *Arch() const { return (**this).Arch(); }; - inline const char *Arch(bool const pseudo) const { return (**this).Arch(pseudo); }; - inline pkgCache::PkgIterator ParentPkg() const { return (**this).ParentPkg(); }; - inline pkgCache::DescIterator DescriptionList() const { return (**this).DescriptionList(); }; - inline pkgCache::DescIterator TranslatedDescription() const { return (**this).TranslatedDescription(); }; - inline pkgCache::DepIterator DependsList() const { return (**this).DependsList(); }; - inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); }; - inline pkgCache::VerFileIterator FileList() const { return (**this).FileList(); }; - inline bool Downloadable() const { return (**this).Downloadable(); }; - inline const char *PriorityType() const { return (**this).PriorityType(); }; - inline string RelStr() const { return (**this).RelStr(); }; - inline bool Automatic() const { return (**this).Automatic(); }; - inline bool Pseudo() const { return (**this).Pseudo(); }; - inline pkgCache::VerFileIterator NewestFile() const { return (**this).NewestFile(); }; - }; - /*}}}*/ - // 103. set::iterator is required to be modifiable, but this allows modification of keys - typedef APT::VersionSet::const_iterator iterator; - - using std::set::insert; - inline void insert(pkgCache::VerIterator const &V) { if (V.end() == false) std::set::insert(V); }; - inline void insert(VersionSet const &verset) { insert(verset.begin(), verset.end()); }; - - /** \brief specifies which version(s) will be returned if non is given */ - enum Version { - /** All versions */ - ALL, - /** Candidate and installed version */ - CANDANDINST, - /** Candidate version */ - CANDIDATE, - /** Installed version */ - INSTALLED, - /** Candidate or if non installed version */ - CANDINST, - /** Installed or if non candidate version */ - INSTCAND, - /** Newest version */ - NEWEST - }; - - /** \brief returns all versions specified on the commandline - - Get all versions from the commandline, uses given default version if - non specifically requested and executes regex's if needed on names. - \param Cache the packages and versions are in - \param cmdline Command line the versions should be extracted from - \param helper responsible for error and message handling */ - static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, - APT::VersionSet::Version const &fallback, CacheSetHelper &helper); - static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, - APT::VersionSet::Version const &fallback) { - CacheSetHelper helper; - return APT::VersionSet::FromCommandLine(Cache, cmdline, fallback, helper); - } - static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { - return APT::VersionSet::FromCommandLine(Cache, cmdline, CANDINST); - } - - static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, - APT::VersionSet::Version const &fallback, CacheSetHelper &helper, - bool const &onlyFromName = false); - static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, - APT::VersionSet::Version const &fallback) { - CacheSetHelper helper; - return APT::VersionSet::FromString(Cache, pkg, fallback, helper); - } - static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg) { - return APT::VersionSet::FromString(Cache, pkg, CANDINST); - } - - /** \brief returns all versions specified for the package - - \param Cache the package and versions are in - \param P the package in question - \param fallback the version(s) you want to get - \param helper the helper used for display and error handling */ - static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, - VersionSet::Version const &fallback, CacheSetHelper &helper); - static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, - APT::VersionSet::Version const &fallback) { - CacheSetHelper helper; - return APT::VersionSet::FromPackage(Cache, P, fallback, helper); - } - static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) { - return APT::VersionSet::FromPackage(Cache, P, CANDINST); - } - - struct Modifier { - enum Position { NONE, PREFIX, POSTFIX }; - unsigned short ID; - const char * const Alias; - Position Pos; - VersionSet::Version SelectVersion; - Modifier (unsigned short const &id, const char * const alias, Position const &pos, - VersionSet::Version const &select) : ID(id), Alias(alias), Pos(pos), - SelectVersion(select) {}; - }; - - static std::map GroupedFromCommandLine( - pkgCacheFile &Cache, const char **cmdline, - std::list const &mods, - unsigned short const &fallback, CacheSetHelper &helper); - static std::map GroupedFromCommandLine( - pkgCacheFile &Cache, const char **cmdline, - std::list const &mods, - unsigned short const &fallback) { - CacheSetHelper helper; - return APT::VersionSet::GroupedFromCommandLine(Cache, cmdline, - mods, fallback, helper); - } - /*}}}*/ -protected: /*{{{*/ - - /** \brief returns the candidate version of the package - - \param Cache to be used to query for information - \param Pkg we want the candidate version from this package */ - static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); - - /** \brief returns the installed version of the package - - \param Cache to be used to query for information - \param Pkg we want the installed version from this package */ - static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); - /*}}}*/ -}; /*}}}*/ -} -#endif diff --git a/cmdline/makefile b/cmdline/makefile index 4ffe49ee0..917ccc96a 100644 --- a/cmdline/makefile +++ b/cmdline/makefile @@ -9,14 +9,14 @@ include ../buildlib/defaults.mak PROGRAM=apt-cache SLIBS = -lapt-pkg $(INTLLIBS) LIB_MAKES = apt-pkg/makefile -SOURCE = apt-cache.cc cacheset.cc +SOURCE = apt-cache.cc include $(PROGRAM_H) # The apt-get program PROGRAM=apt-get SLIBS = -lapt-pkg -lutil $(INTLLIBS) LIB_MAKES = apt-pkg/makefile -SOURCE = apt-get.cc acqprogress.cc cacheset.cc +SOURCE = apt-get.cc acqprogress.cc include $(PROGRAM_H) # The apt-config program diff --git a/debian/changelog b/debian/changelog index 128309b51..04829715c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,8 +5,10 @@ apt (0.7.26~exp11) experimental; urgency=low - handle "circular" conflicts for "all" packages correctly * cmdline/apt-cache.cc: - be able to omit dependency types in (r)depends (Closes: #319006) + * apt-pkg/cacheset.cc: + - move them back to the library as they look stable now - -- David Kalnischkies Wed, 14 Jul 2010 22:58:08 +0200 + -- David Kalnischkies Sat, 17 Jul 2010 19:56:47 +0200 apt (0.7.26~exp10) experimental; urgency=low -- cgit v1.2.3 From 3db58cf41785f1e0b7046bbe7f3ef5e545c9a658 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 25 Jul 2010 08:24:03 +0200 Subject: * apt-pkg/pkgcache.cc: - prefer non-virtual packages in FindPreferredPkg --- apt-pkg/cacheiterators.h | 7 +++++-- apt-pkg/pkgcache.cc | 8 +++++--- debian/changelog | 4 +++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index 1dcc34532..0be9368bd 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -115,8 +115,11 @@ class pkgCache::GrpIterator: public Iterator { /** \brief find the package with the "best" architecture The best architecture is either the "native" or the first - in the list of Architectures which is not an end-Pointer */ - PkgIterator FindPreferredPkg() const; + in the list of Architectures which is not an end-Pointer + + \param PreferNonVirtual tries to respond with a non-virtual package + and only if this fails returns the best virtual package */ + PkgIterator FindPreferredPkg(bool const &PreferNonVirtual = true) const; PkgIterator NextPkg(PkgIterator const &Pkg) const; // Constructors diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 8af8ef7de..9e1f8b633 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -349,19 +349,21 @@ pkgCache::PkgIterator pkgCache::GrpIterator::FindPkg(string Arch) const { // GrpIterator::FindPreferredPkg - Locate the "best" package /*{{{*/ // --------------------------------------------------------------------- /* Returns an End-Pointer on error, pointer to the package otherwise */ -pkgCache::PkgIterator pkgCache::GrpIterator::FindPreferredPkg() const { +pkgCache::PkgIterator pkgCache::GrpIterator::FindPreferredPkg(bool const &PreferNonVirtual) const { pkgCache::PkgIterator Pkg = FindPkg("native"); - if (Pkg.end() == false) + if (Pkg.end() == false && (PreferNonVirtual == false || Pkg->VersionList != 0)) return Pkg; std::vector const archs = APT::Configuration::getArchitectures(); for (std::vector::const_iterator a = archs.begin(); a != archs.end(); ++a) { Pkg = FindPkg(*a); - if (Pkg.end() == false) + if (Pkg.end() == false && (PreferNonVirtual == false || Pkg->VersionList != 0)) return Pkg; } + if (PreferNonVirtual == true) + return FindPreferredPkg(false); return PkgIterator(*Owner, 0); } /*}}}*/ diff --git a/debian/changelog b/debian/changelog index 04829715c..aff194e1c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,8 +7,10 @@ apt (0.7.26~exp11) experimental; urgency=low - be able to omit dependency types in (r)depends (Closes: #319006) * apt-pkg/cacheset.cc: - move them back to the library as they look stable now + * apt-pkg/pkgcache.cc: + - prefer non-virtual packages in FindPreferredPkg - -- David Kalnischkies Sat, 17 Jul 2010 19:56:47 +0200 + -- David Kalnischkies Sun, 25 Jul 2010 08:20:41 +0200 apt (0.7.26~exp10) experimental; urgency=low -- cgit v1.2.3 From 8d87641558a7e0ee53b03e325614532aa686e01b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 25 Jul 2010 19:51:53 +0200 Subject: - prefer non-virtual packages in FindPreferredPkg (Closes: #590041) * test/integration/*: - add with bug#590041 testcase a small test "framework" --- debian/changelog | 6 +- test/integration/framework | 170 +++++++++++++++++++++ test/integration/run-tests | 8 + .../test-bug-590041-prefer-non-virtual-packages | 51 +++++++ 4 files changed, 233 insertions(+), 2 deletions(-) create mode 100644 test/integration/framework create mode 100755 test/integration/run-tests create mode 100755 test/integration/test-bug-590041-prefer-non-virtual-packages diff --git a/debian/changelog b/debian/changelog index aff194e1c..1aa05adcb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,9 +8,11 @@ apt (0.7.26~exp11) experimental; urgency=low * apt-pkg/cacheset.cc: - move them back to the library as they look stable now * apt-pkg/pkgcache.cc: - - prefer non-virtual packages in FindPreferredPkg + - prefer non-virtual packages in FindPreferredPkg (Closes: #590041) + * test/integration/*: + - add with bug#590041 testcase a small test "framework" - -- David Kalnischkies Sun, 25 Jul 2010 08:20:41 +0200 + -- David Kalnischkies Sun, 25 Jul 2010 19:37:45 +0200 apt (0.7.26~exp10) experimental; urgency=low diff --git a/test/integration/framework b/test/integration/framework new file mode 100644 index 000000000..97dce1e19 --- /dev/null +++ b/test/integration/framework @@ -0,0 +1,170 @@ +#!/bin/sh -- # no runable script, just for vi + +# we all like colorful messages +CERROR="" # red +CWARNING="" # yellow +CMSG="" # green +CINFO="" # light blue +CDEBUG="" # blue +CNORMAL="" # default system console color +CDONE="" # green +CPASS="" # green +CFAIL="" # red +CCMD="" # pink + +msgdie() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; } +msgwarn() { echo "${CWARNING}W: $1${CNORMAL}" >&2; } +msgmsg() { echo "${CMSG}$1${CNORMAL}" >&2; } +msginfo() { echo "${CINFO}I: $1${CNORMAL}" >&2; } +msgdebug() { echo "${CDEBUG}D: $1${CNORMAL}" >&2; } +msgdone() { echo "${CDONE}DONE${CNORMAL}" >&2; } +msgnwarn() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; } +msgnmsg() { echo -n "${CMSG}$1${CNORMAL}" >&2; } +msgninfo() { echo -n "${CINFO}I: $1${CNORMAL}" >&2; } +msgndebug() { echo -n "${CDEBUG}D: $1${CNORMAL}" >&2; } +msgtest() { echo -n "${CINFO}$1 ${CCMD}$(echo "$2" | sed -e 's/^aptc/apt-c/' -e 's/^aptg/apt-g/' -e 's/^aptf/apt-f/')${CINFO} …${CNORMAL} " >&2; } +msgpass() { echo "${CPASS}PASS${CNORMAL}" >&2; } +msgskip() { echo "${CWARNING}SKIP${CNORMAL}" >&2; } +msgfail() { echo "${CFAIL}FAIL${CNORMAL}" >&2; } + +# enable / disable Debugging +msginfo() { true; } +msgdebug() { true; } +msgninfo() { true; } +msgndebug() { true; } +msgdone() { if [ "$1" = "debug" -o "$1" = "info" ]; then true; else echo "${CDONE}DONE${CNORMAL}" >&2; fi } + +runapt() { + msgdebug "Executing: ${CCMD}$*${CDEBUG} " + APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$* +} +aptconfig() { runapt apt-config $*; } +aptcache() { runapt apt-cache $*; } +aptget() { runapt apt-get $*; } +aptftparchive() { runapt apt-ftparchive $*; } + +setupenvironment() { + local TMPWORKINGDIRECTORY=$(mktemp -d) + msgninfo "Preparing environment for ${CCMD}$0${CINFO} in ${TMPWORKINGDIRECTORY}… " + BUILDDIRECTORY=$(readlink -f $(dirname $0)/../../build/bin) + test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first" + local OLDWORKINGDIRECTORY=$(pwd) + trap "cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM + cd $TMPWORKINGDIRECTORY + mkdir rootdir aptarchive + cd rootdir + mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d var/cache var/lib/dpkg + mkdir -p var/cache/apt/archives/partial var/lib/apt/lists/partial + touch var/lib/dpkg/status + mkdir -p usr/lib/apt + ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods + cd .. + echo "RootDir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf + echo "Debug::NoLocking \"true\";" >> aptconfig.conf + echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf + export LC_ALL=C + msgdone "info" +} + +configarchitecture() { + local CONFFILE=rootdir/etc/apt/apt.conf.d/01multiarch.conf + echo "APT::Architecture \"$1\";" > $CONFFILE + shift + while [ -n "$1" ]; do + echo "APT::Architectures:: \"$1\";" >> $CONFFILE + shift + done +} + +buildflataptarchive() { + msginfo "Build APT archive for ${CCMD}$0${CINFO}…" + cd aptarchive + APTARCHIVE=$(readlink -f .) + if [ -f Packages ]; then + msgninfo "\tPackages file… " + cat Packages | gzip > Packages.gz + cat Packages | bzip2 > Packages.bz2 + cat Packages | lzma > Packages.lzma + msgdone "info" + fi + if [ -f Sources ]; then + msgninfo "\tSources file… " + cat Sources | gzip > Sources.gz + cat Sources | bzip2 > Sources.bz2 + cat Sources | lzma > Sources.lzma + msgdone "info" + fi + cd .. + aptftparchive release . > Release +} + +setupflataptarchive() { + buildflataptarchive + APTARCHIVE=$(readlink -f ./aptarchive) + if [ -f ${APTARCHIVE}/Packages ]; then + msgninfo "\tadd deb sources.list line… " + echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list + msgdone "info" + else + rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list + fi + if [ -f ${APTARCHIVE}/Sources ]; then + msgninfo "\tadd deb-src sources.list line… " + echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list + msgdone "info" + else + rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list + fi + aptget update -qq +} + +diff() { + local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')" + if [ -n "$DIFFTEXT" ]; then + echo + echo "$DIFFTEXT" + return 1 + else + return 0 + fi +} + +testequal() { + local COMPAREFILE=$(mktemp) + echo "$1" > $COMPAREFILE + shift + msgtest "Test for equality of" "$*" + $* 2>&1 | diff $COMPAREFILE - && msgpass || msgfail +} + +testshowvirtual() { + local VIRTUAL="E: Can't select versions from package '$1' as it purely virtual" + local PACKAGE="$1" + shift + while [ -n "$1" ]; do + VIRTUAL="${VIRTUAL} +E: Can't select versions from package '$1' as it purely virtual" + PACKAGE="${PACKAGE} $1" + shift + done + msgtest "Test for virtual packages" "apt-cache show $PACKAGE" + VIRTUAL="${VIRTUAL} +E: No packages found" + local COMPAREFILE=$(mktemp) + local ARCH=$(dpkg-architecture -qDEB_HOST_ARCH_CPU) + eval `apt-config shell ARCH APT::Architecture` + echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE + aptcache show $PACKAGE 2>&1 | diff $COMPAREFILE - && msgpass || msgfail +} + +testnopackage() { + msgtest "Test for non-existent packages" "apt-cache show $*" + local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')" + if [ -n "$SHOWPKG" ]; then + echo + echo "$SHOWPKG" + msgfail + return 1 + fi + msgpass +} diff --git a/test/integration/run-tests b/test/integration/run-tests new file mode 100755 index 000000000..cb74f21e7 --- /dev/null +++ b/test/integration/run-tests @@ -0,0 +1,8 @@ +#!/bin/sh +set -e + +local DIR=$(readlink -f $(dirname $0)) +for testcase in $(run-parts --list $DIR | grep '/test-'); do + echo "\033[1;32mRun Testcase \033[1;35m$(basename ${testcase})\033[0m" + ${testcase} +done diff --git a/test/integration/test-bug-590041-prefer-non-virtual-packages b/test/integration/test-bug-590041-prefer-non-virtual-packages new file mode 100755 index 000000000..aa9e487e1 --- /dev/null +++ b/test/integration/test-bug-590041-prefer-non-virtual-packages @@ -0,0 +1,51 @@ +#!/bin/sh +set -e + +. $(readlink -f $(dirname $0))/framework +setupenvironment +configarchitecture "i386" "armel" + +pkglibc6="Package: libc6 +Architecture: armel +Version: 2.11.2-2~0.3 +Description: Embedded GNU C Library: Shared libraries +Filename: pool/main/e/eglibc/libc6_2.11.2-2_armel.deb +Installed-Size: 9740 +MD5sum: f5b878ce5fb8aa01a7927fa1460df537 +Maintainer: GNU Libc Maintainers +Priority: required +SHA1: 0464d597dfbf949e8c17a42325b1f93fb4914afd +SHA256: faca4a3d9ccff57568abf41f6cb81ddd835be7b5d8b0161e2d5f9a7f26aae3c0 +Section: libs +Size: 4178958 +" + +pkglibdb1="Package: libdb1 +Architecture: i386 +Version: 2.1.3-13~0.3 +Replaces: libc6 (<< 2.2.5-13~0.3) +Description: The Berkeley database routines [glibc 2.0/2.1 compatibility] +Filename: pool/main/d/db1-compat/libdb1-compat_2.1.3-13_armel.deb +Installed-Size: 136 +MD5sum: 4043f176ab2b40b0c01bc1211b8c103c +Maintainer: Colin Watson +Priority: extra +SHA1: b9396fdd2e3e8d1d4ba9e74e7346075852d85666 +SHA256: f17decaa28d1db3eeb9eb17bebe50d437d293a509bcdd7cdfd3ebb56f5de3cea +Section: oldlibs +Size: 44168 +" + +cat <<-EOF >aptarchive/Packages +$pkglibc6 +$pkglibdb1 +EOF + +setupflataptarchive + +testshowvirtual libc6:i386 +testequal "$pkglibc6" aptcache show libc6:armel +testequal "$pkglibc6" aptcache show libc6 +testequal "$pkglibdb1" aptcache show libdb1:i386 +testnopackage libdb1:armel +testequal "$pkglibdb1" aptcache show libdb1 -- cgit v1.2.3 From f6bfb482a32543deed925b127c972a7c258df4a1 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 25 Jul 2010 20:04:16 +0200 Subject: Strip the .sh extension from the libapt testrunner and make it a bit more robust against calling from outside --- test/libapt/run-tests | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ test/libapt/run-tests.sh | 60 ----------------------------------------------- 2 files changed, 61 insertions(+), 60 deletions(-) create mode 100755 test/libapt/run-tests delete mode 100755 test/libapt/run-tests.sh diff --git a/test/libapt/run-tests b/test/libapt/run-tests new file mode 100755 index 000000000..0f55f7386 --- /dev/null +++ b/test/libapt/run-tests @@ -0,0 +1,61 @@ +#!/bin/sh +set -e + +local DIR=$(readlink -f $(dirname $0)) +echo "Compiling the tests …" +test -d "$DIR/../../build/obj/test/libapt/" || mkdir -p "$DIR/../../build/obj/test/libapt/" +$(cd $DIR && make) +echo "Running all testcases …" +LDPATH="$DIR/../../build/bin" +EXT="_libapt_test" +for testapp in $(ls ${LDPATH}/*$EXT) +do + name=$(basename ${testapp}) + tmppath="" + + if [ $name = "GetListOfFilesInDir${EXT}" ]; then + # TODO: very-low: move env creation to the actual test-app + echo "Prepare Testarea for \033[1;35m$name\033[0m ..." + tmppath=$(mktemp -d) + touch "${tmppath}/anormalfile" \ + "${tmppath}/01yet-anothernormalfile" \ + "${tmppath}/anormalapt.conf" \ + "${tmppath}/01yet-anotherapt.conf" \ + "${tmppath}/anormalapt.list" \ + "${tmppath}/01yet-anotherapt.list" \ + "${tmppath}/wrongextension.wron" \ + "${tmppath}/wrong-extension.wron" \ + "${tmppath}/strangefile." \ + "${tmppath}/s.t.r.a.n.g.e.f.i.l.e" \ + "${tmppath}/.hiddenfile" \ + "${tmppath}/.hiddenfile.conf" \ + "${tmppath}/.hiddenfile.list" \ + "${tmppath}/multi..dot" \ + "${tmppath}/multi.dot.conf" \ + "${tmppath}/multi.dot.list" \ + "${tmppath}/disabledfile.disabled" \ + "${tmppath}/disabledfile.conf.disabled" \ + "${tmppath}/disabledfile.list.disabled" \ + "${tmppath}/invälid.conf" \ + "${tmppath}/invalíd" \ + "${tmppath}/01invalíd" + ln -s "${tmppath}/anormalfile" "${tmppath}/linkedfile.list" + ln -s "${tmppath}/non-existing-file" "${tmppath}/brokenlink.list" + elif [ $name = "getLanguages${EXT}" ]; then + echo "Prepare Testarea for \033[1;35m$name\033[0m ..." + tmppath=$(mktemp -d) + touch "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-tr" \ + "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-pt" \ + "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-se~" \ + "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-st.bak" + fi + + echo -n "Testing with \033[1;35m${name}\033[0m ... " + LD_LIBRARY_PATH=${LDPATH} ${testapp} ${tmppath} && echo "\033[1;32mOKAY\033[0m" || echo "\033[1;31mFAILED\033[0m" + + if [ -n "$tmppath" -a -d "$tmppath" ]; then + echo "Cleanup Testarea after \033[1;35m$name\033[0m ..." + rm -rf "$tmppath" + fi + +done diff --git a/test/libapt/run-tests.sh b/test/libapt/run-tests.sh deleted file mode 100755 index cb7769e4a..000000000 --- a/test/libapt/run-tests.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/sh -set -e - -echo "Compiling the tests ..." -test -d '../../build/obj/test/libapt/' || mkdir -p '../../build/obj/test/libapt/' -make -echo "Running all testcases ..." -LDPATH=$(pwd)/../../build/bin -EXT="_libapt_test" -for testapp in $(ls ${LDPATH}/*$EXT) -do - name=$(basename ${testapp}) - tmppath="" - - if [ $name = "GetListOfFilesInDir${EXT}" ]; then - # TODO: very-low: move env creation to the actual test-app - echo "Prepare Testarea for \033[1;35m$name\033[0m ..." - tmppath=$(mktemp -d) - touch "${tmppath}/anormalfile" \ - "${tmppath}/01yet-anothernormalfile" \ - "${tmppath}/anormalapt.conf" \ - "${tmppath}/01yet-anotherapt.conf" \ - "${tmppath}/anormalapt.list" \ - "${tmppath}/01yet-anotherapt.list" \ - "${tmppath}/wrongextension.wron" \ - "${tmppath}/wrong-extension.wron" \ - "${tmppath}/strangefile." \ - "${tmppath}/s.t.r.a.n.g.e.f.i.l.e" \ - "${tmppath}/.hiddenfile" \ - "${tmppath}/.hiddenfile.conf" \ - "${tmppath}/.hiddenfile.list" \ - "${tmppath}/multi..dot" \ - "${tmppath}/multi.dot.conf" \ - "${tmppath}/multi.dot.list" \ - "${tmppath}/disabledfile.disabled" \ - "${tmppath}/disabledfile.conf.disabled" \ - "${tmppath}/disabledfile.list.disabled" \ - "${tmppath}/invälid.conf" \ - "${tmppath}/invalíd" \ - "${tmppath}/01invalíd" - ln -s "${tmppath}/anormalfile" "${tmppath}/linkedfile.list" - ln -s "${tmppath}/non-existing-file" "${tmppath}/brokenlink.list" - elif [ $name = "getLanguages${EXT}" ]; then - echo "Prepare Testarea for \033[1;35m$name\033[0m ..." - tmppath=$(mktemp -d) - touch "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-tr" \ - "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-pt" \ - "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-se~" \ - "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-st.bak" - fi - - echo -n "Testing with \033[1;35m${name}\033[0m ... " - LD_LIBRARY_PATH=${LDPATH} ${testapp} ${tmppath} && echo "\033[1;32mOKAY\033[0m" || echo "\033[1;31mFAILED\033[0m" - - if [ -n "$tmppath" -a -d "$tmppath" ]; then - echo "Cleanup Testarea after \033[1;35m$name\033[0m ..." - rm -rf "$tmppath" - fi - -done -- cgit v1.2.3 From a5032f842366f482371173d030e505d79366fd19 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 26 Jul 2010 09:22:53 +0200 Subject: add APT::Cache::ShowOnlyFirstOr option to print only the first alternative in the apt-cache (r)depends commands --- cmdline/apt-cache.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 1a1ddcb8c..88bf3a049 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -580,6 +580,7 @@ bool Depends(CommandLine &CmdL) bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false); bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false); bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false); + bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false); bool DidSomething; do { @@ -618,7 +619,7 @@ bool Depends(CommandLine &CmdL) if((Installed && Trg->CurrentVer != 0) || !Installed) { - if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) + if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or && ShowOnlyFirstOr == false) cout << " |"; else cout << " "; @@ -650,6 +651,9 @@ bool Depends(CommandLine &CmdL) if (Recurse == true) Colours[D.ParentPkg()->ID]++; } + + if (ShowOnlyFirstOr == true) + while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D; } } } @@ -687,6 +691,7 @@ bool RDepends(CommandLine &CmdL) bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false); bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false); bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false); + bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false); bool DidSomething; do { @@ -727,7 +732,7 @@ bool RDepends(CommandLine &CmdL) if((Installed && Trg->CurrentVer != 0) || !Installed) { - if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) + if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or && ShowOnlyFirstOr == false) cout << " |"; else cout << " "; @@ -758,6 +763,9 @@ bool RDepends(CommandLine &CmdL) if (Recurse == true) Colours[D.ParentPkg()->ID]++; } + + if (ShowOnlyFirstOr == true) + while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D; } } } -- cgit v1.2.3 From f1a58ff8b6cb4086ae59a2c6b02a29baf97ac116 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 26 Jul 2010 10:53:32 +0200 Subject: - add a 'newest' pseudo target release as in pkg/newest * --- apt-pkg/cacheset.cc | 7 ++++++- debian/changelog | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc index df7e99fd0..f17a9e0d5 100644 --- a/apt-pkg/cacheset.cc +++ b/apt-pkg/cacheset.cc @@ -323,7 +323,12 @@ APT::VersionSet VersionSet::FromString(pkgCacheFile &Cache, std::string pkg, V = getInstalledVer(Cache, P, helper); else if (ver == "candidate") V = getCandidateVer(Cache, P, helper); - else { + else if (ver == "newest") { + if (P->VersionList != 0) + V = P.VersionList(); + else + V = helper.canNotFindNewestVer(Cache, P); + } else { pkgVersionMatch Match(ver, (verIsRel == true ? pkgVersionMatch::Release : pkgVersionMatch::Version)); V = Match.Find(P); diff --git a/debian/changelog b/debian/changelog index 1aa05adcb..a381034c1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,12 +7,14 @@ apt (0.7.26~exp11) experimental; urgency=low - be able to omit dependency types in (r)depends (Closes: #319006) * apt-pkg/cacheset.cc: - move them back to the library as they look stable now + - add a 'newest' pseudo target release as in pkg/newest * apt-pkg/pkgcache.cc: - prefer non-virtual packages in FindPreferredPkg (Closes: #590041) * test/integration/*: - add with bug#590041 testcase a small test "framework" + * - -- David Kalnischkies Sun, 25 Jul 2010 19:37:45 +0200 + -- David Kalnischkies Mon, 26 Jul 2010 10:52:14 +0200 apt (0.7.26~exp10) experimental; urgency=low -- cgit v1.2.3 From 3de4647b39216259678f40f4bf6e8122acd923b5 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 26 Jul 2010 12:43:25 +0200 Subject: - show in (r)depends the canidate per default instead of newest - share the (r)depends code instead of codecopy --- cmdline/apt-cache.cc | 210 ++++++++++++++++----------------------------------- debian/changelog | 5 +- 2 files changed, 67 insertions(+), 148 deletions(-) diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 88bf3a049..70732e4d0 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -551,27 +551,40 @@ bool DumpAvail(CommandLine &Cmd) return !_error->PendingError(); } /*}}}*/ -// Depends - Print out a dependency tree /*{{{*/ -// --------------------------------------------------------------------- -/* */ -bool Depends(CommandLine &CmdL) +// ShowDepends - Helper for printing out a dependency tree /*{{{*/ +class CacheSetHelperDepends: public APT::CacheSetHelper { +public: + APT::PackageSet virtualPkgs; + + virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + virtualPkgs.insert(Pkg); + return pkgCache::VerIterator(Cache, 0); + } + + virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + virtualPkgs.insert(Pkg); + return pkgCache::VerIterator(Cache, 0); + } + + CacheSetHelperDepends() : CacheSetHelper(false) {} +}; +bool ShowDepends(CommandLine &CmdL, bool const RevDepends) { pkgCacheFile CacheFile; pkgCache *Cache = CacheFile.GetPkgCache(); if (unlikely(Cache == NULL)) return false; - SPtrArray Colours = new unsigned[Cache->Head().PackageCount]; - memset(Colours,0,sizeof(*Colours)*Cache->Head().PackageCount); - - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) - Colours[Pkg->ID] = 1; + CacheSetHelperDepends helper; + APT::VersionSet verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::VersionSet::CANDIDATE, helper); + if (verset.empty() == true && helper.virtualPkgs.empty() == true) + return false; + std::vector Shown(Cache->Head().PackageCount); bool const Recurse = _config->FindB("APT::Cache::RecurseDepends", false); bool const Installed = _config->FindB("APT::Cache::Installed", false); bool const Important = _config->FindB("APT::Cache::Important", false); - bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType",true); + bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType", RevDepends == false); bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true); bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true); bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false); @@ -581,27 +594,20 @@ bool Depends(CommandLine &CmdL) bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false); bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false); bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false); - bool DidSomething; - do + + while (verset.empty() != true) { - DidSomething = false; - for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) - { - if (Colours[Pkg->ID] != 1) - continue; - Colours[Pkg->ID] = 2; - DidSomething = true; - - pkgCache::VerIterator Ver = Pkg.VersionList(); - if (Ver.end() == true) - { - cout << '<' << Pkg.FullName(true) << '>' << endl; - continue; - } - + pkgCache::VerIterator Ver = *verset.begin(); + verset.erase(verset.begin()); + pkgCache::PkgIterator Pkg = Ver.ParentPkg(); + Shown[Pkg->ID] = true; + cout << Pkg.FullName(true) << endl; - - for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++) + + if (RevDepends == true) + cout << "Reverse Depends:" << endl; + for (pkgCache::DepIterator D = RevDepends ? Pkg.RevDependsList() : Ver.DependsList(); + D.end() == false; D++) { switch (D->Type) { case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break; @@ -614,7 +620,7 @@ bool Depends(CommandLine &CmdL) case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break; } - pkgCache::PkgIterator Trg = D.TargetPkg(); + pkgCache::PkgIterator Trg = RevDepends ? D.ParentPkg() : D.TargetPkg(); if((Installed && Trg->CurrentVer != 0) || !Installed) { @@ -632,8 +638,11 @@ bool Depends(CommandLine &CmdL) else cout << Trg.FullName(true) << endl; - if (Recurse == true) - Colours[D.TargetPkg()->ID]++; + if (Recurse == true && Shown[Trg->ID] == false) + { + Shown[Trg->ID] = true; + verset.insert(APT::VersionSet::FromPackage(CacheFile, Trg, APT::VersionSet::CANDIDATE, helper)); + } } @@ -647,131 +656,40 @@ bool Depends(CommandLine &CmdL) V->ParentPkg == D->Package) continue; cout << " " << V.ParentPkg().FullName(true) << endl; - - if (Recurse == true) - Colours[D.ParentPkg()->ID]++; + + if (Recurse == true && Shown[V.ParentPkg()->ID] == false) + { + Shown[V.ParentPkg()->ID] = true; + verset.insert(APT::VersionSet::FromPackage(CacheFile, V.ParentPkg(), APT::VersionSet::CANDIDATE, helper)); + } } if (ShowOnlyFirstOr == true) while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D; } - } - } - while (DidSomething == true); - + } + + for (APT::PackageSet::const_iterator Pkg = helper.virtualPkgs.begin(); + Pkg != helper.virtualPkgs.end(); ++Pkg) + cout << '<' << Pkg.FullName(true) << '>' << endl; + return true; } /*}}}*/ -// RDepends - Print out a reverse dependency tree - mbc /*{{{*/ +// Depends - Print out a dependency tree /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool Depends(CommandLine &CmdL) +{ + return ShowDepends(CmdL, false); +} + /*}}}*/ +// RDepends - Print out a reverse dependency tree /*{{{*/ // --------------------------------------------------------------------- /* */ bool RDepends(CommandLine &CmdL) { - pkgCacheFile CacheFile; - pkgCache *Cache = CacheFile.GetPkgCache(); - if (unlikely(Cache == NULL)) - return false; - - SPtrArray Colours = new unsigned[Cache->Head().PackageCount]; - memset(Colours,0,sizeof(*Colours)*Cache->Head().PackageCount); - - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) - Colours[Pkg->ID] = 1; - - bool const Recurse = _config->FindB("APT::Cache::RecurseDepends",false); - bool const Installed = _config->FindB("APT::Cache::Installed",false); - bool const Important = _config->FindB("APT::Cache::Important", false); - bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType",false); - bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true); - bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true); - bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false); - bool const ShowSuggests = _config->FindB("APT::Cache::ShowSuggests", Important == false); - bool const ShowReplaces = _config->FindB("APT::Cache::ShowReplaces", Important == false); - bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false); - bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false); - bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false); - bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false); - bool DidSomething; - do - { - DidSomething = false; - for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) - { - if (Colours[Pkg->ID] != 1) - continue; - Colours[Pkg->ID] = 2; - DidSomething = true; - - pkgCache::VerIterator Ver = Pkg.VersionList(); - if (Ver.end() == true) - { - cout << '<' << Pkg.FullName(true) << '>' << endl; - continue; - } - - cout << Pkg.FullName(true) << endl; - - cout << "Reverse Depends:" << endl; - for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false; D++) - { - switch (D->Type) { - case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break; - case pkgCache::Dep::Depends: if (!ShowDepends) continue; break; - case pkgCache::Dep::Recommends: if (!ShowRecommends) continue; break; - case pkgCache::Dep::Suggests: if (!ShowSuggests) continue; break; - case pkgCache::Dep::Replaces: if (!ShowReplaces) continue; break; - case pkgCache::Dep::Conflicts: if (!ShowConflicts) continue; break; - case pkgCache::Dep::DpkgBreaks: if (!ShowBreaks) continue; break; - case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break; - } - - // Show the package - pkgCache::PkgIterator Trg = D.ParentPkg(); - - if((Installed && Trg->CurrentVer != 0) || !Installed) - { - - if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or && ShowOnlyFirstOr == false) - cout << " |"; - else - cout << " "; - - if (ShowDepType == true) - cout << D.DepType() << ": "; - if (Trg->VersionList == 0) - cout << "<" << Trg.FullName(true) << ">" << endl; - else - cout << Trg.FullName(true) << endl; - - if (Recurse == true) - Colours[D.ParentPkg()->ID]++; - - } - - // Display all solutions - SPtrArray List = D.AllTargets(); - pkgPrioSortList(*Cache,List); - for (pkgCache::Version **I = List; *I != 0; I++) - { - pkgCache::VerIterator V(*Cache,*I); - if (V != Cache->VerP + V.ParentPkg()->VersionList || - V->ParentPkg == D->Package) - continue; - cout << " " << V.ParentPkg().FullName(true) << endl; - - if (Recurse == true) - Colours[D.ParentPkg()->ID]++; - } - - if (ShowOnlyFirstOr == true) - while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D; - } - } - } - while (DidSomething == true); - - return true; + return ShowDepends(CmdL, true); } /*}}}*/ // xvcg - Generate a graph for xvcg /*{{{*/ diff --git a/debian/changelog b/debian/changelog index a381034c1..345a46579 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,8 @@ apt (0.7.26~exp11) experimental; urgency=low - handle "circular" conflicts for "all" packages correctly * cmdline/apt-cache.cc: - be able to omit dependency types in (r)depends (Closes: #319006) + - show in (r)depends the canidate per default instead of newest + - share the (r)depends code instead of codecopy * apt-pkg/cacheset.cc: - move them back to the library as they look stable now - add a 'newest' pseudo target release as in pkg/newest @@ -12,9 +14,8 @@ apt (0.7.26~exp11) experimental; urgency=low - prefer non-virtual packages in FindPreferredPkg (Closes: #590041) * test/integration/*: - add with bug#590041 testcase a small test "framework" - * - -- David Kalnischkies Mon, 26 Jul 2010 10:52:14 +0200 + -- David Kalnischkies Mon, 26 Jul 2010 12:40:44 +0200 apt (0.7.26~exp10) experimental; urgency=low -- cgit v1.2.3