From 6cb1060b58d8add6e04cc30241d3ef0f45ad226d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 27 May 2010 15:17:52 +0200 Subject: * apt-pkg/deb/dpkgpm.cc: - write Disappeared also to the history.log --- apt-pkg/deb/dpkgpm.cc | 33 ++++++++++++++++++++++++--------- apt-pkg/deb/dpkgpm.h | 2 +- debian/changelog | 8 ++++++++ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 8318fe37..35b10975 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -568,15 +568,15 @@ void pkgDPkgPM::DoDpkgStatusFd(int statusfd, int OutStatusFd) } /*}}}*/ // DPkgPM::WriteHistoryTag /*{{{*/ -void pkgDPkgPM::WriteHistoryTag(string tag, string value) +void pkgDPkgPM::WriteHistoryTag(string const &tag, string value) { - if (value.size() > 0) - { - // poor mans rstrip(", ") - if (value[value.size()-2] == ',' && value[value.size()-1] == ' ') - value.erase(value.size() - 2, 2); - fprintf(history_out, "%s: %s\n", tag.c_str(), value.c_str()); - } + size_t const length = value.length(); + if (length == 0) + return; + // poor mans rstrip(", ") + if (value[length-2] == ',' && value[length-1] == ' ') + value.erase(length - 2, 2); + fprintf(history_out, "%s: %s\n", tag.c_str(), value.c_str()); } /*}}}*/ // DPkgPM::OpenLog /*{{{*/ bool pkgDPkgPM::OpenLog() @@ -663,7 +663,22 @@ bool pkgDPkgPM::CloseLog() if(history_out) { - if (dpkg_error.size() > 0) + if (disappearedPkgs.empty() == false) + { + string disappear; + for (std::set::const_iterator d = disappearedPkgs.begin(); + d != disappearedPkgs.end(); ++d) + { + pkgCache::PkgIterator P = Cache.FindPkg(*d); + disappear.append(*d); + if (P.end() == true) + disappear.append(", "); + else + disappear.append(" (").append(Cache[P].CurVersion).append("), "); + } + WriteHistoryTag("Disappeared", disappear); + } + if (dpkg_error.empty() == false) fprintf(history_out, "Error: %s\n", dpkg_error.c_str()); fprintf(history_out, "End-Date: %s\n", timestr); fclose(history_out); diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h index 330c788a..b1459b1f 100644 --- a/apt-pkg/deb/dpkgpm.h +++ b/apt-pkg/deb/dpkgpm.h @@ -68,7 +68,7 @@ class pkgDPkgPM : public pkgPackageManager // Helpers bool RunScriptsWithPkgs(const char *Cnf); bool SendV2Pkgs(FILE *F); - void WriteHistoryTag(string tag, string value); + void WriteHistoryTag(string const &tag, string value); // dpkg log bool OpenLog(); diff --git a/debian/changelog b/debian/changelog index 3771ca41..ee571a53 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +apt (0.7.26~exp6) UNRELEASED; urgency=low + + [ David Kalnischkies ] + * apt-pkg/deb/dpkgpm.cc: + - write Disappeared also to the history.log + + -- David Kalnischkies Thu, 27 May 2010 15:12:02 +0200 + apt (0.7.26~exp5) experimental; urgency=low [ David Kalnischkies ] -- cgit v1.2.3 From eb6f9bac96a2b1938df598f4fd7c68d22c68a230 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 27 May 2010 18:13:52 +0200 Subject: forward manual-installed bit on package disappearance --- apt-pkg/deb/dpkgpm.cc | 47 ++++++++++++++++++++++++++++++++++++++++++++++- apt-pkg/deb/dpkgpm.h | 15 +++++++++++++++ debian/changelog | 3 ++- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 35b10975..0ac6ac16 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -470,7 +470,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) std::clog << "send: '" << status.str() << "'" << endl; if (strncmp(action, "disappear", strlen("disappear")) == 0) - disappearedPkgs.insert(string(pkg_or_trigger)); + handleDisappearAction(pkg_or_trigger); return; } @@ -530,6 +530,51 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) << " action: " << action << endl; } /*}}}*/ +// DPkgPM::handleDisappearAction /*{{{*/ +void pkgDPkgPM::handleDisappearAction(string const &pkgname) +{ + // record the package name for display and stuff later + disappearedPkgs.insert(pkgname); + + pkgCache::PkgIterator Pkg = Cache.FindPkg(pkgname); + if (unlikely(Pkg.end() == true)) + return; + // the disappeared package was auto-installed - nothing to do + if ((Cache[Pkg].Flags & pkgCache::Flag::Auto) == pkgCache::Flag::Auto) + return; + pkgCache::VerIterator PkgVer = Pkg.CurrentVer(); + if (unlikely(PkgVer.end() == true)) + return; + /* search in the list of dependencies for (Pre)Depends, + check if this dependency has a Replaces on our package + and if so transfer the manual installed flag to it */ + for (pkgCache::DepIterator Dep = PkgVer.DependsList(); Dep.end() != true; ++Dep) + { + if (Dep->Type != pkgCache::Dep::Depends && + Dep->Type != pkgCache::Dep::PreDepends) + continue; + pkgCache::PkgIterator Tar = Dep.TargetPkg(); + if (unlikely(Tar.end() == true)) + continue; + // the package is already marked as manual + if ((Cache[Tar].Flags & pkgCache::Flag::Auto) != pkgCache::Flag::Auto) + continue; + pkgCache::VerIterator TarVer = Tar.CurrentVer(); + for (pkgCache::DepIterator Rep = TarVer.DependsList(); Rep.end() != true; ++Rep) + { + if (Rep->Type != pkgCache::Dep::Replaces) + continue; + if (Pkg != Rep.TargetPkg()) + continue; + // okay, they are strongly connected - transfer manual-bit + if (Debug == true) + std::clog << "transfer manual-bit from disappeared »" << pkgname << "« to »" << Tar.FullName() << "«" << std::endl; + Cache[Tar].Flags &= ~Flag::Auto; + break; + } + } +} + /*}}}*/ // DPkgPM::DoDpkgStatusFd /*{{{*/ // --------------------------------------------------------------------- /* diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h index b1459b1f..9a4478f7 100644 --- a/apt-pkg/deb/dpkgpm.h +++ b/apt-pkg/deb/dpkgpm.h @@ -32,6 +32,21 @@ class pkgDPkgPM : public pkgPackageManager FILE *history_out; string dpkg_error; + /** \brief record the disappear action and handle accordingly + + dpkg let packages disappear then they have no files any longer and + nothing depends on them. We need to collect this as dpkg as well as + APT doesn't know beforehand that the package will disappear, so the + only possible option is to tell the user afterwards about it. + To enhance the experience we also try to forward the auto-install + flag so the disappear-causer(s) are not autoremoved next time - + for the transfer to happen the disappeared version needs to depend + on the package the flag should be forwarded to and this package + needs to declare a Replaces on the disappeared package. + \param pkgname Name of the package that disappeared + */ + void handleDisappearAction(string const &pkgname); + protected: // progress reporting diff --git a/debian/changelog b/debian/changelog index ee571a53..9fa04058 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,8 +3,9 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low [ David Kalnischkies ] * apt-pkg/deb/dpkgpm.cc: - write Disappeared also to the history.log + - forward manual-installed bit on package disappearance - -- David Kalnischkies Thu, 27 May 2010 15:12:02 +0200 + -- David Kalnischkies Thu, 27 May 2010 17:34:51 +0200 apt (0.7.26~exp5) experimental; urgency=low -- cgit v1.2.3 From d34690e1dc76c1e572d9f7ac172dd6b12059f774 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 28 May 2010 14:10:00 +0200 Subject: * apt-pkg/deb/debsystem.cc: - add better config item for extended_states file --- apt-pkg/deb/debsystem.cc | 2 +- apt-pkg/depcache.cc | 4 ++-- debian/changelog | 2 ++ doc/apt-mark.8.xml | 7 +------ doc/apt.ent | 8 ++++++++ doc/examples/configure-index | 3 +-- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/apt-pkg/deb/debsystem.cc b/apt-pkg/deb/debsystem.cc index 59f826d9..31c26ab2 100644 --- a/apt-pkg/deb/debsystem.cc +++ b/apt-pkg/deb/debsystem.cc @@ -158,7 +158,7 @@ bool debSystem::Initialize(Configuration &Cnf) /* These really should be jammed into a generic 'Local Database' engine which is yet to be determined. The functions in pkgcachegen should be the only users of these */ - Cnf.CndSet("Dir::State::userstatus","status.user"); // Defunct + Cnf.CndSet("Dir::State::extended_states", Cnf.FindDir("Dir::State").append("extended_states")); Cnf.CndSet("Dir::State::status","/var/lib/dpkg/status"); Cnf.CndSet("Dir::Bin::dpkg","/usr/bin/dpkg"); diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 411ae5f6..bdb89b5c 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -165,7 +165,7 @@ bool pkgDepCache::Init(OpProgress *Prog) bool pkgDepCache::readStateFile(OpProgress *Prog) /*{{{*/ { FileFd state_file; - string const state = _config->FindDir("Dir::State") + "extended_states"; + string const state = _config->FindFile("Dir::State::extended_states"); if(FileExists(state)) { state_file.Open(state, FileFd::ReadOnly); int const file_size = state_file.Size(); @@ -222,7 +222,7 @@ bool pkgDepCache::writeStateFile(OpProgress *prog, bool InstalledOnly) /*{{{*/ std::clog << "pkgDepCache::writeStateFile()" << std::endl; FileFd StateFile; - string const state = _config->FindDir("Dir::State") + "extended_states"; + string const state = _config->FindFile("Dir::State::extended_states"); // if it does not exist, create a empty one if(!FileExists(state)) diff --git a/debian/changelog b/debian/changelog index 9fa04058..02845275 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,6 +4,8 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low * apt-pkg/deb/dpkgpm.cc: - write Disappeared also to the history.log - forward manual-installed bit on package disappearance + * apt-pkg/deb/debsystem.cc: + - add better config item for extended_states file -- David Kalnischkies Thu, 27 May 2010 17:34:51 +0200 diff --git a/doc/apt-mark.8.xml b/doc/apt-mark.8.xml index 3f6cc78f..8e07cd7d 100644 --- a/doc/apt-mark.8.xml +++ b/doc/apt-mark.8.xml @@ -121,12 +121,7 @@ Files - /var/lib/apt/extended_states - Status list of auto-installed packages. - Configuration Item: Dir::State - sets the path to the extended_states file. - - + &file-extended_states; diff --git a/doc/apt.ent b/doc/apt.ent index 494c6b02..0d037c8b 100644 --- a/doc/apt.ent +++ b/doc/apt.ent @@ -363,6 +363,14 @@ "> +/var/lib/apt/extended_states + Status list of auto-installed packages. + Configuration Item: Dir::State::extended_states. + + +"> + diff --git a/doc/examples/configure-index b/doc/examples/configure-index index d168417d..487c09ac 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -294,9 +294,8 @@ Dir "/" State "var/lib/apt/" { Lists "lists/"; - xstatus "xstatus"; - userstatus "status.user"; status "/var/lib/dpkg/status"; + extended_states "extended_states"; cdroms "cdroms.list"; }; -- cgit v1.2.3 From 8378913047031bd1433a5b17e9affc1e055a150e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 28 May 2010 19:04:53 +0200 Subject: * apt-pkg/depcache.cc: - do the autoremove mark process also for required packages to handle these illegally depending on lower priority packages (Closes: #583517) --- apt-pkg/depcache.cc | 7 +++++-- debian/changelog | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index bdb89b5c..c29114a6 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -1638,8 +1638,11 @@ bool pkgDepCache::MarkRequired(InRootSetFunc &userFunc) { if(!(PkgState[p->ID].Flags & Flag::Auto) || (p->Flags & Flag::Essential) || - userFunc.InRootSet(p)) - + userFunc.InRootSet(p) || + // be nice even then a required package violates the policy (#583517) + // and do the full mark process also for required packages + (p.CurrentVer().end() != true && + p.CurrentVer()->Priority == pkgCache::State::Required)) { // the package is installed (and set to keep) if(PkgState[p->ID].Keep() && !p.CurrentVer().end()) diff --git a/debian/changelog b/debian/changelog index 02845275..ce7ff48b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,8 +6,11 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - forward manual-installed bit on package disappearance * apt-pkg/deb/debsystem.cc: - add better config item for extended_states file + * apt-pkg/depcache.cc: + - do the autoremove mark process also for required packages to handle + these illegally depending on lower priority packages (Closes: #583517) - -- David Kalnischkies Thu, 27 May 2010 17:34:51 +0200 + -- David Kalnischkies Fri, 28 May 2010 19:03:30 +0200 apt (0.7.26~exp5) experimental; urgency=low -- cgit v1.2.3 From 392a882ad8a299d55889e9c0fa581a266d6dd2c9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 28 May 2010 19:30:19 +0200 Subject: try harder to find the other pseudo versions for autoremove multiarch --- apt-pkg/depcache.cc | 7 ++----- debian/changelog | 1 + 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index c29114a6..afec7ba8 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -1719,10 +1719,6 @@ void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &pkg, // If the version belongs to a Multi-Arch all package // we will mark all others in this Group with this version also - // Beware: We compare versions here the lazy way: string comparision - // this is bad if multiple repositories provide different versions - // of the package with an identical version number - but even in this - // case the dependencies are likely the same. if (ver->MultiArch == pkgCache::Version::All && strcmp(ver.Arch(true), "all") == 0) { @@ -1734,7 +1730,8 @@ void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &pkg, for (VerIterator V = P.VersionList(); V.end() != true; ++V) { - if (strcmp(VerStr, V.VerStr()) != 0) + if (ver->Hash != V->Hash || + strcmp(VerStr, V.VerStr()) != 0) continue; MarkPackage(P, V, follow_recommends, follow_suggests); break; diff --git a/debian/changelog b/debian/changelog index ce7ff48b..c1ee360f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,6 +9,7 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low * apt-pkg/depcache.cc: - do the autoremove mark process also for required packages to handle these illegally depending on lower priority packages (Closes: #583517) + - try harder to find the other pseudo versions for autoremove multiarch -- David Kalnischkies Fri, 28 May 2010 19:03:30 +0200 -- cgit v1.2.3 From 3152f4aa4a97ad06ef1073aabe137f999f787ee1 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 28 May 2010 23:11:36 +0200 Subject: * apt-pkg/aptconfiguration.cc: - remove duplicate architectures in getArchitectures() --- apt-pkg/aptconfiguration.cc | 15 ++++++++- debian/changelog | 2 ++ test/libapt/getarchitectures_test.cc | 61 ++++++++++++++++++++++++++++++++++++ test/libapt/makefile | 5 +++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 test/libapt/getarchitectures_test.cc diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index 2acf8dd9..0c050d9d 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -327,11 +327,24 @@ std::vector const Configuration::getArchitectures(bool const &Cache if (likely(Cached == true) && archs.empty() == false) return archs; - string const arch = _config->Find("APT::Architecture"); archs = _config->FindVector("APT::Architectures"); + string const arch = _config->Find("APT::Architecture"); + if (unlikely(arch.empty() == true)) + return archs; + if (archs.empty() == true || std::find(archs.begin(), archs.end(), arch) == archs.end()) archs.push_back(arch); + + // erase duplicates and empty strings + for (std::vector::reverse_iterator a = archs.rbegin(); + a != archs.rend(); ++a) { + if (a->empty() == true || std::find(a + 1, archs.rend(), *a) != archs.rend()) + archs.erase(a.base()-1); + if (a == archs.rend()) + break; + } + return archs; } /*}}}*/ diff --git a/debian/changelog b/debian/changelog index c1ee360f..66c41ef5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,6 +10,8 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - do the autoremove mark process also for required packages to handle these illegally depending on lower priority packages (Closes: #583517) - try harder to find the other pseudo versions for autoremove multiarch + * apt-pkg/aptconfiguration.cc: + - remove duplicate architectures in getArchitectures() -- David Kalnischkies Fri, 28 May 2010 19:03:30 +0200 diff --git a/test/libapt/getarchitectures_test.cc b/test/libapt/getarchitectures_test.cc new file mode 100644 index 00000000..1500caee --- /dev/null +++ b/test/libapt/getarchitectures_test.cc @@ -0,0 +1,61 @@ +#include +#include + +#include "assert.h" +#include +#include + +#include + +// simple helper to quickly output a vector of strings +void dumpVector(std::vector vec) { + for (std::vector::const_iterator v = vec.begin(); + v != vec.end(); v++) + std::cout << *v << std::endl; +} + +int main(int argc,char *argv[]) +{ + std::vector vec; + + _config->Set("APT::Architectures::1", "i386"); + _config->Set("APT::Architectures::2", "amd64"); + vec = APT::Configuration::getArchitectures(false); + equals(vec.size(), 2); + equals(vec[0], "i386"); + equals(vec[1], "amd64"); + + _config->Set("APT::Architecture", "i386"); + vec = APT::Configuration::getArchitectures(false); + equals(vec.size(), 2); + equals(vec[0], "i386"); + equals(vec[1], "amd64"); + + _config->Set("APT::Architectures::2", ""); + vec = APT::Configuration::getArchitectures(false); + equals(vec.size(), 1); + equals(vec[0], "i386"); + + _config->Set("APT::Architecture", "armel"); + vec = APT::Configuration::getArchitectures(false); + equals(vec.size(), 2); + equals(vec[0], "i386"); + equals(vec[1], "armel"); + + _config->Set("APT::Architectures::2", "amd64"); + _config->Set("APT::Architectures::3", "i386"); + _config->Set("APT::Architectures::4", "armel"); + _config->Set("APT::Architectures::5", "i386"); + _config->Set("APT::Architectures::6", "amd64"); + _config->Set("APT::Architectures::7", "armel"); + _config->Set("APT::Architectures::8", "armel"); + _config->Set("APT::Architectures::9", "amd64"); + _config->Set("APT::Architectures::10", "amd64"); + vec = APT::Configuration::getArchitectures(false); + equals(vec.size(), 3); + equals(vec[0], "i386"); + equals(vec[1], "amd64"); + equals(vec[2], "armel"); + + return 0; +} diff --git a/test/libapt/makefile b/test/libapt/makefile index 98bdb334..ee3401b3 100644 --- a/test/libapt/makefile +++ b/test/libapt/makefile @@ -12,6 +12,11 @@ SLIBS = -lapt-pkg SOURCE = getlanguages_test.cc include $(PROGRAM_H) +PROGRAM = getArchitectures${BASENAME} +SLIBS = -lapt-pkg +SOURCE = getarchitectures_test.cc +include $(PROGRAM_H) + # Program for testing ParseDepends PROGRAM = ParseDepends${BASENAME} SLIBS = -lapt-pkg -- cgit v1.2.3 From 8fa7eefb8a320e8fa4a26c4718fa606d4d27a56f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 28 May 2010 23:40:08 +0200 Subject: create the bin-test directory automatic in the runner --- test/libapt/run-tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test/libapt/run-tests.sh b/test/libapt/run-tests.sh index f9df1af5..cb7769e4 100755 --- a/test/libapt/run-tests.sh +++ b/test/libapt/run-tests.sh @@ -2,6 +2,7 @@ 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 -- cgit v1.2.3 From e1430400bf012ab7e29b00c78796a14ce9f97107 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 29 May 2010 12:04:51 +0200 Subject: * apt-pkg/indexrecords.{cc,h}: - add a constant Exists check for MetaKeys * apt-pkg/acquire-item.cc: - do not try PDiff if it is not listed in the Meta file --- apt-pkg/acquire-item.cc | 13 ++++++++----- apt-pkg/indexrecords.cc | 5 +++++ apt-pkg/indexrecords.h | 2 ++ debian/changelog | 6 +++++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index c035b916..9e29f818 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -1105,13 +1105,16 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/ return; } } - - // Queue Packages file (either diff or full packages files, depending - // on the users option) - if(_config->FindB("Acquire::PDiffs",true) == true) + + /* Queue Packages file (either diff or full packages files, depending + on the users option) - we also check if the PDiff Index file is listed + in the Meta-Index file. Ideal would be if pkgAcqDiffIndex would test this + instead, but passing the required info to it is to much hassle */ + if(_config->FindB("Acquire::PDiffs",true) == true && (verify == false || + MetaIndexParser->Exists(string((*Target)->MetaKey).append(".diff/Index")) == true)) new pkgAcqDiffIndex(Owner, (*Target)->URI, (*Target)->Description, (*Target)->ShortDesc, ExpectedIndexHash); - else + else new pkgAcqIndex(Owner, (*Target)->URI, (*Target)->Description, (*Target)->ShortDesc, ExpectedIndexHash); } diff --git a/apt-pkg/indexrecords.cc b/apt-pkg/indexrecords.cc index 1fc27b1a..9a960053 100644 --- a/apt-pkg/indexrecords.cc +++ b/apt-pkg/indexrecords.cc @@ -31,6 +31,11 @@ const indexRecords::checkSum *indexRecords::Lookup(const string MetaKey) return Entries[MetaKey]; } +bool indexRecords::Exists(string const &MetaKey) const +{ + return Entries.count(MetaKey) == 1; +} + bool indexRecords::Load(const string Filename) /*{{{*/ { FileFd Fd(Filename, FileFd::ReadOnly); diff --git a/apt-pkg/indexrecords.h b/apt-pkg/indexrecords.h index 468d2bd0..2e3103b7 100644 --- a/apt-pkg/indexrecords.h +++ b/apt-pkg/indexrecords.h @@ -34,6 +34,8 @@ class indexRecords // Lookup function virtual const checkSum *Lookup(const string MetaKey); + /** \brief tests if a checksum for this file is available */ + bool Exists(string const &MetaKey) const; std::vector MetaKeys(); virtual bool Load(string Filename); diff --git a/debian/changelog b/debian/changelog index 66c41ef5..1fa254b0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -12,8 +12,12 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - try harder to find the other pseudo versions for autoremove multiarch * apt-pkg/aptconfiguration.cc: - remove duplicate architectures in getArchitectures() + * apt-pkg/indexrecords.{cc,h}: + - add a constant Exists check for MetaKeys + * apt-pkg/acquire-item.cc: + - do not try PDiff if it is not listed in the Meta file - -- David Kalnischkies Fri, 28 May 2010 19:03:30 +0200 + -- David Kalnischkies Sat, 29 May 2010 12:03:20 +0200 apt (0.7.26~exp5) experimental; urgency=low -- cgit v1.2.3 From b3fdb998016beb8bf3d8bedb3ad6218f9050eece Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 29 May 2010 15:44:47 +0200 Subject: * apt-pkg/cacheiterator.h: - let pkgCache::Iterator inherent std::iterator --- apt-pkg/cacheiterators.h | 4 +++- debian/changelog | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index e2ca7468..3d58f7ec 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -29,10 +29,12 @@ /*}}}*/ #ifndef PKGLIB_CACHEITERATORS_H #define PKGLIB_CACHEITERATORS_H +#include // abstract Iterator template /*{{{*/ /* This template provides the very basic iterator methods we need to have for doing some walk-over-the-cache magic */ -template class pkgCache::Iterator { +template class pkgCache::Iterator : + public std::iterator { protected: Str *S; pkgCache *Owner; diff --git a/debian/changelog b/debian/changelog index 1fa254b0..839c8c80 100644 --- a/debian/changelog +++ b/debian/changelog @@ -16,8 +16,10 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - add a constant Exists check for MetaKeys * apt-pkg/acquire-item.cc: - do not try PDiff if it is not listed in the Meta file + * apt-pkg/cacheiterator.h: + - let pkgCache::Iterator inherent std::iterator - -- David Kalnischkies Sat, 29 May 2010 12:03:20 +0200 + -- David Kalnischkies Sat, 29 May 2010 15:39:07 +0200 apt (0.7.26~exp5) experimental; urgency=low -- cgit v1.2.3 From 461e4a5e0d30549e5b9758ce816027d92747f00d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 29 May 2010 19:02:32 +0200 Subject: * apt-pkg/depcache.cc: - correct "Dangerous iterator usage." pointed out by cppcheck --- apt-pkg/depcache.cc | 6 +++--- debian/changelog | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index afec7ba8..6c73b9cf 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -806,7 +806,7 @@ void pkgDepCache::Update(OpProgress *Prog) a bit we increase with a kill, but we should do something more clever… */ while(recheck.empty() == false) for (std::set::const_iterator p = recheck.begin(); - p != recheck.end(); ++p) { + p != recheck.end();) { if (Prog != 0 && Done%20 == 0) Prog->Progress(Done); PkgIterator P = PkgIterator(*Cache, Cache->PkgP + *p); @@ -814,7 +814,7 @@ void pkgDepCache::Update(OpProgress *Prog) ++killed; ++Done; } - recheck.erase(p); + recheck.erase(p++); } /* Okay, we have killed a great amount of pseudopackages - @@ -849,7 +849,7 @@ void pkgDepCache::Update(OpProgress *Prog) unsigned long const G = *g; recheck.erase(g); if (unlikely(ReInstallPseudoForGroup(G, recheck) == false)) - _error->Warning(_("Internal error, group '%s' has no installable pseudo package"), GrpIterator(*Cache, Cache->GrpP + *g).Name()); + _error->Warning(_("Internal error, group '%s' has no installable pseudo package"), GrpIterator(*Cache, Cache->GrpP + G).Name()); } } diff --git a/debian/changelog b/debian/changelog index 839c8c80..e8c1f959 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,8 +18,10 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - do not try PDiff if it is not listed in the Meta file * apt-pkg/cacheiterator.h: - let pkgCache::Iterator inherent std::iterator + * apt-pkg/depcache.cc: + - correct "Dangerous iterator usage." pointed out by cppcheck - -- David Kalnischkies Sat, 29 May 2010 15:39:07 +0200 + -- David Kalnischkies Sat, 29 May 2010 19:02:12 +0200 apt (0.7.26~exp5) experimental; urgency=low -- cgit v1.2.3 From f5cd2dbfc493127b18d9ea2b0bb258b736b91cd4 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 29 May 2010 19:10:19 +0200 Subject: * ftparchive/writer.h: - add a virtual destructor to FTWScanner class (for cppcheck) --- debian/changelog | 4 +++- ftparchive/writer.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index e8c1f959..2755e7c5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -20,8 +20,10 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - let pkgCache::Iterator inherent std::iterator * apt-pkg/depcache.cc: - correct "Dangerous iterator usage." pointed out by cppcheck + * ftparchive/writer.h: + - add a virtual destructor to FTWScanner class (for cppcheck) - -- David Kalnischkies Sat, 29 May 2010 19:02:12 +0200 + -- David Kalnischkies Sat, 29 May 2010 19:09:05 +0200 apt (0.7.26~exp5) experimental; urgency=low diff --git a/ftparchive/writer.h b/ftparchive/writer.h index 3123a7f4..c08ddea8 100644 --- a/ftparchive/writer.h +++ b/ftparchive/writer.h @@ -72,6 +72,7 @@ class FTWScanner bool SetExts(string const &Vals); FTWScanner(string const &Arch = string()); + virtual ~FTWScanner(); }; class TranslationWriter -- cgit v1.2.3 From e1dbde8dd006ca0ed6b7a6c383af7bbc60014912 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 30 May 2010 07:57:32 +0200 Subject: * apt-pkg/packageset.h: - add a simple wrapper around std::set for packages with it --- apt-pkg/makefile | 3 ++- apt-pkg/packageset.h | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ debian/changelog | 2 ++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 apt-pkg/packageset.h diff --git a/apt-pkg/makefile b/apt-pkg/makefile index 148ad581..d4537859 100644 --- a/apt-pkg/makefile +++ b/apt-pkg/makefile @@ -42,7 +42,8 @@ HEADERS+= algorithms.h depcache.h pkgcachegen.h cacheiterators.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 \ + packageset.h # Source code for the debian specific components # In theory the deb headers do not need to be exported.. diff --git a/apt-pkg/packageset.h b/apt-pkg/packageset.h new file mode 100644 index 00000000..d8053694 --- /dev/null +++ b/apt-pkg/packageset.h @@ -0,0 +1,53 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/** \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. +*/ + /*}}}*/ +#ifndef APT_PACKAGESET_H +#define APT_PACKAGESET_H +// Include Files /*{{{*/ +#include +#include + /*}}}*/ +namespace APT { +class PackageSet : public std::set { /*{{{*/ +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) {} + + 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() {return (*this)->Cache();}; + + friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, (*i)); } + + inline pkgCache::PkgIterator const * operator->() const { + return &**this; + }; + }; + // 103. set::iterator is required to be modifiable, but this allows modification of keys + typedef typename APT::PackageSet::const_iterator iterator; + /*}}}*/ +}; + /*}}}*/ +} +#endif diff --git a/debian/changelog b/debian/changelog index 2755e7c5..6980e5fc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -22,6 +22,8 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - correct "Dangerous iterator usage." pointed out by cppcheck * ftparchive/writer.h: - add a virtual destructor to FTWScanner class (for cppcheck) + * apt-pkg/packageset.h: + - add a simple wrapper around std::set for packages with it -- David Kalnischkies Sat, 29 May 2010 19:09:05 +0200 -- cgit v1.2.3 From ffee1c2bed4accfe25b2ac9e9f0ab9a0ebae9b5b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 30 May 2010 23:12:41 +0200 Subject: move regex magic from apt-get to new FromRegEx method --- apt-pkg/cacheiterators.h | 2 +- apt-pkg/makefile | 2 +- apt-pkg/packageset.cc | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ apt-pkg/packageset.h | 24 ++++++++++++++++++- cmdline/apt-get.cc | 42 +++++++------------------------- debian/changelog | 1 + 6 files changed, 96 insertions(+), 37 deletions(-) create mode 100644 apt-pkg/packageset.cc diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index 3d58f7ec..ee852f59 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -66,7 +66,7 @@ template class pkgCache::Iterator : inline operator Str const *() const {return S == OwnerPointer() ? 0 : S;}; inline Str &operator *() {return *S;}; inline Str const &operator *() const {return *S;}; - inline pkgCache *Cache() {return Owner;}; + inline pkgCache *Cache() const {return Owner;}; // Mixed stuff inline void operator =(const Itr &B) {S = B.S; Owner = B.Owner;}; diff --git a/apt-pkg/makefile b/apt-pkg/makefile index d4537859..968275c5 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 + aptconfiguration.cc packageset.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 \ diff --git a/apt-pkg/packageset.cc b/apt-pkg/packageset.cc new file mode 100644 index 00000000..f452bc05 --- /dev/null +++ b/apt-pkg/packageset.cc @@ -0,0 +1,62 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/* ###################################################################### + + 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. + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include +#include +#include + +#include + +#include + /*}}}*/ +namespace APT { +// FromRegEx - Return all packages in the cache matching a pattern /*{{{*/ +PackageSet PackageSet::FromRegEx(pkgCache &Cache, const char * const pattern, std::ostream &out) { + PackageSet pkgset; + + const char * I; + for (I = pattern; *I != 0; I++) + if (*I == '.' || *I == '?' || *I == '+' || *I == '*' || + *I == '|' || *I == '[' || *I == '^' || *I == '$') + break; + if (*I == 0) + return pkgset; + + regex_t Pattern; + int Res; + if ((Res = regcomp(&Pattern, pattern , REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0) { + char Error[300]; + regerror(Res, &Pattern, Error, sizeof(Error)); + _error->Error(_("Regex compilation error - %s"), Error); + return pkgset; + } + + for (pkgCache::GrpIterator Grp = Cache.GrpBegin(); Grp.end() == false; ++Grp) + { + if (regexec(&Pattern, Grp.Name(), 0, 0, 0) != 0) + continue; + pkgCache::PkgIterator Pkg = Grp.FindPkg("native"); + if (unlikely(Pkg.end() == true)) + // FIXME: Fallback to different architectures here? + continue; + + ioprintf(out, _("Note, selecting %s for regex '%s'\n"), + Pkg.Name(), pattern); + + pkgset.insert(Pkg); + } + + regfree(&Pattern); + + return pkgset; +} + /*}}}*/ +} diff --git a/apt-pkg/packageset.h b/apt-pkg/packageset.h index d8053694..cd1430a2 100644 --- a/apt-pkg/packageset.h +++ b/apt-pkg/packageset.h @@ -10,7 +10,11 @@ #ifndef APT_PACKAGESET_H #define APT_PACKAGESET_H // Include Files /*{{{*/ +#include +#include +#include #include + #include /*}}}*/ namespace APT { @@ -22,6 +26,8 @@ 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(); } @@ -36,7 +42,8 @@ public: /*{{{*/ 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() {return (*this)->Cache();}; + inline pkgCache *Cache() const { return (*this)->Cache(); }; + inline unsigned long Index() const {return (*this)->Index();}; friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, (*i)); } @@ -46,6 +53,21 @@ public: /*{{{*/ }; // 103. set::iterator is required to be modifiable, but this allows modification of keys typedef typename APT::PackageSet::const_iterator iterator; + + /** \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 out stream to print the notice to */ + static APT::PackageSet FromRegEx(pkgCache &Cache, const char *pattern, std::ostream &out); + static APT::PackageSet FromRegEx(pkgCache &Cache, const char *pattern) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::PackageSet::FromRegEx(Cache, pattern, out); + } + /*}}}*/ }; /*}}}*/ diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 44235e35..1cffd673 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -40,7 +40,8 @@ #include #include #include - +#include + #include #include @@ -1780,51 +1781,24 @@ bool DoInstall(CommandLine &CmdL) Packages++; if (Pkg.end() == true) { - // Check if the name is a regex - const char *I; - for (I = S; *I != 0; I++) - if (*I == '?' || *I == '*' || *I == '|' || - *I == '[' || *I == '^' || *I == '$') - break; - if (*I == 0) + APT::PackageSet pkgset = APT::PackageSet::FromRegEx(Cache, S, c1out); + if (pkgset.empty() == true) return _error->Error(_("Couldn't find package %s"),S); // Regexs must always be confirmed ExpectedInst += 1000; - - // Compile the regex pattern - regex_t Pattern; - int Res; - if ((Res = regcomp(&Pattern,S,REG_EXTENDED | REG_ICASE | - REG_NOSUB)) != 0) - { - char Error[300]; - regerror(Res,&Pattern,Error,sizeof(Error)); - return _error->Error(_("Regex compilation error - %s"),Error); - } - - // Run over the matches + bool Hit = false; - for (pkgCache::GrpIterator Grp = Cache->GrpBegin(); Grp.end() == false; ++Grp) + for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { - if (regexec(&Pattern,Grp.Name(),0,0,0) != 0) - continue; - Pkg = Grp.FindPkg("native"); - if (unlikely(Pkg.end() == true)) - continue; - - ioprintf(c1out,_("Note, selecting %s for regex '%s'\n"), - Pkg.Name(),S); - if (VerTag != 0) if (TryToChangeVer(Pkg,Cache,VerTag,VerIsRel) == false) return false; - + Hit |= TryToInstall(Pkg,Cache,Fix,Remove,BrokenFix, ExpectedInst,false); } - regfree(&Pattern); - + if (Hit == false) return _error->Error(_("Couldn't find package %s"),S); } diff --git a/debian/changelog b/debian/changelog index 6980e5fc..023d513b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -24,6 +24,7 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - add a virtual destructor to FTWScanner class (for cppcheck) * apt-pkg/packageset.h: - add a simple wrapper around std::set for packages with it + - move regex magic from apt-get to new FromRegEx method -- David Kalnischkies Sat, 29 May 2010 19:09:05 +0200 -- cgit v1.2.3 From 78c325968642255fd2325003f19729b617477666 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 31 May 2010 00:28:14 +0200 Subject: move cmdline parsing from apt-cache to new FromCommandLine method --- apt-pkg/packageset.cc | 42 ++++++++++++++++++++++++--- apt-pkg/packageset.h | 53 ++++++++++++++++++++++------------ cmdline/apt-cache.cc | 80 ++++++++++++++------------------------------------- debian/changelog | 1 + 4 files changed, 95 insertions(+), 81 deletions(-) diff --git a/apt-pkg/packageset.cc b/apt-pkg/packageset.cc index f452bc05..baa1c211 100644 --- a/apt-pkg/packageset.cc +++ b/apt-pkg/packageset.cc @@ -9,12 +9,15 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include #include #include #include #include +#include + #include /*}}}*/ namespace APT { @@ -44,18 +47,49 @@ PackageSet PackageSet::FromRegEx(pkgCache &Cache, const char * const pattern, st if (regexec(&Pattern, Grp.Name(), 0, 0, 0) != 0) continue; pkgCache::PkgIterator Pkg = Grp.FindPkg("native"); - if (unlikely(Pkg.end() == true)) - // FIXME: Fallback to different architectures here? - continue; + if (Pkg.end() == true) { + 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; + } ioprintf(out, _("Note, selecting %s for regex '%s'\n"), - Pkg.Name(), pattern); + Pkg.FullName(true).c_str(), pattern); pkgset.insert(Pkg); } regfree(&Pattern); + return pkgset; +} + /*}}}*/ +// FromCommandLine - Return all packages specified on commandline /*{{{*/ +PackageSet PackageSet::FromCommandLine(pkgCache &Cache, const char **cmdline, std::ostream &out) { + PackageSet pkgset; + for (const char **I = cmdline + 1; *I != 0; I++) { + pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); + if (Pkg.end() == true) { + std::vector archs = APT::Configuration::getArchitectures(); + for (std::vector::const_iterator a = archs.begin(); + a != archs.end() || Pkg.end() != true; ++a) { + Pkg = Cache.FindPkg(*I, *a); + } + if (Pkg.end() == true) { + PackageSet regex = FromRegEx(Cache, *I, out); + if (regex.empty() == true) + _error->Warning(_("Unable to locate package %s"),*I); + else + pkgset.insert(regex.begin(), regex.end()); + continue; + } + } + pkgset.insert(Pkg); + } return pkgset; } /*}}}*/ diff --git a/apt-pkg/packageset.h b/apt-pkg/packageset.h index cd1430a2..0bd60c56 100644 --- a/apt-pkg/packageset.h +++ b/apt-pkg/packageset.h @@ -28,27 +28,29 @@ public: /*{{{*/ 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();}; + 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::PkgIterator const * operator->() const { - return &**this; + inline pkgCache::Package const * operator->() const { + return &***this; }; }; // 103. set::iterator is required to be modifiable, but this allows modification of keys @@ -68,6 +70,21 @@ public: /*{{{*/ return APT::PackageSet::FromRegEx(Cache, pattern, out); } + /** \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 out stream to print various notices to */ + static APT::PackageSet FromCommandLine(pkgCache &Cache, const char **cmdline, std::ostream &out); + static APT::PackageSet FromCommandLine(pkgCache &Cache, const char **cmdline) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::PackageSet::FromCommandLine(Cache, cmdline, out); + } + + + /*}}}*/ }; /*}}}*/ diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 10dbf44d..95f185b4 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -175,15 +176,10 @@ bool UnMet(CommandLine &CmdL) bool DumpPackage(CommandLine &CmdL) { pkgCache &Cache = *GCache; - for (const char **I = CmdL.FileList + 1; *I != 0; I++) - { - pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); - if (Pkg.end() == true) - { - _error->Warning(_("Unable to locate package %s"),*I); - continue; - } + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) + { cout << "Package: " << Pkg.FullName(true) << endl; cout << "Versions: " << endl; for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++) @@ -545,18 +541,11 @@ bool Depends(CommandLine &CmdL) pkgCache &Cache = *GCache; SPtrArray Colours = new unsigned[Cache.Head().PackageCount]; memset(Colours,0,sizeof(*Colours)*Cache.Head().PackageCount); - - for (const char **I = CmdL.FileList + 1; *I != 0; I++) - { - pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); - if (Pkg.end() == true) - { - _error->Warning(_("Unable to locate package %s"),*I); - continue; - } + + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + 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); @@ -639,18 +628,11 @@ bool RDepends(CommandLine &CmdL) pkgCache &Cache = *GCache; SPtrArray Colours = new unsigned[Cache.Head().PackageCount]; memset(Colours,0,sizeof(*Colours)*Cache.Head().PackageCount); - - for (const char **I = CmdL.FileList + 1; *I != 0; I++) - { - pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); - if (Pkg.end() == true) - { - _error->Warning(_("Unable to locate package %s"),*I); - continue; - } + + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + 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 DidSomething; @@ -1440,23 +1422,9 @@ bool ShowPackage(CommandLine &CmdL) pkgCache &Cache = *GCache; pkgDepCache::Policy Plcy; - unsigned found = 0; - - for (const char **I = CmdL.FileList + 1; *I != 0; I++) + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { - // FIXME: Handle the case in which pkgname name:arch is not found - pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); - if (Pkg.end() == true) - { - Pkg = Cache.FindPkg(*I, "any"); - if (Pkg.end() == true) { - _error->Warning(_("Unable to locate package %s"),*I); - continue; - } - } - - ++found; - // Find the proper version to use. if (_config->FindB("APT::Cache::AllVersions","true") == true) { @@ -1477,7 +1445,7 @@ bool ShowPackage(CommandLine &CmdL) } } - if (found > 0) + if (pkgset.empty() == false) return true; return _error->Error(_("No packages found")); } @@ -1622,15 +1590,10 @@ bool Policy(CommandLine &CmdL) (InstalledLessCandidate > 0 ? (InstalledLessCandidate) : 0) - 1; // Print out detailed information for each package - for (const char **I = CmdL.FileList + 1; *I != 0; I++) + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + for (APT::PackageSet::const_iterator I = pkgset.begin(); I != pkgset.end(); ++I) { - pkgCache::GrpIterator Grp = Cache.FindGrp(*I); - pkgCache::PkgIterator Pkg = Grp.FindPkg("any"); - if (Pkg.end() == true) - { - _error->Warning(_("Unable to locate package %s"),*I); - continue; - } + pkgCache::PkgIterator Pkg = I.Group().FindPkg("any"); for (; Pkg.end() != true; Pkg = Grp.NextPkg(Pkg)) { if (strcmp(Pkg.Arch(),"all") == 0) @@ -1708,10 +1671,9 @@ bool Madison(CommandLine &CmdL) if (_error->PendingError() == true) _error->Discard(); - for (const char **I = CmdL.FileList + 1; *I != 0; I++) + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { - pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); - if (Pkg.end() == false) { for (pkgCache::VerIterator V = Pkg.VersionList(); V.end() == false; V++) @@ -1746,7 +1708,7 @@ bool Madison(CommandLine &CmdL) SrcRecs.Restart(); pkgSrcRecords::Parser *SrcParser; - while ((SrcParser = SrcRecs.Find(*I,false)) != 0) + while ((SrcParser = SrcRecs.Find(Pkg.Name(),false)) != 0) { // Maybe support Release info here too eventually cout << setw(10) << SrcParser->Package() << " | " diff --git a/debian/changelog b/debian/changelog index 023d513b..79768a77 100644 --- a/debian/changelog +++ b/debian/changelog @@ -25,6 +25,7 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low * apt-pkg/packageset.h: - add a simple wrapper around std::set for packages with it - move regex magic from apt-get to new FromRegEx method + - move cmdline parsing from apt-cache to new FromCommandLine method -- David Kalnischkies Sat, 29 May 2010 19:09:05 +0200 -- cgit v1.2.3 From 4c265635a8417b857a3a8f537c74313d5533da9b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 31 May 2010 12:58:20 +0200 Subject: i managed to commit broken code… which (at least in my mind) worked yesterday. Strange… anyway only small fixes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmdline/apt-cache.cc | 2 +- ftparchive/writer.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 95f185b4..943a001a 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1595,7 +1595,7 @@ bool Policy(CommandLine &CmdL) { pkgCache::PkgIterator Pkg = I.Group().FindPkg("any"); - for (; Pkg.end() != true; Pkg = Grp.NextPkg(Pkg)) { + for (; Pkg.end() != true; Pkg = I.Group().NextPkg(Pkg)) { if (strcmp(Pkg.Arch(),"all") == 0) continue; diff --git a/ftparchive/writer.h b/ftparchive/writer.h index c08ddea8..49d430c4 100644 --- a/ftparchive/writer.h +++ b/ftparchive/writer.h @@ -72,7 +72,7 @@ class FTWScanner bool SetExts(string const &Vals); FTWScanner(string const &Arch = string()); - virtual ~FTWScanner(); + virtual ~FTWScanner() {}; }; class TranslationWriter -- cgit v1.2.3 From 6e235c6640cdc6cb9a8c3eaa1e65a6141f463676 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 31 May 2010 14:16:44 +0200 Subject: improve the handling of regex together with the architecture modifier --- apt-pkg/packageset.cc | 35 +++++++++++++++++++++-------------- apt-pkg/packageset.h | 4 ++-- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/apt-pkg/packageset.cc b/apt-pkg/packageset.cc index baa1c211..f296b7c4 100644 --- a/apt-pkg/packageset.cc +++ b/apt-pkg/packageset.cc @@ -22,20 +22,26 @@ /*}}}*/ namespace APT { // FromRegEx - Return all packages in the cache matching a pattern /*{{{*/ -PackageSet PackageSet::FromRegEx(pkgCache &Cache, const char * const pattern, std::ostream &out) { +PackageSet PackageSet::FromRegEx(pkgCache &Cache, std::string pattern, std::ostream &out) { PackageSet pkgset; + std::string arch = "native"; + static const char * const isregex = ".?+*|[^$"; - const char * I; - for (I = pattern; *I != 0; I++) - if (*I == '.' || *I == '?' || *I == '+' || *I == '*' || - *I == '|' || *I == '[' || *I == '^' || *I == '$') - break; - if (*I == 0) + if (pattern.find_first_of(isregex) == std::string::npos) return pkgset; + size_t archfound = pattern.find_last_of(':'); + 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"; + } + regex_t Pattern; int Res; - if ((Res = regcomp(&Pattern, pattern , REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0) { + 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); @@ -46,19 +52,20 @@ PackageSet PackageSet::FromRegEx(pkgCache &Cache, const char * const pattern, st { if (regexec(&Pattern, Grp.Name(), 0, 0, 0) != 0) continue; - pkgCache::PkgIterator Pkg = Grp.FindPkg("native"); + pkgCache::PkgIterator Pkg = Grp.FindPkg(arch); if (Pkg.end() == true) { - 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 (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; } ioprintf(out, _("Note, selecting %s for regex '%s'\n"), - Pkg.FullName(true).c_str(), pattern); + Pkg.FullName(true).c_str(), pattern.c_str()); pkgset.insert(Pkg); } diff --git a/apt-pkg/packageset.h b/apt-pkg/packageset.h index 0bd60c56..9f80d60e 100644 --- a/apt-pkg/packageset.h +++ b/apt-pkg/packageset.h @@ -64,8 +64,8 @@ public: /*{{{*/ \param Cache the packages are in \param pattern regular expression for package names \param out stream to print the notice to */ - static APT::PackageSet FromRegEx(pkgCache &Cache, const char *pattern, std::ostream &out); - static APT::PackageSet FromRegEx(pkgCache &Cache, const char *pattern) { + static APT::PackageSet FromRegEx(pkgCache &Cache, std::string pattern, std::ostream &out); + static APT::PackageSet FromRegEx(pkgCache &Cache, std::string const &pattern) { std::ostream out (std::ofstream("/dev/null").rdbuf()); return APT::PackageSet::FromRegEx(Cache, pattern, out); } -- cgit v1.2.3 From 093e9f5d30f37164dd28d639fedfb059e105e43e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 31 May 2010 17:22:04 +0200 Subject: * apt-pkg/contrib/cmdline.cc: - fix segfault in SaveInConfig caused by writing over char[] sizes --- apt-pkg/contrib/cmndline.cc | 4 ++-- debian/changelog | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc index 0b16bf51..5a994409 100644 --- a/apt-pkg/contrib/cmndline.cc +++ b/apt-pkg/contrib/cmndline.cc @@ -360,11 +360,11 @@ bool CommandLine::DispatchArg(Dispatch *Map,bool NoMatch) than nothing after all. */ void CommandLine::SaveInConfig(unsigned int const &argc, char const * const * const argv) { - char cmdline[300]; + char cmdline[100 + argc * 50]; unsigned int length = 0; bool lastWasOption = false; bool closeQuote = false; - for (unsigned int i = 0; i < argc; ++i, ++length) + for (unsigned int i = 0; i < argc && length < sizeof(cmdline); ++i, ++length) { for (unsigned int j = 0; argv[i][j] != '\0' && length < sizeof(cmdline)-1; ++j, ++length) { diff --git a/debian/changelog b/debian/changelog index 79768a77..6341484f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -26,8 +26,10 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - add a simple wrapper around std::set for packages with it - move regex magic from apt-get to new FromRegEx method - move cmdline parsing from apt-cache to new FromCommandLine method + * apt-pkg/contrib/cmdline.cc: + - fix segfault in SaveInConfig caused by writing over char[] sizes - -- David Kalnischkies Sat, 29 May 2010 19:09:05 +0200 + -- David Kalnischkies Mon, 31 May 2010 17:21:00 +0200 apt (0.7.26~exp5) experimental; urgency=low -- cgit v1.2.3 From bd2fb30a8647293f80b085d0308e66bb9219e662 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 31 May 2010 20:00:16 +0200 Subject: * apt-pkg/pkgcache.cc: - get the best matching arch package from a group with FindPreferredPkg --- apt-pkg/cacheiterators.h | 5 +++++ apt-pkg/pkgcache.cc | 19 +++++++++++++++++++ debian/changelog | 4 +++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index ee852f59..e5b23a81 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -104,6 +104,11 @@ class pkgCache::GrpIterator: public Iterator { inline const char *Name() const {return S->Name == 0?0:Owner->StrP + S->Name;}; inline PkgIterator PackageList() const; PkgIterator FindPkg(string Arch = "any"); + /** \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(); PkgIterator NextPkg(PkgIterator const &Pkg); // Constructors diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index a59a06d6..adaae9c8 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -340,6 +340,25 @@ pkgCache::PkgIterator pkgCache::GrpIterator::FindPkg(string Arch) { break; } + return PkgIterator(*Owner, 0); +} + /*}}}*/ +// GrpIterator::FindPreferredPkg - Locate the "best" package /*{{{*/ +// --------------------------------------------------------------------- +/* Returns an End-Pointer on error, pointer to the package otherwise */ +pkgCache::PkgIterator pkgCache::GrpIterator::FindPreferredPkg() { + pkgCache::PkgIterator Pkg = FindPkg("native"); + if (Pkg.end() == false) + 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) + return Pkg; + } + return PkgIterator(*Owner, 0); } /*}}}*/ diff --git a/debian/changelog b/debian/changelog index 6341484f..92000348 100644 --- a/debian/changelog +++ b/debian/changelog @@ -28,8 +28,10 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - move cmdline parsing from apt-cache to new FromCommandLine method * apt-pkg/contrib/cmdline.cc: - fix segfault in SaveInConfig caused by writing over char[] sizes + * apt-pkg/pkgcache.cc: + - get the best matching arch package from a group with FindPreferredPkg - -- David Kalnischkies Mon, 31 May 2010 17:21:00 +0200 + -- David Kalnischkies Mon, 31 May 2010 19:59:04 +0200 apt (0.7.26~exp5) experimental; urgency=low -- cgit v1.2.3 From d5cc17d6c2ba4e29e800e489d5f3b3cf4a405543 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 31 May 2010 20:02:41 +0200 Subject: * cmdline/apt-cache.cc: - make the search multiarch compatible by using GrpIterator instead --- cmdline/apt-cache.cc | 77 +++++++++++++++++++++++++++------------------------- debian/changelog | 4 ++- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 943a001a..d8e14617 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1272,15 +1272,15 @@ struct ExDescFile bool Search(CommandLine &CmdL) { pkgCache &Cache = *GCache; - bool ShowFull = _config->FindB("APT::Cache::ShowFull",false); - bool NamesOnly = _config->FindB("APT::Cache::NamesOnly",false); - unsigned NumPatterns = CmdL.FileSize() -1; + bool const ShowFull = _config->FindB("APT::Cache::ShowFull",false); + bool const NamesOnly = _config->FindB("APT::Cache::NamesOnly",false); + unsigned int const NumPatterns = CmdL.FileSize() -1; pkgDepCache::Policy Plcy; // Make sure there is at least one argument if (NumPatterns < 1) - return _error->Error(_("You must give exactly one pattern")); + return _error->Error(_("You must give at least one search pattern")); // Compile the regex pattern regex_t *Patterns = new regex_t[NumPatterns]; @@ -1296,8 +1296,6 @@ bool Search(CommandLine &CmdL) } } - // Create the text record parser - pkgRecords Recs(Cache); if (_error->PendingError() == true) { for (unsigned I = 0; I != NumPatterns; I++) @@ -1305,70 +1303,75 @@ bool Search(CommandLine &CmdL) return false; } - ExDescFile *DFList = new ExDescFile[Cache.HeaderP->PackageCount+1]; - memset(DFList,0,sizeof(*DFList)*Cache.HeaderP->PackageCount+1); + ExDescFile *DFList = new ExDescFile[Cache.HeaderP->GroupCount+1]; + memset(DFList,0,sizeof(*DFList)*Cache.HeaderP->GroupCount+1); // Map versions that we want to write out onto the VerList array. - for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) + for (pkgCache::GrpIterator G = Cache.GrpBegin(); G.end() == false; ++G) { - DFList[P->ID].NameMatch = NumPatterns != 0; + if (DFList[G->ID].NameMatch == true) + continue; + + DFList[G->ID].NameMatch = true; for (unsigned I = 0; I != NumPatterns; I++) { - if (regexec(&Patterns[I],P.Name(),0,0,0) == 0) - DFList[P->ID].NameMatch &= true; - else - DFList[P->ID].NameMatch = false; + if (regexec(&Patterns[I],G.Name(),0,0,0) == 0) + continue; + DFList[G->ID].NameMatch = false; + break; } // Doing names only, drop any that dont match.. - if (NamesOnly == true && DFList[P->ID].NameMatch == false) + if (NamesOnly == true && DFList[G->ID].NameMatch == false) continue; - // Find the proper version to use. + // Find the proper version to use + pkgCache::PkgIterator P = G.FindPreferredPkg(); + if (P.end() == true) + continue; pkgCache::VerIterator V = Plcy.GetCandidateVer(P); if (V.end() == false) - DFList[P->ID].Df = V.DescriptionList().FileList(); - } - - // Include all the packages that provide matching names too - for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) - { - if (DFList[P->ID].NameMatch == false) + DFList[G->ID].Df = V.DescriptionList().FileList(); + + if (DFList[G->ID].NameMatch == false) continue; + // Include all the packages that provide matching names too for (pkgCache::PrvIterator Prv = P.ProvidesList() ; Prv.end() == false; Prv++) { pkgCache::VerIterator V = Plcy.GetCandidateVer(Prv.OwnerPkg()); - if (V.end() == false) - { - DFList[Prv.OwnerPkg()->ID].Df = V.DescriptionList().FileList(); - DFList[Prv.OwnerPkg()->ID].NameMatch = true; - } + if (V.end() == true) + continue; + + unsigned long id = Prv.OwnerPkg().Group()->ID; + DFList[id].Df = V.DescriptionList().FileList(); + DFList[id].NameMatch = true; } } - LocalitySort(&DFList->Df,Cache.HeaderP->PackageCount,sizeof(*DFList)); + LocalitySort(&DFList->Df,Cache.HeaderP->GroupCount,sizeof(*DFList)); + // Create the text record parser + pkgRecords Recs(Cache); // Iterate over all the version records and check them for (ExDescFile *J = DFList; J->Df != 0; J++) { pkgRecords::Parser &P = Recs.Lookup(pkgCache::DescFileIterator(Cache,J->Df)); - bool Match = true; - if (J->NameMatch == false) + if (J->NameMatch == false && NamesOnly == false) { - string LongDesc = P.LongDesc(); - Match = NumPatterns != 0; + string const LongDesc = P.LongDesc(); + J->NameMatch = true; for (unsigned I = 0; I != NumPatterns; I++) { if (regexec(&Patterns[I],LongDesc.c_str(),0,0,0) == 0) - Match &= true; - else - Match = false; + continue; + J->NameMatch = false; + break; } } - if (Match == true) + if (J->NameMatch == true) { if (ShowFull == true) { diff --git a/debian/changelog b/debian/changelog index 92000348..054088ec 100644 --- a/debian/changelog +++ b/debian/changelog @@ -30,8 +30,10 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - fix segfault in SaveInConfig caused by writing over char[] sizes * apt-pkg/pkgcache.cc: - get the best matching arch package from a group with FindPreferredPkg + * cmdline/apt-cache.cc: + - make the search multiarch compatible by using GrpIterator instead - -- David Kalnischkies Mon, 31 May 2010 19:59:04 +0200 + -- David Kalnischkies Mon, 31 May 2010 20:00:24 +0200 apt (0.7.26~exp5) experimental; urgency=low -- cgit v1.2.3 From 7959c5eda83bd6d69876942566cf47d74fc76530 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 31 May 2010 21:00:09 +0200 Subject: rename packageset into cacheset while it is not too late --- apt-pkg/cacheset.cc | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++ apt-pkg/cacheset.h | 96 ++++++++++++++++++++++++++++++++++++++++++++++ apt-pkg/makefile | 4 +- apt-pkg/packageset.cc | 103 -------------------------------------------------- apt-pkg/packageset.h | 92 -------------------------------------------- cmdline/apt-cache.cc | 2 +- cmdline/apt-get.cc | 2 +- debian/changelog | 2 +- 8 files changed, 204 insertions(+), 200 deletions(-) create mode 100644 apt-pkg/cacheset.cc create mode 100644 apt-pkg/cacheset.h delete mode 100644 apt-pkg/packageset.cc delete mode 100644 apt-pkg/packageset.h diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc new file mode 100644 index 00000000..b49b3653 --- /dev/null +++ b/apt-pkg/cacheset.cc @@ -0,0 +1,103 @@ +// -*- 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 + /*}}}*/ +namespace APT { +// FromRegEx - Return all packages in the cache matching a pattern /*{{{*/ +PackageSet PackageSet::FromRegEx(pkgCache &Cache, std::string pattern, std::ostream &out) { + PackageSet pkgset; + std::string arch = "native"; + static const char * const isregex = ".?+*|[^$"; + + if (pattern.find_first_of(isregex) == std::string::npos) + return pkgset; + + size_t archfound = pattern.find_last_of(':'); + 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"; + } + + 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 pkgset; + } + + for (pkgCache::GrpIterator Grp = Cache.GrpBegin(); Grp.end() == false; ++Grp) + { + if (regexec(&Pattern, Grp.Name(), 0, 0, 0) != 0) + 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; + } + + ioprintf(out, _("Note, selecting %s for regex '%s'\n"), + Pkg.FullName(true).c_str(), pattern.c_str()); + + pkgset.insert(Pkg); + } + + regfree(&Pattern); + + return pkgset; +} + /*}}}*/ +// FromCommandLine - Return all packages specified on commandline /*{{{*/ +PackageSet PackageSet::FromCommandLine(pkgCache &Cache, const char **cmdline, std::ostream &out) { + PackageSet pkgset; + for (const char **I = cmdline + 1; *I != 0; I++) { + pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); + if (Pkg.end() == true) { + std::vector archs = APT::Configuration::getArchitectures(); + for (std::vector::const_iterator a = archs.begin(); + a != archs.end() || Pkg.end() != true; ++a) { + Pkg = Cache.FindPkg(*I, *a); + } + if (Pkg.end() == true) { + PackageSet regex = FromRegEx(Cache, *I, out); + if (regex.empty() == true) + _error->Warning(_("Unable to locate package %s"),*I); + else + pkgset.insert(regex.begin(), regex.end()); + continue; + } + } + pkgset.insert(Pkg); + } + return pkgset; +} + /*}}}*/ +} diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h new file mode 100644 index 00000000..7c05face --- /dev/null +++ b/apt-pkg/cacheset.h @@ -0,0 +1,96 @@ +// -*- 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 + /*}}}*/ +namespace APT { +/** \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. */ +class PackageSet : public std::set { /*{{{*/ +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 typename APT::PackageSet::const_iterator iterator; + + /** \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 out stream to print the notice to */ + static APT::PackageSet FromRegEx(pkgCache &Cache, std::string pattern, std::ostream &out); + static APT::PackageSet FromRegEx(pkgCache &Cache, std::string const &pattern) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::PackageSet::FromRegEx(Cache, pattern, out); + } + + /** \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 out stream to print various notices to */ + static APT::PackageSet FromCommandLine(pkgCache &Cache, const char **cmdline, std::ostream &out); + static APT::PackageSet FromCommandLine(pkgCache &Cache, const char **cmdline) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::PackageSet::FromCommandLine(Cache, cmdline, out); + } + + + + /*}}}*/ +}; + /*}}}*/ +} +#endif diff --git a/apt-pkg/makefile b/apt-pkg/makefile index 968275c5..1a707869 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 packageset.cc + aptconfiguration.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 \ - packageset.h + cacheset.h # Source code for the debian specific components # In theory the deb headers do not need to be exported.. diff --git a/apt-pkg/packageset.cc b/apt-pkg/packageset.cc deleted file mode 100644 index f296b7c4..00000000 --- a/apt-pkg/packageset.cc +++ /dev/null @@ -1,103 +0,0 @@ -// -*- mode: cpp; mode: fold -*- -// Description /*{{{*/ -/* ###################################################################### - - 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. - - ##################################################################### */ - /*}}}*/ -// Include Files /*{{{*/ -#include -#include -#include -#include - -#include - -#include - -#include - /*}}}*/ -namespace APT { -// FromRegEx - Return all packages in the cache matching a pattern /*{{{*/ -PackageSet PackageSet::FromRegEx(pkgCache &Cache, std::string pattern, std::ostream &out) { - PackageSet pkgset; - std::string arch = "native"; - static const char * const isregex = ".?+*|[^$"; - - if (pattern.find_first_of(isregex) == std::string::npos) - return pkgset; - - size_t archfound = pattern.find_last_of(':'); - 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"; - } - - 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 pkgset; - } - - for (pkgCache::GrpIterator Grp = Cache.GrpBegin(); Grp.end() == false; ++Grp) - { - if (regexec(&Pattern, Grp.Name(), 0, 0, 0) != 0) - 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; - } - - ioprintf(out, _("Note, selecting %s for regex '%s'\n"), - Pkg.FullName(true).c_str(), pattern.c_str()); - - pkgset.insert(Pkg); - } - - regfree(&Pattern); - - return pkgset; -} - /*}}}*/ -// FromCommandLine - Return all packages specified on commandline /*{{{*/ -PackageSet PackageSet::FromCommandLine(pkgCache &Cache, const char **cmdline, std::ostream &out) { - PackageSet pkgset; - for (const char **I = cmdline + 1; *I != 0; I++) { - pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); - if (Pkg.end() == true) { - std::vector archs = APT::Configuration::getArchitectures(); - for (std::vector::const_iterator a = archs.begin(); - a != archs.end() || Pkg.end() != true; ++a) { - Pkg = Cache.FindPkg(*I, *a); - } - if (Pkg.end() == true) { - PackageSet regex = FromRegEx(Cache, *I, out); - if (regex.empty() == true) - _error->Warning(_("Unable to locate package %s"),*I); - else - pkgset.insert(regex.begin(), regex.end()); - continue; - } - } - pkgset.insert(Pkg); - } - return pkgset; -} - /*}}}*/ -} diff --git a/apt-pkg/packageset.h b/apt-pkg/packageset.h deleted file mode 100644 index 9f80d60e..00000000 --- a/apt-pkg/packageset.h +++ /dev/null @@ -1,92 +0,0 @@ -// -*- mode: cpp; mode: fold -*- -// Description /*{{{*/ -/** \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. -*/ - /*}}}*/ -#ifndef APT_PACKAGESET_H -#define APT_PACKAGESET_H -// Include Files /*{{{*/ -#include -#include -#include -#include - -#include - /*}}}*/ -namespace APT { -class PackageSet : public std::set { /*{{{*/ -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 typename APT::PackageSet::const_iterator iterator; - - /** \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 out stream to print the notice to */ - static APT::PackageSet FromRegEx(pkgCache &Cache, std::string pattern, std::ostream &out); - static APT::PackageSet FromRegEx(pkgCache &Cache, std::string const &pattern) { - std::ostream out (std::ofstream("/dev/null").rdbuf()); - return APT::PackageSet::FromRegEx(Cache, pattern, out); - } - - /** \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 out stream to print various notices to */ - static APT::PackageSet FromCommandLine(pkgCache &Cache, const char **cmdline, std::ostream &out); - static APT::PackageSet FromCommandLine(pkgCache &Cache, const char **cmdline) { - std::ostream out (std::ofstream("/dev/null").rdbuf()); - return APT::PackageSet::FromCommandLine(Cache, cmdline, out); - } - - - - /*}}}*/ -}; - /*}}}*/ -} -#endif diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index d8e14617..891b1087 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 1cffd673..9894747f 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include diff --git a/debian/changelog b/debian/changelog index 054088ec..6b9057ae 100644 --- a/debian/changelog +++ b/debian/changelog @@ -22,7 +22,7 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - correct "Dangerous iterator usage." pointed out by cppcheck * ftparchive/writer.h: - add a virtual destructor to FTWScanner class (for cppcheck) - * apt-pkg/packageset.h: + * apt-pkg/cacheset.h: - add a simple wrapper around std::set for packages with it - move regex magic from apt-get to new FromRegEx method - move cmdline parsing from apt-cache to new FromCommandLine method -- cgit v1.2.3 From d4489d4983d5b9840bb2882a088dd1f363a280b9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 31 May 2010 22:36:41 +0200 Subject: * apt-pkg/cacheset.{cc,h}: - add simple wrapper around std::set for cache structures --- apt-pkg/cacheiterators.h | 4 ++-- apt-pkg/cacheset.h | 49 +++++++++++++++++++++++++++++++++++++++++++++--- apt-pkg/pkgcache.cc | 2 +- debian/changelog | 6 +++--- 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index e5b23a81..f0b40dbb 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -205,8 +205,8 @@ class pkgCache::VerIterator : public Iterator { inline PrvIterator ProvidesList() const; inline VerFileIterator FileList() const; bool Downloadable() const; - inline const char *PriorityType() {return Owner->Priority(S->Priority);}; - string RelStr(); + inline const char *PriorityType() const {return Owner->Priority(S->Priority);}; + string RelStr() const; bool Automatic() const; bool Pseudo() const; diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index 7c05face..f0131bfe 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -17,12 +17,12 @@ #include /*}}}*/ namespace APT { +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. */ -class PackageSet : public std::set { /*{{{*/ public: /*{{{*/ /** \brief smell like a pkgCache::PkgIterator */ class const_iterator : public std::set::const_iterator { @@ -86,11 +86,54 @@ public: /*{{{*/ std::ostream out (std::ofstream("/dev/null").rdbuf()); return APT::PackageSet::FromCommandLine(Cache, cmdline, out); } + /*}}}*/ +}; /*}}}*/ +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 typename APT::VersionSet::const_iterator iterator; /*}}}*/ -}; - /*}}}*/ +}; /*}}}*/ } #endif diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index adaae9c8..30bb4147 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -742,7 +742,7 @@ pkgCache::VerFileIterator pkgCache::VerIterator::NewestFile() const // --------------------------------------------------------------------- /* This describes the version from a release-centric manner. The output is a list of Label:Version/Archive */ -string pkgCache::VerIterator::RelStr() +string pkgCache::VerIterator::RelStr() const { bool First = true; string Res; diff --git a/debian/changelog b/debian/changelog index 6b9057ae..994be2bb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -22,8 +22,8 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - correct "Dangerous iterator usage." pointed out by cppcheck * ftparchive/writer.h: - add a virtual destructor to FTWScanner class (for cppcheck) - * apt-pkg/cacheset.h: - - add a simple wrapper around std::set for packages with it + * apt-pkg/cacheset.{cc,h}: + - add simple wrapper around std::set for cache structures - move regex magic from apt-get to new FromRegEx method - move cmdline parsing from apt-cache to new FromCommandLine method * apt-pkg/contrib/cmdline.cc: @@ -33,7 +33,7 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low * cmdline/apt-cache.cc: - make the search multiarch compatible by using GrpIterator instead - -- David Kalnischkies Mon, 31 May 2010 20:00:24 +0200 + -- David Kalnischkies Mon, 31 May 2010 22:36:35 +0200 apt (0.7.26~exp5) experimental; urgency=low -- cgit v1.2.3 From e2c66de5c5e63d8400efb0522c31fbe1ec225f93 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 3 Jun 2010 09:22:00 +0200 Subject: * apt-pkg/pkgcache.h: - switch {,Install-}Size to unsigned long long * apt-pkg/depcache.cc: - deal with long long, not with int to remove 2GB Limit (LP: #250909) --- apt-pkg/acquire-item.h | 4 ++-- apt-pkg/deb/deblistparser.cc | 5 ++--- apt-pkg/depcache.cc | 14 +++++++------- apt-pkg/pkgcache.h | 4 ++-- apt-pkg/tagfile.cc | 24 ++++++++++++++++++++++++ apt-pkg/tagfile.h | 1 + debian/changelog | 10 ++++++++++ 7 files changed, 48 insertions(+), 14 deletions(-) diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h index b338b2a4..36fc53b9 100644 --- a/apt-pkg/acquire-item.h +++ b/apt-pkg/acquire-item.h @@ -112,10 +112,10 @@ class pkgAcquire::Item : public WeakPointable string ErrorText; /** \brief The size of the object to fetch. */ - unsigned long FileSize; + unsigned long long FileSize; /** \brief How much of the object was already fetched. */ - unsigned long PartialSize; + unsigned long long PartialSize; /** \brief If not \b NULL, contains the name of a subprocess that * is operating on this object (for instance, "gzip" or "gpgv"). diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 0551a5f7..83c5b8d2 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -133,10 +133,9 @@ bool debListParser::NewVersion(pkgCache::VerIterator Ver) } // Archive Size - Ver->Size = (unsigned)Section.FindI("Size"); - + Ver->Size = Section.FindULL("Size"); // Unpacked Size (in K) - Ver->InstalledSize = (unsigned)Section.FindI("Installed-Size"); + Ver->InstalledSize = Section.FindULL("Installed-Size"); Ver->InstalledSize *= 1024; // Priority diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 411ae5f6..6e0eeab5 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -422,8 +422,8 @@ void pkgDepCache::AddSizes(const PkgIterator &Pkg,signed long Mult) // Compute the size data if (P.NewInstall() == true) { - iUsrSize += (signed)(Mult*P.InstVerIter(*this)->InstalledSize); - iDownloadSize += (signed)(Mult*P.InstVerIter(*this)->Size); + iUsrSize += (signed long long)(Mult*P.InstVerIter(*this)->InstalledSize); + iDownloadSize += (signed long long)(Mult*P.InstVerIter(*this)->Size); return; } @@ -432,9 +432,9 @@ void pkgDepCache::AddSizes(const PkgIterator &Pkg,signed long Mult) (P.InstallVer != (Version *)Pkg.CurrentVer() || (P.iFlags & ReInstall) == ReInstall) && P.InstallVer != 0) { - iUsrSize += (signed)(Mult*((signed)P.InstVerIter(*this)->InstalledSize - - (signed)Pkg.CurrentVer()->InstalledSize)); - iDownloadSize += (signed)(Mult*P.InstVerIter(*this)->Size); + iUsrSize += (signed long long)(Mult*((signed long long)P.InstVerIter(*this)->InstalledSize - + (signed long long)Pkg.CurrentVer()->InstalledSize)); + iDownloadSize += (signed long long)(Mult*P.InstVerIter(*this)->Size); return; } @@ -442,14 +442,14 @@ void pkgDepCache::AddSizes(const PkgIterator &Pkg,signed long Mult) if (Pkg.State() == pkgCache::PkgIterator::NeedsUnpack && P.Delete() == false) { - iDownloadSize += (signed)(Mult*P.InstVerIter(*this)->Size); + iDownloadSize += (signed long long)(Mult*P.InstVerIter(*this)->Size); return; } // Removing if (Pkg->CurrentVer != 0 && P.InstallVer == 0) { - iUsrSize -= (signed)(Mult*Pkg.CurrentVer()->InstalledSize); + iUsrSize -= (signed long long)(Mult*Pkg.CurrentVer()->InstalledSize); return; } } diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h index 643f240b..426bb9f1 100644 --- a/apt-pkg/pkgcache.h +++ b/apt-pkg/pkgcache.h @@ -532,9 +532,9 @@ struct pkgCache::Version /** \brief archive size for this version For Debian this is the size of the .deb file. */ - map_ptrloc Size; // These are the .deb size + unsigned long long Size; // These are the .deb size /** \brief uncompressed size for this version */ - map_ptrloc InstalledSize; + unsigned long long InstalledSize; /** \brief characteristic value representing this version No two packages in existence should have the same VerStr diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc index 0d4999ee..1394d7e2 100644 --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@ -365,6 +365,30 @@ signed int pkgTagSection::FindI(const char *Tag,signed long Default) const return Result; } /*}}}*/ +// TagSection::FindULL - Find an unsigned long long integer /*{{{*/ +// --------------------------------------------------------------------- +/* */ +unsigned long long pkgTagSection::FindULL(const char *Tag, unsigned long long const &Default) const +{ + const char *Start; + const char *Stop; + if (Find(Tag,Start,Stop) == false) + return Default; + + // Copy it into a temp buffer so we can use strtoull + char S[100]; + if ((unsigned)(Stop - Start) >= sizeof(S)) + return Default; + strncpy(S,Start,Stop-Start); + S[Stop - Start] = 0; + + char *End; + unsigned long long Result = strtoull(S,&End,10); + if (S == End) + return Default; + return Result; +} + /*}}}*/ // TagSection::FindFlag - Locate a yes/no type flag /*{{{*/ // --------------------------------------------------------------------- /* The bits marked in Flag are masked on/off in Flags */ diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index f63a51d0..6891c1d8 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -57,6 +57,7 @@ class pkgTagSection bool Find(const char *Tag,unsigned &Pos) const; string FindS(const char *Tag) const; signed int FindI(const char *Tag,signed long Default = 0) const ; + unsigned long long FindULL(const char *Tag, unsigned long long const &Default = 0) const; bool FindFlag(const char *Tag,unsigned long &Flags, unsigned long Flag) const; bool Scan(const char *Start,unsigned long MaxLength); diff --git a/debian/changelog b/debian/changelog index 3771ca41..e153027b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,13 @@ +apt (0.7.26~exp6) UNRELEASED; urgency=low + + [ David Kalnischkies ] + * apt-pkg/pkgcache.h: + - switch {,Install-}Size to unsigned long long + * apt-pkg/depcache.cc: + - deal with long long, not with int to remove 2GB Limit (LP: #250909) + + -- David Kalnischkies Thu, 03 Jun 2010 09:19:01 +0200 + apt (0.7.26~exp5) experimental; urgency=low [ David Kalnischkies ] -- cgit v1.2.3 From 81305a0b30cc12aa6d32081bbdcf930907ecfbbe Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 3 Jun 2010 09:50:06 +0200 Subject: deprecate AddSize with Multiplier as it is unused and switch to boolean instead to handle the sizes more gracefully. --- apt-pkg/depcache.cc | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++-- apt-pkg/depcache.h | 5 ++-- debian/changelog | 2 ++ 3 files changed, 76 insertions(+), 4 deletions(-) diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 6e0eeab5..786b20ec 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -407,8 +407,11 @@ bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res) /*}}}*/ // DepCache::AddSizes - Add the packages sizes to the counters /*{{{*/ // --------------------------------------------------------------------- -/* Call with Mult = -1 to preform the inverse opration */ -void pkgDepCache::AddSizes(const PkgIterator &Pkg,signed long Mult) +/* Call with Mult = -1 to preform the inverse opration + The Mult increases the complexity of the calulations here and is unused - + or do we really have a usecase for removing the size of a package two + times? So let us replace it with a simple bool and be done with it… */ +__deprecated void pkgDepCache::AddSizes(const PkgIterator &Pkg,signed long Mult) { StateCache &P = PkgState[Pkg->ID]; @@ -454,6 +457,72 @@ void pkgDepCache::AddSizes(const PkgIterator &Pkg,signed long Mult) } } /*}}}*/ +// DepCache::AddSizes - Add the packages sizes to the counters /*{{{*/ +// --------------------------------------------------------------------- +/* Call with Inverse = true to preform the inverse opration */ +void pkgDepCache::AddSizes(const PkgIterator &Pkg, bool const &Inverse) +{ + StateCache &P = PkgState[Pkg->ID]; + + if (Pkg->VersionList == 0) + return; + + if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure && + P.Keep() == true) + return; + + // Compute the size data + if (P.NewInstall() == true) + { + if (Inverse == false) { + iUsrSize += P.InstVerIter(*this)->InstalledSize; + iDownloadSize += P.InstVerIter(*this)->Size; + } else { + iUsrSize -= P.InstVerIter(*this)->InstalledSize; + iDownloadSize -= P.InstVerIter(*this)->Size; + } + return; + } + + // Upgrading + if (Pkg->CurrentVer != 0 && + (P.InstallVer != (Version *)Pkg.CurrentVer() || + (P.iFlags & ReInstall) == ReInstall) && P.InstallVer != 0) + { + if (Inverse == false) { + iUsrSize -= Pkg.CurrentVer()->InstalledSize; + iUsrSize += P.InstVerIter(*this)->InstalledSize; + iDownloadSize += P.InstVerIter(*this)->Size; + } else { + iUsrSize -= P.InstVerIter(*this)->InstalledSize; + iUsrSize += Pkg.CurrentVer()->InstalledSize; + iDownloadSize -= P.InstVerIter(*this)->Size; + } + return; + } + + // Reinstall + if (Pkg.State() == pkgCache::PkgIterator::NeedsUnpack && + P.Delete() == false) + { + if (Inverse == false) + iDownloadSize += P.InstVerIter(*this)->Size; + else + iDownloadSize -= P.InstVerIter(*this)->Size; + return; + } + + // Removing + if (Pkg->CurrentVer != 0 && P.InstallVer == 0) + { + if (Inverse == false) + iUsrSize -= Pkg.CurrentVer()->InstalledSize; + else + iUsrSize += Pkg.CurrentVer()->InstalledSize; + return; + } +} + /*}}}*/ // DepCache::AddStates - Add the package to the state counter /*{{{*/ // --------------------------------------------------------------------- /* This routine is tricky to use, you must make sure that it is never diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h index 3decc7a5..d4258438 100644 --- a/apt-pkg/depcache.h +++ b/apt-pkg/depcache.h @@ -321,8 +321,9 @@ class pkgDepCache : protected pkgCache::Namespace void Update(PkgIterator const &P); // Count manipulators - void AddSizes(const PkgIterator &Pkg,signed long Mult = 1); - inline void RemoveSizes(const PkgIterator &Pkg) {AddSizes(Pkg,-1);}; + void AddSizes(const PkgIterator &Pkg, bool const &Invert = false); + inline void RemoveSizes(const PkgIterator &Pkg) {AddSizes(Pkg, true);}; + void AddSizes(const PkgIterator &Pkg,signed long Mult) __deprecated; void AddStates(const PkgIterator &Pkg,int Add = 1); inline void RemoveStates(const PkgIterator &Pkg) {AddStates(Pkg,-1);}; diff --git a/debian/changelog b/debian/changelog index e153027b..2be95675 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,8 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - switch {,Install-}Size to unsigned long long * apt-pkg/depcache.cc: - deal with long long, not with int to remove 2GB Limit (LP: #250909) + - deprecate AddSize with Multiplier as it is unused and switch to + boolean instead to handle the sizes more gracefully. -- David Kalnischkies Thu, 03 Jun 2010 09:19:01 +0200 -- cgit v1.2.3 From a3c4c81afe25377020470ff71c1362136437397c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 3 Jun 2010 10:45:58 +0200 Subject: * apt-pkg/depcache.cc: - switch i{Download,Usr}Size from double to (un)signed long long The biggest reason is that this saves a lot of float point operations we do in AddSizes() on integers. The only reason i see that this was a double is that it was 64bit long and can therefore store bigger values than int/long, but with the availablity of (un)signed long long we are now also at 64bit and can store sizes more than 8 Exabytes big - by the time this will be a limit the C/C++ Standard will have bigger types, hopefully. --- apt-pkg/acquire.cc | 12 ++++++------ apt-pkg/acquire.h | 6 +++--- apt-pkg/depcache.h | 12 +++++++----- debian/changelog | 1 + 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 832eaa02..63825da9 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -506,9 +506,9 @@ bool pkgAcquire::Clean(string Dir) // Acquire::TotalNeeded - Number of bytes to fetch /*{{{*/ // --------------------------------------------------------------------- /* This is the total number of bytes needed */ -double pkgAcquire::TotalNeeded() +unsigned long long pkgAcquire::TotalNeeded() { - double Total = 0; + unsigned long long Total = 0; for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); I++) Total += (*I)->FileSize; return Total; @@ -517,9 +517,9 @@ double pkgAcquire::TotalNeeded() // Acquire::FetchNeeded - Number of bytes needed to get /*{{{*/ // --------------------------------------------------------------------- /* This is the number of bytes that is not local */ -double pkgAcquire::FetchNeeded() +unsigned long long pkgAcquire::FetchNeeded() { - double Total = 0; + unsigned long long Total = 0; for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); I++) if ((*I)->Local == false) Total += (*I)->FileSize; @@ -529,9 +529,9 @@ double pkgAcquire::FetchNeeded() // Acquire::PartialPresent - Number of partial bytes we already have /*{{{*/ // --------------------------------------------------------------------- /* This is the number of bytes that is not local */ -double pkgAcquire::PartialPresent() +unsigned long long pkgAcquire::PartialPresent() { - double Total = 0; + unsigned long long Total = 0; for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); I++) if ((*I)->Local == false) Total += (*I)->PartialSize; diff --git a/apt-pkg/acquire.h b/apt-pkg/acquire.h index 8e2c2115..82be8b84 100644 --- a/apt-pkg/acquire.h +++ b/apt-pkg/acquire.h @@ -323,17 +323,17 @@ class pkgAcquire /** \return the total size in bytes of all the items included in * this download. */ - double TotalNeeded(); + unsigned long long TotalNeeded(); /** \return the size in bytes of all non-local items included in * this download. */ - double FetchNeeded(); + unsigned long long FetchNeeded(); /** \return the amount of data to be fetched that is already * present on the filesystem. */ - double PartialPresent(); + unsigned long long PartialPresent(); /** \brief Delayed constructor * diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h index d4258438..c6f245a8 100644 --- a/apt-pkg/depcache.h +++ b/apt-pkg/depcache.h @@ -286,9 +286,11 @@ class pkgDepCache : protected pkgCache::Namespace pkgCache *Cache; StateCache *PkgState; unsigned char *DepState; - - double iUsrSize; - double iDownloadSize; + + /** Stores the space changes after installation */ + signed long long iUsrSize; + /** Stores how much we need to download to get the packages */ + unsigned long long iDownloadSize; unsigned long iInstCount; unsigned long iDelCount; unsigned long iKeepCount; @@ -452,8 +454,8 @@ class pkgDepCache : protected pkgCache::Namespace bool writeStateFile(OpProgress *prog, bool InstalledOnly=true); // Size queries - inline double UsrSize() {return iUsrSize;}; - inline double DebSize() {return iDownloadSize;}; + inline signed long long UsrSize() {return iUsrSize;}; + inline unsigned long long DebSize() {return iDownloadSize;}; inline unsigned long DelCount() {return iDelCount;}; inline unsigned long KeepCount() {return iKeepCount;}; inline unsigned long InstCount() {return iInstCount;}; diff --git a/debian/changelog b/debian/changelog index 2be95675..97d6abe8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,6 +7,7 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - deal with long long, not with int to remove 2GB Limit (LP: #250909) - deprecate AddSize with Multiplier as it is unused and switch to boolean instead to handle the sizes more gracefully. + - switch i{Download,Usr}Size from double to (un)signed long long -- David Kalnischkies Thu, 03 Jun 2010 09:19:01 +0200 -- cgit v1.2.3 From 3a882565a943644dcf7287c9673fb07f617fb851 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 3 Jun 2010 10:48:19 +0200 Subject: * cmdline/apt-get.cc: - use unsigned long long instead of double to store values it gets --- cmdline/apt-get.cc | 12 ++++++------ debian/changelog | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 44235e35..661ca614 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -837,9 +837,9 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, return false; // Display statistics - double FetchBytes = Fetcher.FetchNeeded(); - double FetchPBytes = Fetcher.PartialPresent(); - double DebBytes = Fetcher.TotalNeeded(); + unsigned long long FetchBytes = Fetcher.FetchNeeded(); + unsigned long long FetchPBytes = Fetcher.PartialPresent(); + unsigned long long DebBytes = Fetcher.TotalNeeded(); if (DebBytes != Cache->DebSize()) { c0out << DebBytes << ',' << Cache->DebSize() << endl; @@ -2362,9 +2362,9 @@ bool DoSource(CommandLine &CmdL) } // Display statistics - double FetchBytes = Fetcher.FetchNeeded(); - double FetchPBytes = Fetcher.PartialPresent(); - double DebBytes = Fetcher.TotalNeeded(); + unsigned long long FetchBytes = Fetcher.FetchNeeded(); + unsigned long long FetchPBytes = Fetcher.PartialPresent(); + unsigned long long DebBytes = Fetcher.TotalNeeded(); // Check for enough free space struct statvfs Buf; diff --git a/debian/changelog b/debian/changelog index 97d6abe8..cad4bf99 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,8 +8,10 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - deprecate AddSize with Multiplier as it is unused and switch to boolean instead to handle the sizes more gracefully. - switch i{Download,Usr}Size from double to (un)signed long long + * cmdline/apt-get.cc: + - use unsigned long long instead of double to store values it gets - -- David Kalnischkies Thu, 03 Jun 2010 09:19:01 +0200 + -- David Kalnischkies Thu, 03 Jun 2010 10:46:46 +0200 apt (0.7.26~exp5) experimental; urgency=low -- cgit v1.2.3 From 2e5f4e45f593535e2c88181ff7a9e2d32a5e60f9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 4 Jun 2010 14:43:03 +0200 Subject: * apt-pkg/cachefile.{cc,h}: - split Open() into submethods to be able to build only parts - make the OpProgress optional in the Cache buildprocess --- apt-pkg/cachefile.cc | 50 ++++++++++++++++++++++++++++++++------------- apt-pkg/cachefile.h | 15 ++++++++------ apt-pkg/deb/debindexfile.cc | 18 ++++++++-------- apt-pkg/deb/debindexfile.h | 6 +++--- apt-pkg/indexfile.h | 8 ++++++-- apt-pkg/pkgcachegen.cc | 45 +++++++++++++++++++++++++--------------- apt-pkg/pkgcachegen.h | 10 +++++++-- debian/changelog | 3 +++ 8 files changed, 103 insertions(+), 52 deletions(-) diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc index 790312dc..b0f8bc42 100644 --- a/apt-pkg/cachefile.cc +++ b/apt-pkg/cachefile.cc @@ -46,7 +46,7 @@ pkgCacheFile::~pkgCacheFile() // CacheFile::BuildCaches - Open and build the cache files /*{{{*/ // --------------------------------------------------------------------- /* */ -bool pkgCacheFile::BuildCaches(OpProgress &Progress,bool WithLock) +bool pkgCacheFile::BuildCaches(OpProgress *Progress, bool WithLock) { const bool ErrorWasEmpty = _error->empty(); if (WithLock == true) @@ -65,8 +65,9 @@ bool pkgCacheFile::BuildCaches(OpProgress &Progress,bool WithLock) return _error->Error(_("The list of sources could not be read.")); // Read the caches - bool Res = pkgMakeStatusCache(List,Progress,&Map,!WithLock); - Progress.Done(); + bool Res = pkgCacheGenerator::MakeStatusCache(List,Progress,&Map,!WithLock); + if (Progress != NULL) + Progress->Done(); if (Res == false) return _error->Error(_("The package lists or status file could not be parsed or opened.")); @@ -80,29 +81,50 @@ bool pkgCacheFile::BuildCaches(OpProgress &Progress,bool WithLock) return true; } /*}}}*/ -// CacheFile::Open - Open the cache files, creating if necessary /*{{{*/ +// CacheFile::BuildPolicy - Open and build all relevant preferences /*{{{*/ // --------------------------------------------------------------------- /* */ -bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock) +bool pkgCacheFile::BuildPolicy(OpProgress *Progress) { - if (BuildCaches(Progress,WithLock) == false) - return false; - - // The policy engine Policy = new pkgPolicy(Cache); if (_error->PendingError() == true) return false; if (ReadPinFile(*Policy) == false || ReadPinDir(*Policy) == false) return false; - - // Create the dependency cache + + return true; +} + /*}}}*/ +// CacheFile::BuildDepCache - Open and build the dependency cache /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool pkgCacheFile::BuildDepCache(OpProgress *Progress) +{ DCache = new pkgDepCache(Cache,Policy); if (_error->PendingError() == true) return false; - - DCache->Init(&Progress); - Progress.Done(); + + DCache->Init(Progress); + return true; +} + /*}}}*/ +// CacheFile::Open - Open the cache files, creating if necessary /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool pkgCacheFile::Open(OpProgress *Progress, bool WithLock) +{ + if (BuildCaches(Progress,WithLock) == false) + return false; + + if (BuildPolicy(Progress) == false) + return false; + + if (BuildDepCache(Progress) == false) + return false; + + if (Progress != NULL) + Progress->Done(); if (_error->PendingError() == true) return false; diff --git a/apt-pkg/cachefile.h b/apt-pkg/cachefile.h index 3b057951..b75a7dbe 100644 --- a/apt-pkg/cachefile.h +++ b/apt-pkg/cachefile.h @@ -30,11 +30,10 @@ class pkgCacheFile MMap *Map; pkgCache *Cache; pkgDepCache *DCache; - + pkgPolicy *Policy; + public: - pkgPolicy *Policy; - // We look pretty much exactly like a pointer to a dep cache inline operator pkgCache &() {return *Cache;}; inline operator pkgCache *() {return Cache;}; @@ -45,12 +44,16 @@ class pkgCacheFile inline pkgDepCache::StateCache &operator [](pkgCache::PkgIterator const &I) {return (*DCache)[I];}; inline unsigned char &operator [](pkgCache::DepIterator const &I) {return (*DCache)[I];}; - bool BuildCaches(OpProgress &Progress,bool WithLock = true); - bool Open(OpProgress &Progress,bool WithLock = true); + bool BuildCaches(OpProgress *Progress = NULL,bool WithLock = true); + __deprecated bool BuildCaches(OpProgress &Progress,bool const &WithLock = true) { return BuildCaches(&Progress, WithLock); }; + bool BuildPolicy(OpProgress *Progress = NULL); + bool BuildDepCache(OpProgress *Progress = NULL); + bool Open(OpProgress *Progress = NULL, bool WithLock = true); + __deprecated bool Open(OpProgress &Progress,bool const &WithLock = true) { return Open(&Progress, WithLock); }; void Close(); pkgCacheFile(); - ~pkgCacheFile(); + virtual ~pkgCacheFile(); }; #endif diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index b89429d8..6d9e9949 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -262,15 +262,15 @@ unsigned long debPackagesIndex::Size() const // PackagesIndex::Merge - Load the index file into a cache /*{{{*/ // --------------------------------------------------------------------- /* */ -bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const +bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const { string PackageFile = IndexFile("Packages"); FileFd Pkg(PackageFile,FileFd::ReadOnly); debListParser Parser(&Pkg, Architecture); if (_error->PendingError() == true) return _error->Error("Problem opening %s",PackageFile.c_str()); - - Prog.SubProgress(0,Info("Packages")); + if (Prog != NULL) + Prog->SubProgress(0,Info("Packages")); ::URI Tmp(URI); if (Gen.SelectFile(PackageFile,Tmp.Host,*this) == false) return _error->Error("Problem with SelectFile %s",PackageFile.c_str()); @@ -445,7 +445,7 @@ unsigned long debTranslationsIndex::Size() const // TranslationsIndex::Merge - Load the index file into a cache /*{{{*/ // --------------------------------------------------------------------- /* */ -bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const +bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const { // Check the translation file, if in use string TranslationFile = IndexFile(Language); @@ -456,7 +456,8 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const if (_error->PendingError() == true) return false; - Prog.SubProgress(0, Info(TranslationFile.c_str())); + if (Prog != NULL) + Prog->SubProgress(0, Info(TranslationFile.c_str())); if (Gen.SelectFile(TranslationFile,string(),*this) == false) return _error->Error("Problem with SelectFile %s",TranslationFile.c_str()); @@ -529,7 +530,7 @@ unsigned long debStatusIndex::Size() const // StatusIndex::Merge - Load the index file into a cache /*{{{*/ // --------------------------------------------------------------------- /* */ -bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const +bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const { FileFd Pkg(File,FileFd::ReadOnly); if (_error->PendingError() == true) @@ -537,8 +538,9 @@ bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const debListParser Parser(&Pkg); if (_error->PendingError() == true) return false; - - Prog.SubProgress(0,File); + + if (Prog != NULL) + Prog->SubProgress(0,File); if (Gen.SelectFile(File,string(),*this,pkgCache::Flag::NotSource) == false) return _error->Error("Problem with SelectFile %s",File.c_str()); diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h index 766e8b21..b5085992 100644 --- a/apt-pkg/deb/debindexfile.h +++ b/apt-pkg/deb/debindexfile.h @@ -35,7 +35,7 @@ class debStatusIndex : public pkgIndexFile virtual bool Exists() const; virtual bool HasPackages() const {return true;}; virtual unsigned long Size() const; - virtual bool Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const; + virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const; virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const; debStatusIndex(string File); @@ -67,7 +67,7 @@ class debPackagesIndex : public pkgIndexFile virtual bool Exists() const; virtual bool HasPackages() const {return true;}; virtual unsigned long Size() const; - virtual bool Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const; + virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const; virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const; debPackagesIndex(string const &URI, string const &Dist, string const &Section, @@ -99,7 +99,7 @@ class debTranslationsIndex : public pkgIndexFile virtual bool Exists() const; virtual bool HasPackages() const; virtual unsigned long Size() const; - virtual bool Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const; + virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const; virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const; debTranslationsIndex(string URI,string Dist,string Section, char const * const Language); diff --git a/apt-pkg/indexfile.h b/apt-pkg/indexfile.h index 3cc50162..2b5ae634 100644 --- a/apt-pkg/indexfile.h +++ b/apt-pkg/indexfile.h @@ -74,8 +74,12 @@ class pkgIndexFile virtual bool Exists() const = 0; virtual bool HasPackages() const = 0; virtual unsigned long Size() const = 0; - virtual bool Merge(pkgCacheGenerator &/*Gen*/,OpProgress &/*Prog*/) const {return false;}; - virtual bool MergeFileProvides(pkgCacheGenerator &/*Gen*/,OpProgress &/*Prog*/) const {return true;}; + virtual bool Merge(pkgCacheGenerator &/*Gen*/,OpProgress* /*Prog*/) const { return false; }; + __deprecated virtual bool Merge(pkgCacheGenerator &Gen, OpProgress &Prog) const + { return Merge(Gen, &Prog); }; + virtual bool MergeFileProvides(pkgCacheGenerator &/*Gen*/,OpProgress* /*Prog*/) const {return true;}; + __deprecated virtual bool MergeFileProvides(pkgCacheGenerator &Gen, OpProgress &Prog) const + {return MergeFileProvides(Gen, &Prog);}; virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const; static bool TranslationsAvailable(); diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index d96d3370..5649cd6f 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -526,7 +526,7 @@ map_ptrloc pkgCacheGenerator::NewDescription(pkgCache::DescIterator &Desc, // CacheGenerator::FinishCache - do various finish operations /*{{{*/ // --------------------------------------------------------------------- /* This prepares the Cache for delivery */ -bool pkgCacheGenerator::FinishCache(OpProgress &Progress) +bool pkgCacheGenerator::FinishCache(OpProgress *Progress) { // FIXME: add progress reporting for this operation // Do we have different architectures in your groups ? @@ -923,7 +923,7 @@ static unsigned long ComputeSize(FileIterator Start,FileIterator End) // --------------------------------------------------------------------- /* */ static bool BuildCache(pkgCacheGenerator &Gen, - OpProgress &Progress, + OpProgress *Progress, unsigned long &CurrentSize,unsigned long TotalSize, FileIterator Start, FileIterator End) { @@ -944,7 +944,8 @@ static bool BuildCache(pkgCacheGenerator &Gen, } unsigned long Size = (*I)->Size(); - Progress.OverallProgress(CurrentSize,TotalSize,Size,_("Reading package lists")); + if (Progress != NULL) + Progress->OverallProgress(CurrentSize,TotalSize,Size,_("Reading package lists")); CurrentSize += Size; if ((*I)->Merge(Gen,Progress) == false) @@ -953,13 +954,15 @@ static bool BuildCache(pkgCacheGenerator &Gen, if (Gen.HasFileDeps() == true) { - Progress.Done(); + if (Progress != NULL) + Progress->Done(); TotalSize = ComputeSize(Start, End); CurrentSize = 0; for (I = Start; I != End; I++) { unsigned long Size = (*I)->Size(); - Progress.OverallProgress(CurrentSize,TotalSize,Size,_("Collecting File Provides")); + if (Progress != NULL) + Progress->OverallProgress(CurrentSize,TotalSize,Size,_("Collecting File Provides")); CurrentSize += Size; if ((*I)->MergeFileProvides(Gen,Progress) == false) return false; @@ -969,7 +972,7 @@ static bool BuildCache(pkgCacheGenerator &Gen, return true; } /*}}}*/ -// MakeStatusCache - Construct the status cache /*{{{*/ +// CacheGenerator::MakeStatusCache - Construct the status cache /*{{{*/ // --------------------------------------------------------------------- /* This makes sure that the status cache (the cache that has all index files from the sources list and all local ones) is ready @@ -977,7 +980,10 @@ static bool BuildCache(pkgCacheGenerator &Gen, the cache will be stored there. This is pretty much mandetory if you are using AllowMem. AllowMem lets the function be run as non-root where it builds the cache 'fast' into a memory buffer. */ -bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, +__deprecated bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, + MMap **OutMap, bool AllowMem) + { return pkgCacheGenerator::MakeStatusCache(List, &Progress, OutMap, AllowMem); } +bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress, MMap **OutMap,bool AllowMem) { bool const Debug = _config->FindB("Debug::pkgCacheGen", false); @@ -1028,13 +1034,15 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, if (Writeable == false && AllowMem == false && CacheFile.empty() == false) return _error->Error(_("Unable to write to %s"),flNotFile(CacheFile).c_str()); - - Progress.OverallProgress(0,1,1,_("Reading package lists")); - + + if (Progress != NULL) + Progress->OverallProgress(0,1,1,_("Reading package lists")); + // Cache is OK, Fin. if (CheckValidity(CacheFile,Files.begin(),Files.end(),OutMap) == true) { - Progress.OverallProgress(1,1,1,_("Reading package lists")); + if (Progress != NULL) + Progress->OverallProgress(1,1,1,_("Reading package lists")); if (Debug == true) std::clog << "pkgcache.bin is valid - no need to build anything" << std::endl; return true; @@ -1084,7 +1092,7 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, TotalSize = ComputeSize(Files.begin()+EndOfSource,Files.end()); // Build the status cache - pkgCacheGenerator Gen(Map.Get(),&Progress); + pkgCacheGenerator Gen(Map.Get(),Progress); if (_error->PendingError() == true) return false; if (BuildCache(Gen,Progress,CurrentSize,TotalSize, @@ -1101,7 +1109,7 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, TotalSize = ComputeSize(Files.begin(),Files.end()); // Build the source cache - pkgCacheGenerator Gen(Map.Get(),&Progress); + pkgCacheGenerator Gen(Map.Get(),Progress); if (_error->PendingError() == true) return false; if (BuildCache(Gen,Progress,CurrentSize,TotalSize, @@ -1160,10 +1168,12 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, return true; } /*}}}*/ -// MakeOnlyStatusCache - Build a cache with just the status files /*{{{*/ +// CacheGenerator::MakeOnlyStatusCache - Build only a status files cache/*{{{*/ // --------------------------------------------------------------------- /* */ -bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap) +__deprecated bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap) + { return pkgCacheGenerator::MakeOnlyStatusCache(&Progress, OutMap); } +bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap) { unsigned long MapSize = _config->FindI("APT::Cache-Limit",20*1024*1024); vector Files; @@ -1178,8 +1188,9 @@ bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap) TotalSize = ComputeSize(Files.begin()+EndOfSource,Files.end()); // Build the status cache - Progress.OverallProgress(0,1,1,_("Reading package lists")); - pkgCacheGenerator Gen(Map.Get(),&Progress); + if (Progress != NULL) + Progress->OverallProgress(0,1,1,_("Reading package lists")); + pkgCacheGenerator Gen(Map.Get(),Progress); if (_error->PendingError() == true) return false; if (BuildCache(Gen,Progress,CurrentSize,TotalSize, diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h index 46d0cd89..ff0941e0 100644 --- a/apt-pkg/pkgcachegen.h +++ b/apt-pkg/pkgcachegen.h @@ -76,7 +76,11 @@ class pkgCacheGenerator /*{{{*/ bool HasFileDeps() {return FoundFileDeps;}; bool MergeFileProvides(ListParser &List); - bool FinishCache(OpProgress &Progress); + bool FinishCache(OpProgress *Progress); + + static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress, + MMap **OutMap = 0,bool AllowMem = false); + static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap); pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress); ~pkgCacheGenerator(); @@ -134,10 +138,12 @@ class pkgCacheGenerator::ListParser virtual ~ListParser() {}; }; /*}}}*/ + bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, MMap **OutMap = 0,bool AllowMem = false); bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap); + #ifdef APT_COMPATIBILITY #if APT_COMPATIBILITY != 986 #warning "Using APT_COMPATIBILITY" @@ -145,7 +151,7 @@ bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap); MMap *pkgMakeStatusCacheMem(pkgSourceList &List,OpProgress &Progress) { MMap *Map = 0; - if (pkgMakeStatusCache(List,Progress,&Map,true) == false) + if (pkgCacheGenerator::MakeStatusCache(List,&Progress,&Map,true) == false) return 0; return Map; } diff --git a/debian/changelog b/debian/changelog index 994be2bb..097916d1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -32,6 +32,9 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - get the best matching arch package from a group with FindPreferredPkg * cmdline/apt-cache.cc: - make the search multiarch compatible by using GrpIterator instead + * apt-pkg/cachefile.{cc,h}: + - split Open() into submethods to be able to build only parts + - make the OpProgress optional in the Cache buildprocess -- David Kalnischkies Mon, 31 May 2010 22:36:35 +0200 -- cgit v1.2.3 From ea4b220b1b17b270fc1a05e454439c32589548b7 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 4 Jun 2010 14:51:21 +0200 Subject: Switch away from the now deprecated methods for Cache building --- apt-inst/deb/dpkgdb.cc | 2 +- cmdline/apt-extracttemplates.cc | 3 +-- cmdline/apt-get.cc | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apt-inst/deb/dpkgdb.cc b/apt-inst/deb/dpkgdb.cc index e51e4f8b..a75cf59c 100644 --- a/apt-inst/deb/dpkgdb.cc +++ b/apt-inst/deb/dpkgdb.cc @@ -142,7 +142,7 @@ bool debDpkgDB::ReadyPkgCache(OpProgress &Progress) CacheMap = 0; } - if (pkgMakeOnlyStatusCache(Progress,&CacheMap) == false) + if (pkgCacheGenerator::MakeOnlyStatusCache(&Progress,&CacheMap) == false) return false; Cache->DropProgress(); diff --git a/cmdline/apt-extracttemplates.cc b/cmdline/apt-extracttemplates.cc index 21ef1a05..07bc0c25 100644 --- a/cmdline/apt-extracttemplates.cc +++ b/cmdline/apt-extracttemplates.cc @@ -296,8 +296,7 @@ bool Go(CommandLine &CmdL) MMap *Map = 0; pkgSourceList List; List.ReadMainList(); - OpProgress Prog; - pkgMakeStatusCache(List,Prog,&Map,true); + pkgCacheGenerator::MakeStatusCache(List,NULL,&Map,true); if (Map == 0) return false; DebFile::Cache = new pkgCache(Map); diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 9894747f..c70dd56a 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -91,14 +91,14 @@ class CacheFile : public pkgCacheFile bool BuildCaches(bool WithLock = true) { OpTextProgress Prog(*_config); - if (pkgCacheFile::BuildCaches(Prog,WithLock) == false) + if (pkgCacheFile::BuildCaches(&Prog,WithLock) == false) return false; return true; } bool Open(bool WithLock = true) { OpTextProgress Prog(*_config); - if (pkgCacheFile::Open(Prog,WithLock) == false) + if (pkgCacheFile::Open(&Prog,WithLock) == false) return false; Sort(); -- cgit v1.2.3 From 3f8621c5effb167a51944b86334867e2fe8fedb3 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 4 Jun 2010 22:58:57 +0200 Subject: store also the SourceList we use internally for export --- apt-pkg/cachefile.cc | 58 +++++++++++++++++++++++++++++++++++++++++----------- apt-pkg/cachefile.h | 15 +++++++++++++- debian/changelog | 1 + 3 files changed, 61 insertions(+), 13 deletions(-) diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc index b0f8bc42..01598386 100644 --- a/apt-pkg/cachefile.cc +++ b/apt-pkg/cachefile.cc @@ -27,7 +27,8 @@ // CacheFile::CacheFile - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -pkgCacheFile::pkgCacheFile() : Map(0), Cache(0), DCache(0), Policy(0) +pkgCacheFile::pkgCacheFile() : Map(NULL), Cache(NULL), DCache(NULL), + Policy(NULL), SrcList(NULL) { } /*}}}*/ @@ -38,16 +39,30 @@ pkgCacheFile::~pkgCacheFile() { delete DCache; delete Policy; + delete SrcList; delete Cache; delete Map; _system->UnLock(true); -} +} /*}}}*/ // CacheFile::BuildCaches - Open and build the cache files /*{{{*/ // --------------------------------------------------------------------- /* */ bool pkgCacheFile::BuildCaches(OpProgress *Progress, bool WithLock) { + if (Cache != NULL) + return true; + + if (_config->FindB("pkgCacheFile::Generate", true) == false) + { + Map = new MMap(*new FileFd(_config->FindFile("Dir::Cache::pkgcache"), + FileFd::ReadOnly),MMap::Public|MMap::ReadOnly); + Cache = new pkgCache(Map); + if (_error->PendingError() == true) + return false; + return true; + } + const bool ErrorWasEmpty = _error->empty(); if (WithLock == true) if (_system->Lock() == false) @@ -58,14 +73,11 @@ bool pkgCacheFile::BuildCaches(OpProgress *Progress, bool WithLock) if (_error->PendingError() == true) return false; - - // Read the source list - pkgSourceList List; - if (List.ReadMainList() == false) - return _error->Error(_("The list of sources could not be read.")); + + BuildSourceList(Progress); // Read the caches - bool Res = pkgCacheGenerator::MakeStatusCache(List,Progress,&Map,!WithLock); + bool Res = pkgCacheGenerator::MakeStatusCache(*SrcList,Progress,&Map,!WithLock); if (Progress != NULL) Progress->Done(); if (Res == false) @@ -81,11 +93,28 @@ bool pkgCacheFile::BuildCaches(OpProgress *Progress, bool WithLock) return true; } /*}}}*/ +// CacheFile::BuildSourceList - Open and build all relevant sources.list/*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool pkgCacheFile::BuildSourceList(OpProgress *Progress) +{ + if (SrcList != NULL) + return true; + + SrcList = new pkgSourceList(); + if (SrcList->ReadMainList() == false) + return _error->Error(_("The list of sources could not be read.")); + return true; +} + /*}}}*/ // CacheFile::BuildPolicy - Open and build all relevant preferences /*{{{*/ // --------------------------------------------------------------------- /* */ bool pkgCacheFile::BuildPolicy(OpProgress *Progress) { + if (Policy != NULL) + return true; + Policy = new pkgPolicy(Cache); if (_error->PendingError() == true) return false; @@ -101,6 +130,9 @@ bool pkgCacheFile::BuildPolicy(OpProgress *Progress) /* */ bool pkgCacheFile::BuildDepCache(OpProgress *Progress) { + if (DCache != NULL) + return true; + DCache = new pkgDepCache(Cache,Policy); if (_error->PendingError() == true) return false; @@ -139,12 +171,14 @@ void pkgCacheFile::Close() delete DCache; delete Policy; delete Cache; + delete SrcList; delete Map; _system->UnLock(true); - Map = 0; - DCache = 0; - Policy = 0; - Cache = 0; + Map = NULL; + DCache = NULL; + Policy = NULL; + Cache = NULL; + SrcList = NULL; } /*}}}*/ diff --git a/apt-pkg/cachefile.h b/apt-pkg/cachefile.h index b75a7dbe..1647aff8 100644 --- a/apt-pkg/cachefile.h +++ b/apt-pkg/cachefile.h @@ -23,6 +23,7 @@ #include class pkgPolicy; +class pkgSourceList; class pkgCacheFile { protected: @@ -31,6 +32,7 @@ class pkgCacheFile pkgCache *Cache; pkgDepCache *DCache; pkgPolicy *Policy; + pkgSourceList *SrcList; public: @@ -39,6 +41,10 @@ class pkgCacheFile inline operator pkgCache *() {return Cache;}; inline operator pkgDepCache &() {return *DCache;}; inline operator pkgDepCache *() {return DCache;}; + inline operator pkgPolicy &() {return *Policy;}; + inline operator pkgPolicy *() {return Policy;}; + inline operator pkgSourceList &() {return *SrcList;}; + inline operator pkgSourceList *() {return SrcList;}; inline pkgDepCache *operator ->() {return DCache;}; inline pkgDepCache &operator *() {return *DCache;}; inline pkgDepCache::StateCache &operator [](pkgCache::PkgIterator const &I) {return (*DCache)[I];}; @@ -46,12 +52,19 @@ class pkgCacheFile bool BuildCaches(OpProgress *Progress = NULL,bool WithLock = true); __deprecated bool BuildCaches(OpProgress &Progress,bool const &WithLock = true) { return BuildCaches(&Progress, WithLock); }; + bool BuildSourceList(OpProgress *Progress = NULL); bool BuildPolicy(OpProgress *Progress = NULL); bool BuildDepCache(OpProgress *Progress = NULL); bool Open(OpProgress *Progress = NULL, bool WithLock = true); + inline bool ReadOnlyOpen(OpProgress *Progress = NULL) { return Open(Progress, false); }; __deprecated bool Open(OpProgress &Progress,bool const &WithLock = true) { return Open(&Progress, WithLock); }; void Close(); - + + inline pkgCache* GetPkgCache() { BuildCaches(NULL, false); return Cache; }; + inline pkgDepCache* GetDepCache() { BuildDepCache(); return DCache; }; + inline pkgPolicy* GetPolicy() { BuildPolicy(); return Policy; }; + inline pkgSourceList* GetSourceList() { BuildSourceList(); return SrcList; }; + pkgCacheFile(); virtual ~pkgCacheFile(); }; diff --git a/debian/changelog b/debian/changelog index 097916d1..9001e91a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -35,6 +35,7 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low * apt-pkg/cachefile.{cc,h}: - split Open() into submethods to be able to build only parts - make the OpProgress optional in the Cache buildprocess + - store also the SourceList we use internally for export -- David Kalnischkies Mon, 31 May 2010 22:36:35 +0200 -- cgit v1.2.3 From 856d3b06a6eb6a7f455294c69fc13604e099fd56 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 09:20:29 +0200 Subject: Add a method to get a VersionSet from the Commandline and refactor the existing methods a bit to reuse them easier intern --- apt-pkg/cacheset.cc | 140 +++++++++++++++++++++++++++++++++++++++++++++------- apt-pkg/cacheset.h | 74 +++++++++++++++++++++++++-- 2 files changed, 191 insertions(+), 23 deletions(-) diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc index b49b3653..7372c909 100644 --- a/apt-pkg/cacheset.cc +++ b/apt-pkg/cacheset.cc @@ -13,6 +13,7 @@ #include #include #include +#include #include @@ -22,7 +23,7 @@ /*}}}*/ namespace APT { // FromRegEx - Return all packages in the cache matching a pattern /*{{{*/ -PackageSet PackageSet::FromRegEx(pkgCache &Cache, std::string pattern, std::ostream &out) { +PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, std::ostream &out) { PackageSet pkgset; std::string arch = "native"; static const char * const isregex = ".?+*|[^$"; @@ -48,7 +49,7 @@ PackageSet PackageSet::FromRegEx(pkgCache &Cache, std::string pattern, std::ostr return pkgset; } - for (pkgCache::GrpIterator Grp = Cache.GrpBegin(); Grp.end() == false; ++Grp) + for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) { if (regexec(&Pattern, Grp.Name(), 0, 0, 0) != 0) continue; @@ -76,28 +77,129 @@ PackageSet PackageSet::FromRegEx(pkgCache &Cache, std::string pattern, std::ostr } /*}}}*/ // FromCommandLine - Return all packages specified on commandline /*{{{*/ -PackageSet PackageSet::FromCommandLine(pkgCache &Cache, const char **cmdline, std::ostream &out) { +PackageSet PackageSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline, std::ostream &out) { PackageSet pkgset; for (const char **I = cmdline + 1; *I != 0; I++) { - pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); - if (Pkg.end() == true) { - std::vector archs = APT::Configuration::getArchitectures(); - for (std::vector::const_iterator a = archs.begin(); - a != archs.end() || Pkg.end() != true; ++a) { - Pkg = Cache.FindPkg(*I, *a); - } - if (Pkg.end() == true) { - PackageSet regex = FromRegEx(Cache, *I, out); - if (regex.empty() == true) - _error->Warning(_("Unable to locate package %s"),*I); - else - pkgset.insert(regex.begin(), regex.end()); - continue; + PackageSet pset = FromString(Cache, *I, out); + pkgset.insert(pset.begin(), pset.end()); + } + return pkgset; +} + /*}}}*/ +// FromString - Return all packages matching a specific string /*{{{*/ +PackageSet PackageSet::FromString(pkgCacheFile &Cache, const char * const str, std::ostream &out) { + pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(str); + if (Grp.end() == false) { + pkgCache::PkgIterator Pkg = Grp.FindPreferredPkg(); + PackageSet pkgset; + pkgset.insert(Pkg); + return pkgset; + } + PackageSet regex = FromRegEx(Cache, str, out); + if (regex.empty() == true) + _error->Warning(_("Unable to locate package %s"), str); + return regex; +} + /*}}}*/ +// FromCommandLine - Return all versions specified on commandline /*{{{*/ +APT::VersionSet VersionSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline, + APT::VersionSet::Version const &fallback, std::ostream &out) { + VersionSet verset; + for (const char **I = cmdline + 1; *I != 0; I++) { + std::string pkg = *I; + 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 = PackageSet::FromString(Cache, pkg.c_str(), out); + for (PackageSet::const_iterator P = pkgset.begin(); + P != pkgset.end(); ++P) { + if (vertag != string::npos) { + pkgVersionMatch Match(ver, (verIsRel == true ? pkgVersionMatch::Release : + pkgVersionMatch::Version)); + pkgCache::VerIterator 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 (strcmp(ver.c_str(), V.VerStr()) != 0) + ioprintf(out, _("Selected version %s (%s) for %s\n"), + V.VerStr(), V.RelStr().c_str(), P.FullName(true).c_str()); + verset.insert(V); + } else { + pkgCache::VerIterator V; + switch(fallback) { + case VersionSet::ALL: + for (V = P.VersionList(); V.end() != true; ++V) + verset.insert(V); + break; + case VersionSet::CANDANDINST: + verset.insert(getInstalledVer(Cache, P)); + verset.insert(getCandidateVer(Cache, P)); + break; + case VersionSet::CANDIDATE: + verset.insert(getCandidateVer(Cache, P)); + break; + case VersionSet::INSTALLED: + verset.insert(getInstalledVer(Cache, P)); + break; + case VersionSet::CANDINST: + V = getCandidateVer(Cache, P, true); + if (V.end() == true) + V = getInstalledVer(Cache, P, true); + if (V.end() == false) + verset.insert(V); + else + _error->Error(_("Can't select installed nor candidate version from package %s as it has neither of them"), P.FullName(true).c_str()); + break; + case VersionSet::INSTCAND: + V = getInstalledVer(Cache, P, true); + if (V.end() == true) + V = getCandidateVer(Cache, P, true); + if (V.end() == false) + verset.insert(V); + else + _error->Error(_("Can't select installed nor candidate version from package %s as it has neither of them"), P.FullName(true).c_str()); + break; + case VersionSet::NEWEST: + if (P->VersionList != 0) + verset.insert(P.VersionList()); + else + _error->Error(_("Can't select newest version from package %s as it is purely virtual"), P.FullName(true).c_str()); + break; + } } } - pkgset.insert(Pkg); } - return pkgset; + return verset; +} + /*}}}*/ +// getCandidateVer - Returns the candidate version of the given package /*{{{*/ +pkgCache::VerIterator VersionSet::getCandidateVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg, bool const &AllowError) { + if (unlikely(Cache.BuildDepCache() == false)) + return pkgCache::VerIterator(*Cache); + pkgCache::VerIterator Cand = Cache[Pkg].InstVerIter(Cache); + if (AllowError == false && Cand.end() == true) + _error->Error(_("Can't select candidate version from package %s as it has no candidate"), Pkg.FullName(true).c_str()); + return Cand; +} + /*}}}*/ +// getInstalledVer - Returns the installed version of the given package /*{{{*/ +pkgCache::VerIterator VersionSet::getInstalledVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg, bool const &AllowError) { + if (AllowError == false && Pkg->CurrentVer == 0) + _error->Error(_("Can't select installed version from package %s as it is not installed"), Pkg.FullName(true).c_str()); + return Pkg.CurrentVer(); } /*}}}*/ } diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index f0131bfe..708531b4 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -14,6 +14,7 @@ #include #include +#include #include /*}}}*/ namespace APT { @@ -68,12 +69,23 @@ public: /*{{{*/ \param Cache the packages are in \param pattern regular expression for package names \param out stream to print the notice to */ - static APT::PackageSet FromRegEx(pkgCache &Cache, std::string pattern, std::ostream &out); - static APT::PackageSet FromRegEx(pkgCache &Cache, std::string const &pattern) { + static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string pattern, std::ostream &out); + static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string const &pattern) { std::ostream out (std::ofstream("/dev/null").rdbuf()); return APT::PackageSet::FromRegEx(Cache, pattern, out); } + /** \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 out stream to print various notices to */ + static APT::PackageSet FromString(pkgCacheFile &Cache, const char * const string, std::ostream &out); + static APT::PackageSet FromString(pkgCacheFile &Cache, const char * const string) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::PackageSet::FromString(Cache, string, out); + } + /** \brief returns all packages specified on the commandline Get all package names from the commandline and executes regex's if needed. @@ -81,8 +93,8 @@ public: /*{{{*/ \param Cache the packages are in \param cmdline Command line the package names should be extracted from \param out stream to print various notices to */ - static APT::PackageSet FromCommandLine(pkgCache &Cache, const char **cmdline, std::ostream &out); - static APT::PackageSet FromCommandLine(pkgCache &Cache, const char **cmdline) { + static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, std::ostream &out); + static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { std::ostream out (std::ofstream("/dev/null").rdbuf()); return APT::PackageSet::FromCommandLine(Cache, cmdline, out); } @@ -133,6 +145,60 @@ public: /*{{{*/ // 103. set::iterator is required to be modifiable, but this allows modification of keys typedef typename APT::VersionSet::const_iterator iterator; + /** \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 out stream to print various notices to */ + static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, + APT::VersionSet::Version const &fallback, std::ostream &out); + static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, + APT::VersionSet::Version const &fallback) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::VersionSet::FromCommandLine(Cache, cmdline, fallback, out); + } + static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { + return APT::VersionSet::FromCommandLine(Cache, cmdline, CANDINST); + } + /*}}}*/ +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 + \param AllowError add an error to the stack if not */ + static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg, bool const &AllowError = false); + + /** \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 + \param AllowError add an error to the stack if not */ + static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg, bool const &AllowError = false); + /*}}}*/ }; /*}}}*/ } -- cgit v1.2.3 From d9eb210edda5515ca467eb234dd58b60d43c4513 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 10:04:48 +0200 Subject: use pkgCacheFile and the new CacheSets all over the place --- cmdline/apt-cache.cc | 399 +++++++++++++++++++++++++-------------------------- debian/changelog | 1 + 2 files changed, 195 insertions(+), 205 deletions(-) diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 891b1087..227fda4b 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -46,9 +46,6 @@ using namespace std; -pkgCache *GCache = 0; -pkgSourceList *SrcList = 0; - // LocalitySort - Sort a version list by package file locality /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -86,10 +83,13 @@ void LocalitySort(pkgCache::DescFile **begin, /* */ bool UnMet(CommandLine &CmdL) { - pkgCache &Cache = *GCache; - bool Important = _config->FindB("APT::Cache::Important",false); - - for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) + bool const Important = _config->FindB("APT::Cache::Important",false); + + pkgCacheFile CacheFile; + if (unlikely(CacheFile.GetPkgCache() == NULL)) + return false; + + for (pkgCache::PkgIterator P = CacheFile.GetPkgCache()->PkgBegin(); P.end() == false; P++) { for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++) { @@ -174,9 +174,9 @@ bool UnMet(CommandLine &CmdL) // --------------------------------------------------------------------- /* */ bool DumpPackage(CommandLine &CmdL) -{ - pkgCache &Cache = *GCache; - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); +{ + pkgCacheFile CacheFile; + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { @@ -239,18 +239,22 @@ bool DumpPackage(CommandLine &CmdL) /* */ bool Stats(CommandLine &Cmd) { - pkgCache &Cache = *GCache; - cout << _("Total package names: ") << Cache.Head().GroupCount << " (" << - SizeToStr(Cache.Head().GroupCount*Cache.Head().GroupSz) << ')' << endl - << _("Total package structures: ") << Cache.Head().PackageCount << " (" << - SizeToStr(Cache.Head().PackageCount*Cache.Head().PackageSz) << ')' << endl; + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == NULL)) + return false; + + cout << _("Total package names: ") << Cache->Head().GroupCount << " (" << + SizeToStr(Cache->Head().GroupCount*Cache->Head().GroupSz) << ')' << endl + << _("Total package structures: ") << Cache->Head().PackageCount << " (" << + SizeToStr(Cache->Head().PackageCount*Cache->Head().PackageSz) << ')' << endl; int Normal = 0; int Virtual = 0; int NVirt = 0; int DVirt = 0; int Missing = 0; - pkgCache::PkgIterator I = Cache.PkgBegin(); + pkgCache::PkgIterator I = Cache->PkgBegin(); for (;I.end() != true; I++) { if (I->VersionList != 0 && I->ProvidesList == 0) @@ -288,33 +292,33 @@ bool Stats(CommandLine &Cmd) cout << _(" Mixed virtual packages: ") << NVirt << endl; cout << _(" Missing: ") << Missing << endl; - cout << _("Total distinct versions: ") << Cache.Head().VersionCount << " (" << - SizeToStr(Cache.Head().VersionCount*Cache.Head().VersionSz) << ')' << endl; - cout << _("Total distinct descriptions: ") << Cache.Head().DescriptionCount << " (" << - SizeToStr(Cache.Head().DescriptionCount*Cache.Head().DescriptionSz) << ')' << endl; - cout << _("Total dependencies: ") << Cache.Head().DependsCount << " (" << - SizeToStr(Cache.Head().DependsCount*Cache.Head().DependencySz) << ')' << endl; + cout << _("Total distinct versions: ") << Cache->Head().VersionCount << " (" << + SizeToStr(Cache->Head().VersionCount*Cache->Head().VersionSz) << ')' << endl; + cout << _("Total distinct descriptions: ") << Cache->Head().DescriptionCount << " (" << + SizeToStr(Cache->Head().DescriptionCount*Cache->Head().DescriptionSz) << ')' << endl; + cout << _("Total dependencies: ") << Cache->Head().DependsCount << " (" << + SizeToStr(Cache->Head().DependsCount*Cache->Head().DependencySz) << ')' << endl; - cout << _("Total ver/file relations: ") << Cache.Head().VerFileCount << " (" << - SizeToStr(Cache.Head().VerFileCount*Cache.Head().VerFileSz) << ')' << endl; - cout << _("Total Desc/File relations: ") << Cache.Head().DescFileCount << " (" << - SizeToStr(Cache.Head().DescFileCount*Cache.Head().DescFileSz) << ')' << endl; - cout << _("Total Provides mappings: ") << Cache.Head().ProvidesCount << " (" << - SizeToStr(Cache.Head().ProvidesCount*Cache.Head().ProvidesSz) << ')' << endl; + cout << _("Total ver/file relations: ") << Cache->Head().VerFileCount << " (" << + SizeToStr(Cache->Head().VerFileCount*Cache->Head().VerFileSz) << ')' << endl; + cout << _("Total Desc/File relations: ") << Cache->Head().DescFileCount << " (" << + SizeToStr(Cache->Head().DescFileCount*Cache->Head().DescFileSz) << ')' << endl; + cout << _("Total Provides mappings: ") << Cache->Head().ProvidesCount << " (" << + SizeToStr(Cache->Head().ProvidesCount*Cache->Head().ProvidesSz) << ')' << endl; // String list stats unsigned long Size = 0; unsigned long Count = 0; - for (pkgCache::StringItem *I = Cache.StringItemP + Cache.Head().StringList; - I!= Cache.StringItemP; I = Cache.StringItemP + I->NextItem) + for (pkgCache::StringItem *I = Cache->StringItemP + Cache->Head().StringList; + I!= Cache->StringItemP; I = Cache->StringItemP + I->NextItem) { Count++; - Size += strlen(Cache.StrP + I->String) + 1; + Size += strlen(Cache->StrP + I->String) + 1; } cout << _("Total globbed strings: ") << Count << " (" << SizeToStr(Size) << ')' << endl; unsigned long DepVerSize = 0; - for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) + for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; P++) { for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++) { @@ -329,15 +333,15 @@ bool Stats(CommandLine &Cmd) unsigned long Slack = 0; for (int I = 0; I != 7; I++) - Slack += Cache.Head().Pools[I].ItemSize*Cache.Head().Pools[I].Count; + Slack += Cache->Head().Pools[I].ItemSize*Cache->Head().Pools[I].Count; cout << _("Total slack space: ") << SizeToStr(Slack) << endl; unsigned long Total = 0; - Total = Slack + Size + Cache.Head().DependsCount*Cache.Head().DependencySz + - Cache.Head().VersionCount*Cache.Head().VersionSz + - Cache.Head().PackageCount*Cache.Head().PackageSz + - Cache.Head().VerFileCount*Cache.Head().VerFileSz + - Cache.Head().ProvidesCount*Cache.Head().ProvidesSz; + Total = Slack + Size + Cache->Head().DependsCount*Cache->Head().DependencySz + + Cache->Head().VersionCount*Cache->Head().VersionSz + + Cache->Head().PackageCount*Cache->Head().PackageSz + + Cache->Head().VerFileCount*Cache->Head().VerFileSz + + Cache->Head().ProvidesCount*Cache->Head().ProvidesSz; cout << _("Total space accounted for: ") << SizeToStr(Total) << endl; return true; @@ -348,10 +352,14 @@ bool Stats(CommandLine &Cmd) /* This is worthless except fer debugging things */ bool Dump(CommandLine &Cmd) { - pkgCache &Cache = *GCache; - cout << "Using Versioning System: " << Cache.VS->Label << endl; + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == NULL)) + return false; + + cout << "Using Versioning System: " << Cache->VS->Label << endl; - for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) + for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; P++) { cout << "Package: " << P.FullName(true) << endl; for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++) @@ -370,7 +378,7 @@ bool Dump(CommandLine &Cmd) } } - for (pkgCache::PkgFileIterator F = Cache.FileBegin(); F.end() == false; F++) + for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F.end() == false; F++) { cout << "File: " << F.FileName() << endl; cout << " Type: " << F.IndexType() << endl; @@ -396,18 +404,17 @@ bool Dump(CommandLine &Cmd) make this run really fast, perhaps I went a little overboard.. */ bool DumpAvail(CommandLine &Cmd) { - pkgCache &Cache = *GCache; - - pkgPolicy Plcy(&Cache); - if (ReadPinFile(Plcy) == false || ReadPinDir(Plcy) == false) + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == NULL || CacheFile.BuildPolicy() == false)) return false; - - unsigned long Count = Cache.HeaderP->PackageCount+1; + + unsigned long Count = Cache->HeaderP->PackageCount+1; pkgCache::VerFile **VFList = new pkgCache::VerFile *[Count]; memset(VFList,0,sizeof(*VFList)*Count); // Map versions that we want to write out onto the VerList array. - for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) + for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; P++) { if (P->VersionList == 0) continue; @@ -415,7 +422,7 @@ bool DumpAvail(CommandLine &Cmd) /* Find the proper version to use. If the policy says there are no possible selections we return the installed version, if available.. This prevents dselect from making it obsolete. */ - pkgCache::VerIterator V = Plcy.GetCandidateVer(P); + pkgCache::VerIterator V = CacheFile.GetPolicy()->GetCandidateVer(P); if (V.end() == true) { if (P->CurrentVer == 0) @@ -460,10 +467,10 @@ bool DumpAvail(CommandLine &Cmd) LocalitySort(VFList,Count,sizeof(*VFList)); // Iterate over all the package files and write them out. - char *Buffer = new char[Cache.HeaderP->MaxVerFileSize+10]; + char *Buffer = new char[Cache->HeaderP->MaxVerFileSize+10]; for (pkgCache::VerFile **J = VFList; *J != 0;) { - pkgCache::PkgFileIterator File(Cache,(*J)->File + Cache.PkgFileP); + pkgCache::PkgFileIterator File(*Cache,(*J)->File + Cache->PkgFileP); if (File.IsOk() == false) { _error->Error(_("Package file %s is out of sync."),File.FileName()); @@ -482,7 +489,7 @@ bool DumpAvail(CommandLine &Cmd) unsigned long Pos = 0; for (; *J != 0; J++) { - if ((*J)->File + Cache.PkgFileP != File) + if ((*J)->File + Cache->PkgFileP != File) break; const pkgCache::VerFile &VF = **J; @@ -538,11 +545,15 @@ bool DumpAvail(CommandLine &Cmd) /* */ bool Depends(CommandLine &CmdL) { - pkgCache &Cache = *GCache; - SPtrArray Colours = new unsigned[Cache.Head().PackageCount]; - memset(Colours,0,sizeof(*Colours)*Cache.Head().PackageCount); + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == NULL)) + return false; - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + SPtrArray Colours = new unsigned[Cache->Head().PackageCount]; + memset(Colours,0,sizeof(*Colours)*Cache->Head().PackageCount); + + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) Colours[Pkg->ID] = 1; @@ -553,7 +564,7 @@ bool Depends(CommandLine &CmdL) do { DidSomething = false; - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) { if (Colours[Pkg->ID] != 1) continue; @@ -600,11 +611,11 @@ bool Depends(CommandLine &CmdL) // Display all solutions SPtrArray List = D.AllTargets(); - pkgPrioSortList(Cache,List); + pkgPrioSortList(*Cache,List); for (pkgCache::Version **I = List; *I != 0; I++) { - pkgCache::VerIterator V(Cache,*I); - if (V != Cache.VerP + V.ParentPkg()->VersionList || + pkgCache::VerIterator V(*Cache,*I); + if (V != Cache->VerP + V.ParentPkg()->VersionList || V->ParentPkg == D->Package) continue; cout << " " << V.ParentPkg().FullName(true) << endl; @@ -625,11 +636,15 @@ bool Depends(CommandLine &CmdL) /* */ bool RDepends(CommandLine &CmdL) { - pkgCache &Cache = *GCache; - SPtrArray Colours = new unsigned[Cache.Head().PackageCount]; - memset(Colours,0,sizeof(*Colours)*Cache.Head().PackageCount); + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == NULL)) + return false; - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + SPtrArray Colours = new unsigned[Cache->Head().PackageCount]; + memset(Colours,0,sizeof(*Colours)*Cache->Head().PackageCount); + + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) Colours[Pkg->ID] = 1; @@ -639,7 +654,7 @@ bool RDepends(CommandLine &CmdL) do { DidSomething = false; - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) { if (Colours[Pkg->ID] != 1) continue; @@ -681,11 +696,11 @@ bool RDepends(CommandLine &CmdL) // Display all solutions SPtrArray List = D.AllTargets(); - pkgPrioSortList(Cache,List); + pkgPrioSortList(*Cache,List); for (pkgCache::Version **I = List; *I != 0; I++) { - pkgCache::VerIterator V(Cache,*I); - if (V != Cache.VerP + V.ParentPkg()->VersionList || + pkgCache::VerIterator V(*Cache,*I); + if (V != Cache->VerP + V.ParentPkg()->VersionList || V->ParentPkg == D->Package) continue; cout << " " << V.ParentPkg().FullName(true) << endl; @@ -707,7 +722,11 @@ bool RDepends(CommandLine &CmdL) bool XVcg(CommandLine &CmdL) { - pkgCache &Cache = *GCache; + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == NULL)) + return false; + bool GivenOnly = _config->FindB("APT::Cache::GivenOnly",false); /* Normal packages are boxes @@ -724,21 +743,21 @@ bool XVcg(CommandLine &CmdL) 0 = None */ enum States {None=0, ToShow, ToShowNR, DoneNR, Done}; enum TheFlags {ForceNR=(1<<0)}; - unsigned char *Show = new unsigned char[Cache.Head().PackageCount]; - unsigned char *Flags = new unsigned char[Cache.Head().PackageCount]; - unsigned char *ShapeMap = new unsigned char[Cache.Head().PackageCount]; + unsigned char *Show = new unsigned char[Cache->Head().PackageCount]; + unsigned char *Flags = new unsigned char[Cache->Head().PackageCount]; + unsigned char *ShapeMap = new unsigned char[Cache->Head().PackageCount]; // Show everything if no arguments given if (CmdL.FileList[1] == 0) - for (unsigned long I = 0; I != Cache.Head().PackageCount; I++) + for (unsigned long I = 0; I != Cache->Head().PackageCount; I++) Show[I] = ToShow; else - for (unsigned long I = 0; I != Cache.Head().PackageCount; I++) + for (unsigned long I = 0; I != Cache->Head().PackageCount; I++) Show[I] = None; - memset(Flags,0,sizeof(*Flags)*Cache.Head().PackageCount); + memset(Flags,0,sizeof(*Flags)*Cache->Head().PackageCount); // Map the shapes - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) { if (Pkg->VersionList == 0) { @@ -777,7 +796,7 @@ bool XVcg(CommandLine &CmdL) } // Locate the package - pkgCache::PkgIterator Pkg = Cache.FindPkg(P); + pkgCache::PkgIterator Pkg = Cache->FindPkg(P); if (Pkg.end() == true) { _error->Warning(_("Unable to locate package %s"),*I); @@ -798,7 +817,7 @@ bool XVcg(CommandLine &CmdL) while (Act == true) { Act = false; - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) { // See we need to show this package if (Show[Pkg->ID] == None || Show[Pkg->ID] >= DoneNR) @@ -833,7 +852,7 @@ bool XVcg(CommandLine &CmdL) for (pkgCache::VerIterator I = DPkg.VersionList(); I.end() == false && Hit == false; I++) { - if (Cache.VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true) + if (Cache->VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true) Hit = true; } @@ -841,7 +860,7 @@ bool XVcg(CommandLine &CmdL) for (pkgCache::PrvIterator I = DPkg.ProvidesList(); I.end() == false && Hit == false; I++) { - if (Cache.VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false) + if (Cache->VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false) Hit = true; } @@ -902,7 +921,7 @@ bool XVcg(CommandLine &CmdL) /* Draw the box colours after the fact since we can not tell what colour they should be until everything is finished drawing */ - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) { if (Show[Pkg->ID] < DoneNR) continue; @@ -931,7 +950,11 @@ bool XVcg(CommandLine &CmdL) http://www.research.att.com/sw/tools/graphviz/ */ bool Dotty(CommandLine &CmdL) { - pkgCache &Cache = *GCache; + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == NULL)) + return false; + bool GivenOnly = _config->FindB("APT::Cache::GivenOnly",false); /* Normal packages are boxes @@ -948,21 +971,21 @@ bool Dotty(CommandLine &CmdL) 0 = None */ enum States {None=0, ToShow, ToShowNR, DoneNR, Done}; enum TheFlags {ForceNR=(1<<0)}; - unsigned char *Show = new unsigned char[Cache.Head().PackageCount]; - unsigned char *Flags = new unsigned char[Cache.Head().PackageCount]; - unsigned char *ShapeMap = new unsigned char[Cache.Head().PackageCount]; + unsigned char *Show = new unsigned char[Cache->Head().PackageCount]; + unsigned char *Flags = new unsigned char[Cache->Head().PackageCount]; + unsigned char *ShapeMap = new unsigned char[Cache->Head().PackageCount]; // Show everything if no arguments given if (CmdL.FileList[1] == 0) - for (unsigned long I = 0; I != Cache.Head().PackageCount; I++) + for (unsigned long I = 0; I != Cache->Head().PackageCount; I++) Show[I] = ToShow; else - for (unsigned long I = 0; I != Cache.Head().PackageCount; I++) + for (unsigned long I = 0; I != Cache->Head().PackageCount; I++) Show[I] = None; - memset(Flags,0,sizeof(*Flags)*Cache.Head().PackageCount); + memset(Flags,0,sizeof(*Flags)*Cache->Head().PackageCount); // Map the shapes - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) { if (Pkg->VersionList == 0) { @@ -1001,7 +1024,7 @@ bool Dotty(CommandLine &CmdL) } // Locate the package - pkgCache::PkgIterator Pkg = Cache.FindPkg(P); + pkgCache::PkgIterator Pkg = Cache->FindPkg(P); if (Pkg.end() == true) { _error->Warning(_("Unable to locate package %s"),*I); @@ -1022,7 +1045,7 @@ bool Dotty(CommandLine &CmdL) while (Act == true) { Act = false; - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) { // See we need to show this package if (Show[Pkg->ID] == None || Show[Pkg->ID] >= DoneNR) @@ -1055,7 +1078,7 @@ bool Dotty(CommandLine &CmdL) for (pkgCache::VerIterator I = DPkg.VersionList(); I.end() == false && Hit == false; I++) { - if (Cache.VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true) + if (Cache->VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true) Hit = true; } @@ -1063,7 +1086,7 @@ bool Dotty(CommandLine &CmdL) for (pkgCache::PrvIterator I = DPkg.ProvidesList(); I.end() == false && Hit == false; I++) { - if (Cache.VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false) + if (Cache->VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false) Hit = true; } @@ -1117,7 +1140,7 @@ bool Dotty(CommandLine &CmdL) /* Draw the box colours after the fact since we can not tell what colour they should be until everything is finished drawing */ - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) { if (Show[Pkg->ID] < DoneNR) continue; @@ -1191,8 +1214,12 @@ bool DoAdd(CommandLine &CmdL) // --------------------------------------------------------------------- /* This displays the package record from the proper package index file. It is not used by DumpAvail for performance reasons. */ -bool DisplayRecord(pkgCache::VerIterator V) +bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V) { + pkgCache *Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == NULL)) + return false; + // Find an appropriate file pkgCache::VerFileIterator Vf = V.FileList(); for (; Vf.end() == false; Vf++) @@ -1211,7 +1238,7 @@ bool DisplayRecord(pkgCache::VerIterator V) return false; // Read the record - unsigned char *Buffer = new unsigned char[GCache->HeaderP->MaxVerFileSize+1]; + unsigned char *Buffer = new unsigned char[Cache->HeaderP->MaxVerFileSize+1]; Buffer[V.FileList()->Size] = '\n'; if (PkgF.Seek(V.FileList()->Offset) == false || PkgF.Read(Buffer,V.FileList()->Size) == false) @@ -1231,7 +1258,7 @@ bool DisplayRecord(pkgCache::VerIterator V) } // Show the right description - pkgRecords Recs(*GCache); + pkgRecords Recs(*Cache); pkgCache::DescIterator Desc = V.TranslatedDescription(); pkgRecords::Parser &P = Recs.Lookup(Desc.FileList()); cout << "Description" << ( (strcmp(Desc.LanguageCode(),"") != 0) ? "-" : "" ) << Desc.LanguageCode() << ": " << P.LongDesc(); @@ -1271,13 +1298,16 @@ struct ExDescFile /* This searches the package names and package descriptions for a pattern */ bool Search(CommandLine &CmdL) { - pkgCache &Cache = *GCache; bool const ShowFull = _config->FindB("APT::Cache::ShowFull",false); bool const NamesOnly = _config->FindB("APT::Cache::NamesOnly",false); unsigned int const NumPatterns = CmdL.FileSize() -1; - pkgDepCache::Policy Plcy; - + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + pkgDepCache::Policy *Plcy = CacheFile.GetPolicy(); + if (unlikely(Cache == NULL || Plcy == NULL)) + return false; + // Make sure there is at least one argument if (NumPatterns < 1) return _error->Error(_("You must give at least one search pattern")); @@ -1303,11 +1333,11 @@ bool Search(CommandLine &CmdL) return false; } - ExDescFile *DFList = new ExDescFile[Cache.HeaderP->GroupCount+1]; - memset(DFList,0,sizeof(*DFList)*Cache.HeaderP->GroupCount+1); + ExDescFile *DFList = new ExDescFile[Cache->HeaderP->GroupCount+1]; + memset(DFList,0,sizeof(*DFList)*Cache->HeaderP->GroupCount+1); // Map versions that we want to write out onto the VerList array. - for (pkgCache::GrpIterator G = Cache.GrpBegin(); G.end() == false; ++G) + for (pkgCache::GrpIterator G = Cache->GrpBegin(); G.end() == false; ++G) { if (DFList[G->ID].NameMatch == true) continue; @@ -1329,7 +1359,7 @@ bool Search(CommandLine &CmdL) pkgCache::PkgIterator P = G.FindPreferredPkg(); if (P.end() == true) continue; - pkgCache::VerIterator V = Plcy.GetCandidateVer(P); + pkgCache::VerIterator V = Plcy->GetCandidateVer(P); if (V.end() == false) DFList[G->ID].Df = V.DescriptionList().FileList(); @@ -1339,7 +1369,7 @@ bool Search(CommandLine &CmdL) // Include all the packages that provide matching names too for (pkgCache::PrvIterator Prv = P.ProvidesList() ; Prv.end() == false; Prv++) { - pkgCache::VerIterator V = Plcy.GetCandidateVer(Prv.OwnerPkg()); + pkgCache::VerIterator V = Plcy->GetCandidateVer(Prv.OwnerPkg()); if (V.end() == true) continue; @@ -1349,14 +1379,14 @@ bool Search(CommandLine &CmdL) } } - LocalitySort(&DFList->Df,Cache.HeaderP->GroupCount,sizeof(*DFList)); + LocalitySort(&DFList->Df,Cache->HeaderP->GroupCount,sizeof(*DFList)); // Create the text record parser - pkgRecords Recs(Cache); + pkgRecords Recs(*Cache); // Iterate over all the version records and check them for (ExDescFile *J = DFList; J->Df != 0; J++) { - pkgRecords::Parser &P = Recs.Lookup(pkgCache::DescFileIterator(Cache,J->Df)); + pkgRecords::Parser &P = Recs.Lookup(pkgCache::DescFileIterator(*Cache,J->Df)); if (J->NameMatch == false && NamesOnly == false) { @@ -1398,15 +1428,17 @@ bool Search(CommandLine &CmdL) /* show automatically installed packages (sorted) */ bool ShowAuto(CommandLine &CmdL) { - OpProgress op; - pkgDepCache DepCache(GCache); - DepCache.Init(&op); + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + pkgDepCache *DepCache = CacheFile.GetDepCache(); + if (unlikely(Cache == NULL || DepCache == NULL)) + return false; std::vector packages; - packages.reserve(GCache->HeaderP->PackageCount / 3); + packages.reserve(Cache->HeaderP->PackageCount / 3); - for (pkgCache::PkgIterator P = GCache->PkgBegin(); P.end() == false; P++) - if (DepCache[P].Flags & pkgCache::Flag::Auto) + for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; P++) + if ((*DepCache)[P].Flags & pkgCache::Flag::Auto) packages.push_back(P.Name()); std::sort(packages.begin(), packages.end()); @@ -1421,34 +1453,16 @@ bool ShowAuto(CommandLine &CmdL) // --------------------------------------------------------------------- /* */ bool ShowPackage(CommandLine &CmdL) -{ - pkgCache &Cache = *GCache; - pkgDepCache::Policy Plcy; - - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) - { - // Find the proper version to use. - if (_config->FindB("APT::Cache::AllVersions","true") == true) - { - pkgCache::VerIterator V; - for (V = Pkg.VersionList(); V.end() == false; V++) - { - if (DisplayRecord(V) == false) - return false; - } - } - else - { - pkgCache::VerIterator V = Plcy.GetCandidateVer(Pkg); - if (V.end() == true || V.FileList().end() == true) - continue; - if (DisplayRecord(V) == false) - return false; - } - } - - if (pkgset.empty() == false) +{ + pkgCacheFile CacheFile; + APT::VersionSet::Version const select = _config->FindB("APT::Cache::AllVersions", true) ? + APT::VersionSet::ALL : APT::VersionSet::INSTALLED; + APT::VersionSet const verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList, select); + for (APT::VersionSet::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) + if (DisplayRecord(CacheFile, Ver) == false) + return false; + + if (verset.empty() == false) return true; return _error->Error(_("No packages found")); } @@ -1458,8 +1472,10 @@ bool ShowPackage(CommandLine &CmdL) /* This does a prefix match on the first argument */ bool ShowPkgNames(CommandLine &CmdL) { - pkgCache &Cache = *GCache; - pkgCache::GrpIterator I = Cache.GrpBegin(); + pkgCacheFile CacheFile; + if (unlikely(CacheFile.BuildCaches(NULL, false) == false)) + return false; + pkgCache::GrpIterator I = CacheFile.GetPkgCache()->GrpBegin(); bool const All = _config->FindB("APT::Cache::AllNames","false"); if (CmdL.FileList[1] != 0) @@ -1495,11 +1511,13 @@ bool ShowPkgNames(CommandLine &CmdL) /* */ bool ShowSrcPackage(CommandLine &CmdL) { - pkgSourceList List; - List.ReadMainList(); - + pkgCacheFile CacheFile; + pkgSourceList *List = CacheFile.GetSourceList(); + if (unlikely(List == NULL)) + return false; + // Create the text record parsers - pkgSrcRecords SrcRecs(List); + pkgSrcRecords SrcRecs(*List); if (_error->PendingError() == true) return false; @@ -1530,19 +1548,18 @@ bool ShowSrcPackage(CommandLine &CmdL) /* */ bool Policy(CommandLine &CmdL) { - if (SrcList == 0) - return _error->Error("Generate must be enabled for this function"); - - pkgCache &Cache = *GCache; - pkgPolicy Plcy(&Cache); - if (ReadPinFile(Plcy) == false || ReadPinDir(Plcy) == false) + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + pkgPolicy *Plcy = CacheFile.GetPolicy(); + pkgSourceList *SrcList = CacheFile.GetSourceList(); + if (unlikely(Cache == NULL || Plcy == NULL || SrcList == NULL)) return false; - + // Print out all of the package files if (CmdL.FileList[1] == 0) { cout << _("Package files:") << endl; - for (pkgCache::PkgFileIterator F = Cache.FileBegin(); F.end() == false; F++) + for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F.end() == false; F++) { // Locate the associated index files so we can derive a description pkgIndexFile *Indx; @@ -1551,7 +1568,7 @@ bool Policy(CommandLine &CmdL) return _error->Error(_("Cache is out of sync, can't x-ref a package file")); printf("%4i %s\n", - Plcy.GetPriority(F),Indx->Describe(true).c_str()); + Plcy->GetPriority(F),Indx->Describe(true).c_str()); // Print the reference information for the package string Str = F.RelStr(); @@ -1563,16 +1580,16 @@ bool Policy(CommandLine &CmdL) // Show any packages have explicit pins cout << _("Pinned packages:") << endl; - pkgCache::PkgIterator I = Cache.PkgBegin(); + pkgCache::PkgIterator I = Cache->PkgBegin(); for (;I.end() != true; I++) { - if (Plcy.GetPriority(I) == 0) + if (Plcy->GetPriority(I) == 0) continue; // Print the package name and the version we are forcing to cout << " " << I.FullName(true) << " -> "; - pkgCache::VerIterator V = Plcy.GetMatch(I); + pkgCache::VerIterator V = Plcy->GetMatch(I); if (V.end() == true) cout << _("(not found)") << endl; else @@ -1593,7 +1610,7 @@ bool Policy(CommandLine &CmdL) (InstalledLessCandidate > 0 ? (InstalledLessCandidate) : 0) - 1; // Print out detailed information for each package - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); for (APT::PackageSet::const_iterator I = pkgset.begin(); I != pkgset.end(); ++I) { pkgCache::PkgIterator Pkg = I.Group().FindPkg("any"); @@ -1613,17 +1630,17 @@ bool Policy(CommandLine &CmdL) // Candidate Version cout << msgCandidate << OutputInDepth(deepCandidate, " "); - pkgCache::VerIterator V = Plcy.GetCandidateVer(Pkg); + pkgCache::VerIterator V = Plcy->GetCandidateVer(Pkg); if (V.end() == true) cout << _("(none)") << endl; else cout << V.VerStr() << endl; // Pinned version - if (Plcy.GetPriority(Pkg) != 0) + if (Plcy->GetPriority(Pkg) != 0) { cout << _(" Package pin: "); - V = Plcy.GetMatch(Pkg); + V = Plcy->GetMatch(Pkg); if (V.end() == true) cout << _("(not found)") << endl; else @@ -1638,7 +1655,7 @@ bool Policy(CommandLine &CmdL) cout << " *** " << V.VerStr(); else cout << " " << V.VerStr(); - cout << " " << Plcy.GetPriority(Pkg) << endl; + cout << " " << Plcy->GetPriority(Pkg) << endl; for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; VF++) { // Locate the associated index files so we can derive a description @@ -1646,7 +1663,7 @@ bool Policy(CommandLine &CmdL) if (SrcList->FindIndex(VF.File(),Indx) == false && _system->FindIndex(VF.File(),Indx) == false) return _error->Error(_("Cache is out of sync, can't x-ref a package file")); - printf(" %4i %s\n",Plcy.GetPriority(VF.File()), + printf(" %4i %s\n",Plcy->GetPriority(VF.File()), Indx->Describe(true).c_str()); } } @@ -1661,12 +1678,11 @@ bool Policy(CommandLine &CmdL) /* */ bool Madison(CommandLine &CmdL) { - if (SrcList == 0) - return _error->Error("Generate must be enabled for this function"); - - SrcList->ReadMainList(); + pkgCacheFile CacheFile; + pkgSourceList *SrcList = CacheFile.GetSourceList(); - pkgCache &Cache = *GCache; + if (SrcList == 0) + return false; // Create the src text record parsers and ignore errors about missing // deb-src lines that are generated from pkgSrcRecords::pkgSrcRecords @@ -1674,7 +1690,7 @@ bool Madison(CommandLine &CmdL) if (_error->PendingError() == true) _error->Discard(); - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { if (Pkg.end() == false) @@ -1729,11 +1745,9 @@ bool Madison(CommandLine &CmdL) bool GenCaches(CommandLine &Cmd) { OpTextProgress Progress(*_config); - - pkgSourceList List; - if (List.ReadMainList() == false) - return false; - return pkgMakeStatusCache(List,Progress); + + pkgCacheFile CacheFile; + return CacheFile.BuildCaches(&Progress, true); } /*}}}*/ // ShowHelp - Show a help screen /*{{{*/ @@ -1865,35 +1879,10 @@ int main(int argc,const char *argv[]) /*{{{*/ if (isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1) _config->Set("quiet","1"); +// if (_config->FindB("APT::Cache::Generate",true) == false) if (CmdL.DispatchArg(CmdsA,false) == false && _error->PendingError() == false) - { - MMap *Map = 0; - if (_config->FindB("APT::Cache::Generate",true) == false) - { - Map = new MMap(*new FileFd(_config->FindFile("Dir::Cache::pkgcache"), - FileFd::ReadOnly),MMap::Public|MMap::ReadOnly); - } - else - { - // Open the cache file - SrcList = new pkgSourceList; - SrcList->ReadMainList(); + CmdL.DispatchArg(CmdsB); - // Generate it and map it - OpProgress Prog; - pkgMakeStatusCache(*SrcList,Prog,&Map,true); - } - - if (_error->PendingError() == false) - { - pkgCache Cache(Map); - GCache = &Cache; - if (_error->PendingError() == false) - CmdL.DispatchArg(CmdsB); - } - delete Map; - } - // Print any errors or warnings found during parsing if (_error->empty() == false) { diff --git a/debian/changelog b/debian/changelog index 9001e91a..d935d06d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -32,6 +32,7 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - get the best matching arch package from a group with FindPreferredPkg * cmdline/apt-cache.cc: - make the search multiarch compatible by using GrpIterator instead + - use pkgCacheFile and the new CacheSets all over the place * apt-pkg/cachefile.{cc,h}: - split Open() into submethods to be able to build only parts - make the OpProgress optional in the Cache buildprocess -- cgit v1.2.3 From 0588779fb2139b70f369ccac20fcc0f3a3e9ed47 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 10:17:10 +0200 Subject: Add a option to apt-cache policy to additionally init the DepCache before starting to get the package informations. This is useful e.g. for debugging the MultiArchKiller. --- cmdline/apt-cache.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 227fda4b..b0e70510 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1555,6 +1555,12 @@ bool Policy(CommandLine &CmdL) if (unlikely(Cache == NULL || Plcy == NULL || SrcList == NULL)) return false; + /* Should the MultiArchKiller be run to see which pseudo packages for an + arch all package are currently installed? Activating it gives a speed + penality for no real gain beside enhanced debugging, so in general no. */ + if (_config->FindB("APT::Cache::Policy::DepCache", false) == true) + CacheFile.GetDepCache(); + // Print out all of the package files if (CmdL.FileList[1] == 0) { -- cgit v1.2.3 From f44a05ff641523ab8eae84166e9b1a9dcf1b366f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 12:54:30 +0200 Subject: add --target-release option (Closes: #115520) --- cmdline/apt-cache.cc | 2 ++ debian/changelog | 1 + 2 files changed, 3 insertions(+) diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index b0e70510..005721dd 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1831,6 +1831,8 @@ int main(int argc,const char *argv[]) /*{{{*/ {'n',"names-only","APT::Cache::NamesOnly",0}, {0,"all-names","APT::Cache::AllNames",0}, {0,"recurse","APT::Cache::RecurseDepends",0}, + {'t',"target-release","APT::Default-Release",CommandLine::HasArg}, + {'t',"default-release","APT::Default-Release",CommandLine::HasArg}, {'c',"config-file",0,CommandLine::ConfigFile}, {'o',"option",0,CommandLine::ArbItem}, {0,"installed","APT::Cache::Installed",0}, diff --git a/debian/changelog b/debian/changelog index d935d06d..acdc1795 100644 --- a/debian/changelog +++ b/debian/changelog @@ -33,6 +33,7 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low * cmdline/apt-cache.cc: - make the search multiarch compatible by using GrpIterator instead - use pkgCacheFile and the new CacheSets all over the place + - add --target-release option (Closes: #115520) * apt-pkg/cachefile.{cc,h}: - split Open() into submethods to be able to build only parts - make the OpProgress optional in the Cache buildprocess -- cgit v1.2.3 From 9f1f17ccd4f84c23410ae62911c85f5836c3b503 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 13:09:18 +0200 Subject: Don't increase the commandline parameter in the library but in the application to be really generic. --- apt-pkg/cacheset.cc | 4 ++-- cmdline/apt-cache.cc | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc index 7372c909..5dbd1a4d 100644 --- a/apt-pkg/cacheset.cc +++ b/apt-pkg/cacheset.cc @@ -79,7 +79,7 @@ PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, std:: // FromCommandLine - Return all packages specified on commandline /*{{{*/ PackageSet PackageSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline, std::ostream &out) { PackageSet pkgset; - for (const char **I = cmdline + 1; *I != 0; I++) { + for (const char **I = cmdline; *I != 0; ++I) { PackageSet pset = FromString(Cache, *I, out); pkgset.insert(pset.begin(), pset.end()); } @@ -105,7 +105,7 @@ PackageSet PackageSet::FromString(pkgCacheFile &Cache, const char * const str, s APT::VersionSet VersionSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline, APT::VersionSet::Version const &fallback, std::ostream &out) { VersionSet verset; - for (const char **I = cmdline + 1; *I != 0; I++) { + for (const char **I = cmdline; *I != 0; ++I) { std::string pkg = *I; std::string ver; bool verIsRel = false; diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 005721dd..e3876d5e 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -176,7 +176,7 @@ bool UnMet(CommandLine &CmdL) bool DumpPackage(CommandLine &CmdL) { pkgCacheFile CacheFile; - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { @@ -553,7 +553,7 @@ bool Depends(CommandLine &CmdL) SPtrArray Colours = new unsigned[Cache->Head().PackageCount]; memset(Colours,0,sizeof(*Colours)*Cache->Head().PackageCount); - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); + 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; @@ -644,7 +644,7 @@ bool RDepends(CommandLine &CmdL) SPtrArray Colours = new unsigned[Cache->Head().PackageCount]; memset(Colours,0,sizeof(*Colours)*Cache->Head().PackageCount); - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); + 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; @@ -1457,7 +1457,7 @@ bool ShowPackage(CommandLine &CmdL) pkgCacheFile CacheFile; APT::VersionSet::Version const select = _config->FindB("APT::Cache::AllVersions", true) ? APT::VersionSet::ALL : APT::VersionSet::INSTALLED; - APT::VersionSet const verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList, select); + APT::VersionSet const verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, select); for (APT::VersionSet::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) if (DisplayRecord(CacheFile, Ver) == false) return false; @@ -1616,7 +1616,7 @@ bool Policy(CommandLine &CmdL) (InstalledLessCandidate > 0 ? (InstalledLessCandidate) : 0) - 1; // Print out detailed information for each package - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); for (APT::PackageSet::const_iterator I = pkgset.begin(); I != pkgset.end(); ++I) { pkgCache::PkgIterator Pkg = I.Group().FindPkg("any"); @@ -1696,7 +1696,7 @@ bool Madison(CommandLine &CmdL) if (_error->PendingError() == true) _error->Discard(); - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { if (Pkg.end() == false) -- cgit v1.2.3 From c45f2d1995a58c7a5a8616c6fbf9f95ee4ccfd49 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 13:38:17 +0200 Subject: do not insert end() Iterators into the CacheSet even if requested --- apt-pkg/cacheset.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index 708531b4..b65e053e 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -61,6 +61,9 @@ public: /*{{{*/ // 103. set::iterator is required to be modifiable, but this allows modification of keys typedef typename APT::PackageSet::const_iterator iterator; + using std::set::insert; + inline void insert(pkgCache::PkgIterator const &P) { if (P.end() == false) std::set::insert(P); }; + /** \brief returns all packages in the cache whose name matchs a given pattern A simple helper responsible for executing a regular expression on all @@ -145,6 +148,9 @@ public: /*{{{*/ // 103. set::iterator is required to be modifiable, but this allows modification of keys typedef typename APT::VersionSet::const_iterator iterator; + using std::set::insert; + inline void insert(pkgCache::VerIterator const &V) { if (V.end() == false) std::set::insert(V); }; + /** \brief specifies which version(s) will be returned if non is given */ enum Version { /** All versions */ -- cgit v1.2.3 From 292f5b8770a0f10d8a19204dc4a914437d861662 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 13:42:04 +0200 Subject: apt-cache show --no-all-versions should issues the Candidate --- cmdline/apt-cache.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index e3876d5e..b782c70a 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1456,7 +1456,7 @@ bool ShowPackage(CommandLine &CmdL) { pkgCacheFile CacheFile; APT::VersionSet::Version const select = _config->FindB("APT::Cache::AllVersions", true) ? - APT::VersionSet::ALL : APT::VersionSet::INSTALLED; + APT::VersionSet::ALL : APT::VersionSet::CANDIDATE; APT::VersionSet const verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, select); for (APT::VersionSet::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) if (DisplayRecord(CacheFile, Ver) == false) -- cgit v1.2.3 From fe870febbfc1145d4a2a6b86985b0253419d52a8 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 15:47:16 +0200 Subject: handle :arch modifier in PackageSet::FromString correctly --- apt-pkg/cacheset.cc | 26 ++++++++++++++++++++------ apt-pkg/cacheset.h | 4 ++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc index 5dbd1a4d..8fcffaf9 100644 --- a/apt-pkg/cacheset.cc +++ b/apt-pkg/cacheset.cc @@ -87,17 +87,31 @@ PackageSet PackageSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline } /*}}}*/ // FromString - Return all packages matching a specific string /*{{{*/ -PackageSet PackageSet::FromString(pkgCacheFile &Cache, const char * const str, std::ostream &out) { - pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(str); - if (Grp.end() == false) { - pkgCache::PkgIterator Pkg = Grp.FindPreferredPkg(); +PackageSet PackageSet::FromString(pkgCacheFile &Cache, std::string const &str, std::ostream &out) { + 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); + } + + pkgCache::PkgIterator Pkg; + 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() == false) { PackageSet pkgset; pkgset.insert(Pkg); return pkgset; } PackageSet regex = FromRegEx(Cache, str, out); if (regex.empty() == true) - _error->Warning(_("Unable to locate package %s"), str); + _error->Warning(_("Unable to locate package %s"), str.c_str()); return regex; } /*}}}*/ @@ -188,7 +202,7 @@ pkgCache::VerIterator VersionSet::getCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg, bool const &AllowError) { if (unlikely(Cache.BuildDepCache() == false)) return pkgCache::VerIterator(*Cache); - pkgCache::VerIterator Cand = Cache[Pkg].InstVerIter(Cache); + pkgCache::VerIterator Cand = Cache[Pkg].CandidateVerIter(Cache); if (AllowError == false && Cand.end() == true) _error->Error(_("Can't select candidate version from package %s as it has no candidate"), Pkg.FullName(true).c_str()); return Cand; diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index b65e053e..4f7be4ca 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -83,8 +83,8 @@ public: /*{{{*/ \param Cache the packages are in \param string String the package name(s) should be extracted from \param out stream to print various notices to */ - static APT::PackageSet FromString(pkgCacheFile &Cache, const char * const string, std::ostream &out); - static APT::PackageSet FromString(pkgCacheFile &Cache, const char * const string) { + static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string, std::ostream &out); + static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string) { std::ostream out (std::ofstream("/dev/null").rdbuf()); return APT::PackageSet::FromString(Cache, string, out); } -- cgit v1.2.3 From 88edd59bb5ff29d1f55612b2ab216a72b9a9898e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 16:45:19 +0200 Subject: enhance the changelog a bit --- debian/changelog | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/debian/changelog b/debian/changelog index acdc1795..5590f20f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,6 +10,7 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - do the autoremove mark process also for required packages to handle these illegally depending on lower priority packages (Closes: #583517) - try harder to find the other pseudo versions for autoremove multiarch + - correct "Dangerous iterator usage" pointed out by cppcheck * apt-pkg/aptconfiguration.cc: - remove duplicate architectures in getArchitectures() * apt-pkg/indexrecords.{cc,h}: @@ -18,8 +19,6 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - do not try PDiff if it is not listed in the Meta file * apt-pkg/cacheiterator.h: - let pkgCache::Iterator inherent std::iterator - * apt-pkg/depcache.cc: - - correct "Dangerous iterator usage." pointed out by cppcheck * ftparchive/writer.h: - add a virtual destructor to FTWScanner class (for cppcheck) * apt-pkg/cacheset.{cc,h}: @@ -34,12 +33,13 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - make the search multiarch compatible by using GrpIterator instead - use pkgCacheFile and the new CacheSets all over the place - add --target-release option (Closes: #115520) + - accept pkg/release and pkg=version in show and co. (Closes: #236270) * apt-pkg/cachefile.{cc,h}: - split Open() into submethods to be able to build only parts - make the OpProgress optional in the Cache buildprocess - store also the SourceList we use internally for export - -- David Kalnischkies Mon, 31 May 2010 22:36:35 +0200 + -- David Kalnischkies Sat, 05 Jun 2010 14:39:58 +0200 apt (0.7.26~exp5) experimental; urgency=low -- cgit v1.2.3 From 6ebaae9a5d794ce69d17e419c109fc185925541c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 16:59:45 +0200 Subject: accept package versions in the unmet command --- cmdline/apt-cache.cc | 57 +++++++++++++++++++++++++++++++--------------------- debian/changelog | 1 + 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index b782c70a..ef074280 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -81,18 +81,8 @@ void LocalitySort(pkgCache::DescFile **begin, // UnMet - Show unmet dependencies /*{{{*/ // --------------------------------------------------------------------- /* */ -bool UnMet(CommandLine &CmdL) +bool ShowUnMet(pkgCache::VerIterator const &V, bool const &Important) { - bool const Important = _config->FindB("APT::Cache::Important",false); - - pkgCacheFile CacheFile; - if (unlikely(CacheFile.GetPkgCache() == NULL)) - return false; - - for (pkgCache::PkgIterator P = CacheFile.GetPkgCache()->PkgBegin(); P.end() == false; P++) - { - for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++) - { bool Header = false; for (pkgCache::DepIterator D = V.DependsList(); D.end() == false;) { @@ -100,20 +90,19 @@ bool UnMet(CommandLine &CmdL) pkgCache::DepIterator Start; pkgCache::DepIterator End; D.GlobOr(Start,End); - - // Skip conflicts and replaces - if (End->Type != pkgCache::Dep::PreDepends && - End->Type != pkgCache::Dep::Depends && - End->Type != pkgCache::Dep::Suggests && - End->Type != pkgCache::Dep::Recommends) - continue; // Important deps only if (Important == true) if (End->Type != pkgCache::Dep::PreDepends && End->Type != pkgCache::Dep::Depends) continue; - + + // Skip conflicts and replaces + if (End->Type == pkgCache::Dep::DpkgBreaks || + End->Type == pkgCache::Dep::Replaces || + End->Type == pkgCache::Dep::Conflicts) + continue; + // Verify the or group bool OK = false; pkgCache::DepIterator RealStart = Start; @@ -142,7 +131,7 @@ bool UnMet(CommandLine &CmdL) // Oops, it failed.. if (Header == false) ioprintf(cout,_("Package %s version %s has an unmet dep:\n"), - P.FullName(true).c_str(),V.VerStr()); + V.ParentPkg().FullName(true).c_str(),V.VerStr()); Header = true; // Print out the dep type @@ -164,9 +153,31 @@ bool UnMet(CommandLine &CmdL) while (1); cout << endl; - } - } - } + } + return true; +} +bool UnMet(CommandLine &CmdL) +{ + bool const Important = _config->FindB("APT::Cache::Important",false); + + pkgCacheFile CacheFile; + if (unlikely(CacheFile.GetPkgCache() == NULL)) + return false; + + if (CmdL.FileSize() <= 1) + { + for (pkgCache::PkgIterator P = CacheFile.GetPkgCache()->PkgBegin(); P.end() == false; P++) + for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; ++V) + if (ShowUnMet(V, Important) == false) + return false; + } + else + { + APT::VersionSet verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1); + for (APT::VersionSet::iterator V = verset.begin(); V != verset.end(); ++V) + if (ShowUnMet(V, Important) == false) + return false; + } return true; } /*}}}*/ diff --git a/debian/changelog b/debian/changelog index 5590f20f..6c9faf11 100644 --- a/debian/changelog +++ b/debian/changelog @@ -34,6 +34,7 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - use pkgCacheFile and the new CacheSets all over the place - add --target-release option (Closes: #115520) - accept pkg/release and pkg=version in show and co. (Closes: #236270) + - accept package versions in the unmet command * apt-pkg/cachefile.{cc,h}: - split Open() into submethods to be able to build only parts - make the OpProgress optional in the Cache buildprocess -- cgit v1.2.3 From 84910ad5090b8cffc81d7942497ca09cc5d93244 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 18:00:00 +0200 Subject: support special release-modifier 'installed' and 'candidate' --- apt-pkg/cacheset.cc | 126 ++++++++++++++++++++++++++++++++-------------------- apt-pkg/cacheset.h | 5 +++ debian/changelog | 1 + 3 files changed, 83 insertions(+), 49 deletions(-) diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc index 8fcffaf9..c0b06ba3 100644 --- a/apt-pkg/cacheset.cc +++ b/apt-pkg/cacheset.cc @@ -132,10 +132,19 @@ APT::VersionSet VersionSet::FromCommandLine(pkgCacheFile &Cache, const char **cm PackageSet pkgset = PackageSet::FromString(Cache, pkg.c_str(), out); for (PackageSet::const_iterator P = pkgset.begin(); P != pkgset.end(); ++P) { - if (vertag != string::npos) { + if (vertag == string::npos) { + AddSelectedVersion(Cache, verset, P, fallback); + continue; + } + pkgCache::VerIterator V; + if (ver == "installed") + V = getInstalledVer(Cache, P); + else if (ver == "candidate") + V = getCandidateVer(Cache, P); + else { pkgVersionMatch Match(ver, (verIsRel == true ? pkgVersionMatch::Release : - pkgVersionMatch::Version)); - pkgCache::VerIterator V = Match.Find(P); + pkgVersionMatch::Version)); + V = Match.Find(P); if (V.end() == true) { if (verIsRel == true) _error->Error(_("Release '%s' for '%s' was not found"), @@ -145,58 +154,77 @@ APT::VersionSet VersionSet::FromCommandLine(pkgCacheFile &Cache, const char **cm ver.c_str(), P.FullName(true).c_str()); continue; } - if (strcmp(ver.c_str(), V.VerStr()) != 0) - ioprintf(out, _("Selected version %s (%s) for %s\n"), - V.VerStr(), V.RelStr().c_str(), P.FullName(true).c_str()); - verset.insert(V); - } else { - pkgCache::VerIterator V; - switch(fallback) { - case VersionSet::ALL: - for (V = P.VersionList(); V.end() != true; ++V) - verset.insert(V); - break; - case VersionSet::CANDANDINST: - verset.insert(getInstalledVer(Cache, P)); - verset.insert(getCandidateVer(Cache, P)); - break; - case VersionSet::CANDIDATE: - verset.insert(getCandidateVer(Cache, P)); - break; - case VersionSet::INSTALLED: - verset.insert(getInstalledVer(Cache, P)); - break; - case VersionSet::CANDINST: - V = getCandidateVer(Cache, P, true); - if (V.end() == true) - V = getInstalledVer(Cache, P, true); - if (V.end() == false) - verset.insert(V); - else - _error->Error(_("Can't select installed nor candidate version from package %s as it has neither of them"), P.FullName(true).c_str()); - break; - case VersionSet::INSTCAND: - V = getInstalledVer(Cache, P, true); - if (V.end() == true) - V = getCandidateVer(Cache, P, true); - if (V.end() == false) - verset.insert(V); - else - _error->Error(_("Can't select installed nor candidate version from package %s as it has neither of them"), P.FullName(true).c_str()); - break; - case VersionSet::NEWEST: - if (P->VersionList != 0) - verset.insert(P.VersionList()); - else - _error->Error(_("Can't select newest version from package %s as it is purely virtual"), P.FullName(true).c_str()); - break; - } } + if (V.end() == true) + continue; + if (ver == V.VerStr()) + ioprintf(out, _("Selected version '%s' (%s) for '%s'\n"), + V.VerStr(), V.RelStr().c_str(), P.FullName(true).c_str()); + verset.insert(V); } } return verset; } /*}}}*/ +// AddSelectedVersion - add version from package based on fallback /*{{{*/ +bool VersionSet::AddSelectedVersion(pkgCacheFile &Cache, VersionSet &verset, + pkgCache::PkgIterator const &P, VersionSet::Version const &fallback, + bool const &AllowError) { + pkgCache::VerIterator V; + switch(fallback) { + case VersionSet::ALL: + if (P->VersionList != 0) + for (V = P.VersionList(); V.end() != true; ++V) + verset.insert(V); + else if (AllowError == false) + return _error->Error(_("Can't select versions from package '%s' as it purely virtual"), P.FullName(true).c_str()); + else + return false; + break; + case VersionSet::CANDANDINST: + verset.insert(getInstalledVer(Cache, P, AllowError)); + verset.insert(getCandidateVer(Cache, P, AllowError)); + break; + case VersionSet::CANDIDATE: + verset.insert(getCandidateVer(Cache, P, AllowError)); + break; + case VersionSet::INSTALLED: + verset.insert(getInstalledVer(Cache, P, AllowError)); + break; + case VersionSet::CANDINST: + V = getCandidateVer(Cache, P, true); + if (V.end() == true) + V = getInstalledVer(Cache, P, true); + if (V.end() == false) + verset.insert(V); + else if (AllowError == false) + return _error->Error(_("Can't select installed nor candidate version from package '%s' as it has neither of them"), P.FullName(true).c_str()); + else + return false; + break; + case VersionSet::INSTCAND: + V = getInstalledVer(Cache, P, true); + if (V.end() == true) + V = getCandidateVer(Cache, P, true); + if (V.end() == false) + verset.insert(V); + else if (AllowError == false) + return _error->Error(_("Can't select installed nor candidate version from package '%s' as it has neither of them"), P.FullName(true).c_str()); + else + return false; + break; + case VersionSet::NEWEST: + if (P->VersionList != 0) + verset.insert(P.VersionList()); + else if (AllowError == false) + return _error->Error(_("Can't select newest version from package '%s' as it is purely virtual"), P.FullName(true).c_str()); + else + return false; + break; + } + return true; +} + /*}}}*/ // getCandidateVer - Returns the candidate version of the given package /*{{{*/ pkgCache::VerIterator VersionSet::getCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg, bool const &AllowError) { diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index 4f7be4ca..0f3a87a3 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -205,6 +205,11 @@ protected: /*{{{*/ static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg, bool const &AllowError = false); + + static bool AddSelectedVersion(pkgCacheFile &Cache, VersionSet &verset, + pkgCache::PkgIterator const &P, VersionSet::Version const &fallback, + bool const &AllowError = false); + /*}}}*/ }; /*}}}*/ } diff --git a/debian/changelog b/debian/changelog index 6c9faf11..21093b05 100644 --- a/debian/changelog +++ b/debian/changelog @@ -25,6 +25,7 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low - add simple wrapper around std::set for cache structures - move regex magic from apt-get to new FromRegEx method - move cmdline parsing from apt-cache to new FromCommandLine method + - support special release-modifier 'installed' and 'candidate' * apt-pkg/contrib/cmdline.cc: - fix segfault in SaveInConfig caused by writing over char[] sizes * apt-pkg/pkgcache.cc: -- cgit v1.2.3 From 07c279d93f0b61e96c9caf8139accd0289feab56 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 19:14:32 +0200 Subject: do not fail if an unrelated error is pending in DisplayRecord() --- cmdline/apt-cache.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index ef074280..de4288c5 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1243,11 +1243,11 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V) pkgCache::PkgFileIterator I = Vf.File(); if (I.IsOk() == false) return _error->Error(_("Package file %s is out of sync."),I.FileName()); - - FileFd PkgF(I.FileName(),FileFd::ReadOnly); - if (_error->PendingError() == true) + + FileFd PkgF; + if (PkgF.Open(I.FileName(), FileFd::ReadOnly) == false) return false; - + // Read the record unsigned char *Buffer = new unsigned char[Cache->HeaderP->MaxVerFileSize+1]; Buffer[V.FileList()->Size] = '\n'; -- cgit v1.2.3 From 9cc83a6fbc089ccf9cb8d52ee9f380cf5df62d5c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 6 Jun 2010 21:41:27 +0200 Subject: add a GroupedFromCommandLine method to the PackageSet to split the packages on the commandline into groups based on modifiers --- apt-pkg/cacheset.cc | 33 +++++++++++++++++++++++++++++++++ apt-pkg/cacheset.h | 23 +++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc index c0b06ba3..43ade4b4 100644 --- a/apt-pkg/cacheset.cc +++ b/apt-pkg/cacheset.cc @@ -76,6 +76,39 @@ PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, std:: return pkgset; } /*}}}*/ +// GroupedFromCommandLine - Return all versions specified on commandline/*{{{*/ +std::map PackageSet::GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback, std::ostream &out) { + std::map pkgsets; + for (const char **I = cmdline; *I != 0; ++I) { + unsigned short modID = fallback; + std::string str = *I; + 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; + } + break; + } + PackageSet pset = PackageSet::FromString(Cache, str, out); + pkgsets[modID].insert(pset.begin(), pset.end()); + } + return pkgsets; +} + /*}}}*/ // FromCommandLine - Return all packages specified on commandline /*{{{*/ PackageSet PackageSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline, std::ostream &out) { PackageSet pkgset; diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index 0f3a87a3..c9d12108 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -11,6 +11,8 @@ // Include Files /*{{{*/ #include #include +#include +#include #include #include @@ -101,6 +103,27 @@ public: /*{{{*/ std::ostream out (std::ofstream("/dev/null").rdbuf()); return APT::PackageSet::FromCommandLine(Cache, cmdline, out); } + + 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) {}; + }; + + static std::map GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback, std::ostream &out); + static std::map GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::PackageSet::GroupedFromCommandLine(Cache, cmdline, + mods, fallback, out); + } /*}}}*/ }; /*}}}*/ class VersionSet : public std::set { /*{{{*/ -- cgit v1.2.3 From 3c9772456931842dee211444086c15dd2e5f9a29 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 6 Jun 2010 21:49:28 +0200 Subject: use the GroupedFromCommandLine() method in the dotty and xvcg command to get all the funky features in less lines --- cmdline/apt-cache.cc | 84 ++++++++++++++++++---------------------------------- 1 file changed, 28 insertions(+), 56 deletions(-) diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index de4288c5..7cb95b3f 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -787,38 +787,24 @@ bool XVcg(CommandLine &CmdL) ShapeMap[Pkg->ID] = 3; } } - + // Load the list of packages from the command line into the show list - for (const char **I = CmdL.FileList + 1; *I != 0; I++) + std::list mods; + mods.push_back(APT::PackageSet::Modifier(0, ",", APT::PackageSet::Modifier::POSTFIX)); + mods.push_back(APT::PackageSet::Modifier(1, "^", APT::PackageSet::Modifier::POSTFIX)); + std::map pkgsets = + APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0); + + for (APT::PackageSet::const_iterator Pkg = pkgsets[0].begin(); + Pkg != pkgsets[0].end(); ++Pkg) + Show[Pkg->ID] = ToShow; + for (APT::PackageSet::const_iterator Pkg = pkgsets[1].begin(); + Pkg != pkgsets[1].end(); ++Pkg) { - // Process per-package flags - string P = *I; - bool Force = false; - if (P.length() > 3) - { - if (P.end()[-1] == '^') - { - Force = true; - P.erase(P.end()-1); - } - - if (P.end()[-1] == ',') - P.erase(P.end()-1); - } - - // Locate the package - pkgCache::PkgIterator Pkg = Cache->FindPkg(P); - if (Pkg.end() == true) - { - _error->Warning(_("Unable to locate package %s"),*I); - continue; - } Show[Pkg->ID] = ToShow; - - if (Force == true) - Flags[Pkg->ID] |= ForceNR; + Flags[Pkg->ID] |= ForceNR; } - + // Little header cout << "graph: { title: \"packages\"" << endl << "xmax: 700 ymax: 700 x: 30 y: 30" << endl << @@ -1015,38 +1001,24 @@ bool Dotty(CommandLine &CmdL) ShapeMap[Pkg->ID] = 3; } } - + // Load the list of packages from the command line into the show list - for (const char **I = CmdL.FileList + 1; *I != 0; I++) + std::list mods; + mods.push_back(APT::PackageSet::Modifier(0, ",", APT::PackageSet::Modifier::POSTFIX)); + mods.push_back(APT::PackageSet::Modifier(1, "^", APT::PackageSet::Modifier::POSTFIX)); + std::map pkgsets = + APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0); + + for (APT::PackageSet::const_iterator Pkg = pkgsets[0].begin(); + Pkg != pkgsets[0].end(); ++Pkg) + Show[Pkg->ID] = ToShow; + for (APT::PackageSet::const_iterator Pkg = pkgsets[1].begin(); + Pkg != pkgsets[1].end(); ++Pkg) { - // Process per-package flags - string P = *I; - bool Force = false; - if (P.length() > 3) - { - if (P.end()[-1] == '^') - { - Force = true; - P.erase(P.end()-1); - } - - if (P.end()[-1] == ',') - P.erase(P.end()-1); - } - - // Locate the package - pkgCache::PkgIterator Pkg = Cache->FindPkg(P); - if (Pkg.end() == true) - { - _error->Warning(_("Unable to locate package %s"),*I); - continue; - } Show[Pkg->ID] = ToShow; - - if (Force == true) - Flags[Pkg->ID] |= ForceNR; + Flags[Pkg->ID] |= ForceNR; } - + // Little header printf("digraph packages {\n"); printf("concentrate=true;\n"); -- cgit v1.2.3 From 1ddb859611d2e0f3d9ea12085001810f689e8c99 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 8 Jun 2010 19:27:49 +0200 Subject: * apt-pkg/indexrecords.cc: - backport forgotten Valid-Until patch from the obsolete experimental branch to prevent replay attacks better, thanks to Thomas Viehmann for the initial patch! (Closes: #499897) --- apt-pkg/acquire-item.cc | 12 ++++++- apt-pkg/indexrecords.cc | 38 ++++++++++++++++++++-- apt-pkg/indexrecords.h | 4 +++ debian/changelog | 4 +++ test/pre-upload-check.py | 14 ++++++++ .../sources.list.all-validuntil-broken | 1 + 6 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 test/testsources.list/sources.list.all-validuntil-broken diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index c035b916..4a846804 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -33,6 +33,7 @@ #include #include #include +#include /*}}}*/ using namespace std; @@ -1177,6 +1178,15 @@ bool pkgAcqMetaIndex::VerifyVendor(string Message) /*{{{*/ Transformed = ""; } + if (_config->FindB("Acquire::Check-Valid-Until", true)) { + if (MetaIndexParser->GetValidUntil() > 0 && + time(NULL) > MetaIndexParser->GetValidUntil()) { + return _error->Error(_("Release file expired, ignoring %s (valid until %s)"), + RealURI.c_str(), + TimeRFC1123(MetaIndexParser->GetValidUntil()).c_str()); + } + } + if (_config->FindB("Debug::pkgAcquire::Auth", false)) { std::cerr << "Got Codename: " << MetaIndexParser->GetDist() << std::endl; @@ -1194,7 +1204,7 @@ bool pkgAcqMetaIndex::VerifyVendor(string Message) /*{{{*/ // return false; if (!Transformed.empty()) { - _error->Warning("Conflicting distribution: %s (expected %s but got %s)", + _error->Warning(_("Conflicting distribution: %s (expected %s but got %s)"), Desc.Description.c_str(), Transformed.c_str(), MetaIndexParser->GetDist().c_str()); diff --git a/apt-pkg/indexrecords.cc b/apt-pkg/indexrecords.cc index 1fc27b1a..24ed02ba 100644 --- a/apt-pkg/indexrecords.cc +++ b/apt-pkg/indexrecords.cc @@ -7,8 +7,11 @@ #include #include #include +#include #include #include +#include + /*}}}*/ string indexRecords::GetDist() const { @@ -26,6 +29,11 @@ string indexRecords::GetExpectedDist() const return this->ExpectedDist; } +time_t indexRecords::GetValidUntil() const +{ + return this->ValidUntil; +} + const indexRecords::checkSum *indexRecords::Lookup(const string MetaKey) { return Entries[MetaKey]; @@ -82,7 +90,33 @@ bool indexRecords::Load(const string Filename) /*{{{*/ return false; } - string Strdate = Section.FindS("Date"); // FIXME: verify this somehow? + string Label = Section.FindS("Label"); + string StrDate = Section.FindS("Date"); + string StrValidUntil = Section.FindS("Valid-Until"); + + // if we have a Valid-Until header, use it + if (!StrValidUntil.empty()) + { + // set ValidUntil based on the information in the Release file + if(!StrToTime(StrValidUntil, ValidUntil)) + { + ErrorText = _(("Invalid 'Valid-Until' entry in Release file " + Filename).c_str()); + return false; + } + } else { + // if we don't have a valid-until string, check if we have a default + if (!Label.empty()) + { + int MaxAge = _config->FindI(string("apt::acquire::max-default-age::"+Label).c_str(),0); + if(MaxAge > 0 && !StrToTime(StrDate, ValidUntil)) + { + ErrorText = _(("Invalid 'Date' entry in Release file " + Filename).c_str()); + return false; + } + ValidUntil += 24*60*60*MaxAge; + } + } + return true; } /*}}}*/ @@ -160,6 +194,6 @@ indexRecords::indexRecords() } indexRecords::indexRecords(const string ExpectedDist) : - ExpectedDist(ExpectedDist) + ExpectedDist(ExpectedDist), ValidUntil(0) { } diff --git a/apt-pkg/indexrecords.h b/apt-pkg/indexrecords.h index 468d2bd0..500cf23c 100644 --- a/apt-pkg/indexrecords.h +++ b/apt-pkg/indexrecords.h @@ -12,6 +12,7 @@ #include #include +#include class indexRecords { @@ -25,6 +26,8 @@ class indexRecords string Dist; string Suite; string ExpectedDist; + time_t ValidUntil; + std::map Entries; public: @@ -38,6 +41,7 @@ class indexRecords virtual bool Load(string Filename); string GetDist() const; + time_t GetValidUntil() const; virtual bool CheckDist(const string MaybeDist) const; string GetExpectedDist() const; virtual ~indexRecords(){}; diff --git a/debian/changelog b/debian/changelog index 3771ca41..d8fb5775 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,10 @@ apt (0.7.26~exp5) experimental; urgency=low [ David Kalnischkies ] + * apt-pkg/indexrecords.cc: + - backport forgotten Valid-Until patch from the obsolete experimental + branch to prevent replay attacks better, thanks to Thomas Viehmann + for the initial patch! (Closes: #499897) * cmdline/apt-get.cc: - rerun dpkg-source in source if --fix-broken is given (Closes: #576752) - don't suggest held packages as they are installed (Closes: #578135) diff --git a/test/pre-upload-check.py b/test/pre-upload-check.py index 268b3d67..e2dfecbd 100755 --- a/test/pre-upload-check.py +++ b/test/pre-upload-check.py @@ -95,6 +95,20 @@ class testAuthentication(unittest.TestCase): self.assert_(len(glob.glob("/var/lib/apt/lists/partial/*")) == 0, "partial/ dir has leftover files: %s" % glob.glob("/var/lib/apt/lists/partial/*")) + def testValid(self): + for f in glob.glob("testsources.list/sources.list*validuntil*"): + self._cleanup() + (prefix, testtype, result) = f.split("-") + expected_res = self._expectedRes(result) + cmd = ["update"] + res = call([self.apt,"-o","Dir::Etc::sourcelist=./%s" % f]+cmd+apt_args, + stdout=stdout, stderr=stderr) + self.assert_(res == expected_res, + "test '%s' failed (got %s expected %s" % (f,res,expected_res)) + if expected_res == 0: + self.assert_(len(glob.glob("/var/lib/apt/lists/partial/*")) == 0, + "partial/ dir has leftover files: %s" % glob.glob("/var/lib/apt/lists/partial/*")) + class testLocalRepositories(unittest.TestCase): " test local repository regressions " diff --git a/test/testsources.list/sources.list.all-validuntil-broken b/test/testsources.list/sources.list.all-validuntil-broken new file mode 100644 index 00000000..bab59bb8 --- /dev/null +++ b/test/testsources.list/sources.list.all-validuntil-broken @@ -0,0 +1 @@ +deb http://people.ubuntu.com/~mvo/apt/auth-test-suit/all-validuntil-broken/ / -- cgit v1.2.3 From cd8cf88f0e64e222e9fdcbf86e6cbbe09306040e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 8 Jun 2010 22:46:42 +0200 Subject: * apt-pkg/contrib/strutl.cc: - split StrToTime() into HTTP1.1 and FTP date parser methods and use strptime() instead of some selfmade scanf mangling --- apt-pkg/contrib/strutl.cc | 36 ++++++++++++++++++++++++++++++++++++ apt-pkg/contrib/strutl.h | 4 +++- debian/changelog | 3 +++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index c7d63ce8..96e8143e 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -855,6 +855,42 @@ static time_t timegm(struct tm *t) } #endif /*}}}*/ +// FullDateToTime - Converts a HTTP1.1 full date strings into a time_t /*{{{*/ +// --------------------------------------------------------------------- +/* tries to parses a full date as specified in RFC2616 Section 3.3.1 + with one exception: All timezones (%Z) are accepted but the protocol + says that it MUST be GMT, but this one is equal to UTC which we will + encounter from time to time (e.g. in Release files) so we accept all + here and just assume it is GMT (or UTC) later on */ +bool RFC1123StrToTime(const char* const str,time_t &time) +{ + struct tm Tm; + // Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 + if (strptime(str, "%a, %d %b %Y %H:%M:%S %Z", &Tm) == NULL && + // Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 + strptime(str, "%A, %d-%b-%y %H:%M:%S %Z", &Tm) == NULL && + // Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format + strptime(str, "%a %b %d %H:%M:%S %Y", &Tm) == NULL) + return false; + + time = timegm(&Tm); + return true; +} + /*}}}*/ +// FTPMDTMStrToTime - Converts a ftp modification date into a time_t /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool FTPMDTMStrToTime(const char* const str,time_t &time) +{ + struct tm Tm; + // MDTM includes no whitespaces but recommend and ignored by strptime + if (strptime(str, "%Y %m %d %H %M %S", &Tm) == NULL) + return false; + + time = timegm(&Tm); + return true; +} + /*}}}*/ // StrToTime - Converts a string into a time_t /*{{{*/ // --------------------------------------------------------------------- /* This handles all 3 populare time formats including RFC 1123, RFC 1036 diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index e509145f..b5de0802 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -45,7 +45,9 @@ string Base64Encode(const string &Str); string OutputInDepth(const unsigned long Depth, const char* Separator=" "); string URItoFileName(const string &URI); string TimeRFC1123(time_t Date); -bool StrToTime(const string &Val,time_t &Result); +bool RFC1123StrToTime(const char* const str,time_t &time) __attrib_const; +bool FTPMDTMStrToTime(const char* const str,time_t &time) __attrib_const; +__deprecated bool StrToTime(const string &Val,time_t &Result); string LookupTag(const string &Message,const char *Tag,const char *Default = 0); int StringToBool(const string &Text,int Default = -1); bool ReadMessages(int Fd, vector &List); diff --git a/debian/changelog b/debian/changelog index d8fb5775..2a40d084 100644 --- a/debian/changelog +++ b/debian/changelog @@ -44,6 +44,9 @@ apt (0.7.26~exp5) experimental; urgency=low - add 'disappear' to the known processing states, thanks Jonathan Nieder * apt-pkg/packagemanager.h: - export info about disappeared packages with GetDisappearedPackages() + * apt-pkg/contrib/strutl.cc: + - split StrToTime() into HTTP1.1 and FTP date parser methods and + use strptime() instead of some selfmade scanf mangling [ Michael Vogt ] * methods/http.{cc,h}: -- cgit v1.2.3 From 0323317c08c0b08bf0ba1ac37a37a8de333cdb40 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 8 Jun 2010 22:55:42 +0200 Subject: enhance the Valid-Until code a bit by using the correct RFC1123StrToTime method and allow for better translations of the error messages --- apt-pkg/acquire-item.cc | 16 +++++++++------- apt-pkg/indexrecords.cc | 24 ++++++++++++------------ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 4a846804..ac84c2e5 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -1178,13 +1178,15 @@ bool pkgAcqMetaIndex::VerifyVendor(string Message) /*{{{*/ Transformed = ""; } - if (_config->FindB("Acquire::Check-Valid-Until", true)) { - if (MetaIndexParser->GetValidUntil() > 0 && - time(NULL) > MetaIndexParser->GetValidUntil()) { - return _error->Error(_("Release file expired, ignoring %s (valid until %s)"), - RealURI.c_str(), - TimeRFC1123(MetaIndexParser->GetValidUntil()).c_str()); - } + if (_config->FindB("Acquire::Check-Valid-Until", true) == true && + MetaIndexParser->GetValidUntil() > 0) { + time_t const invalid_since = time(NULL) - MetaIndexParser->GetValidUntil(); + if (invalid_since > 0) + // TRANSLATOR: The first %s is the URL of the bad Release file, the second is + // the time since then the file is invalid - formated in the same way as in + // the download progress display (e.g. 7d 3h 42min 1s) + return _error->Error(_("Release file expired, ignoring %s (invalid since %s)"), + RealURI.c_str(), TimeToStr(invalid_since).c_str()); } if (_config->FindB("Debug::pkgAcquire::Auth", false)) diff --git a/apt-pkg/indexrecords.cc b/apt-pkg/indexrecords.cc index 24ed02ba..1312e681 100644 --- a/apt-pkg/indexrecords.cc +++ b/apt-pkg/indexrecords.cc @@ -91,30 +91,30 @@ bool indexRecords::Load(const string Filename) /*{{{*/ } string Label = Section.FindS("Label"); - string StrDate = Section.FindS("Date"); + string StrDate = Section.FindS("Date"); string StrValidUntil = Section.FindS("Valid-Until"); // if we have a Valid-Until header, use it - if (!StrValidUntil.empty()) + if (StrValidUntil.empty() == false) { // set ValidUntil based on the information in the Release file - if(!StrToTime(StrValidUntil, ValidUntil)) + if(RFC1123StrToTime(StrValidUntil.c_str(), ValidUntil) == false) { - ErrorText = _(("Invalid 'Valid-Until' entry in Release file " + Filename).c_str()); + strprintf(ErrorText, _("Invalid 'Valid-Until' entry in Release file %s"), Filename.c_str()); return false; } } else { // if we don't have a valid-until string, check if we have a default - if (!Label.empty()) + int MaxAge = _config->FindI("APT::Acquire::Max-Default-Age", 0); + if (Label.empty() == true) + MaxAge = _config->FindI(string("APT::Acquire::Max-Default-Age::"+Label).c_str(), MaxAge); + + if(MaxAge > 0 && RFC1123StrToTime(StrDate.c_str(), ValidUntil) == false) { - int MaxAge = _config->FindI(string("apt::acquire::max-default-age::"+Label).c_str(),0); - if(MaxAge > 0 && !StrToTime(StrDate, ValidUntil)) - { - ErrorText = _(("Invalid 'Date' entry in Release file " + Filename).c_str()); - return false; - } - ValidUntil += 24*60*60*MaxAge; + strprintf(ErrorText, _("Invalid 'Date' entry in Release file %s"), Filename.c_str()); + return false; } + ValidUntil += 24*60*60*MaxAge; } return true; -- cgit v1.2.3 From bbde96a611f39f5040b332dae1515207db341743 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 8 Jun 2010 23:38:34 +0200 Subject: use the Valid-Until header from the Release file but if the user provides a setting in the configuration prefer the date which is earlier. --- apt-pkg/indexrecords.cc | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/apt-pkg/indexrecords.cc b/apt-pkg/indexrecords.cc index 1312e681..cdc2897b 100644 --- a/apt-pkg/indexrecords.cc +++ b/apt-pkg/indexrecords.cc @@ -88,34 +88,39 @@ bool indexRecords::Load(const string Filename) /*{{{*/ { strprintf(ErrorText, _("No Hash entry in Release file %s"), Filename.c_str()); return false; - } + } string Label = Section.FindS("Label"); string StrDate = Section.FindS("Date"); string StrValidUntil = Section.FindS("Valid-Until"); - // if we have a Valid-Until header, use it + // if we have a Valid-Until header in the Release file, use it as default if (StrValidUntil.empty() == false) { - // set ValidUntil based on the information in the Release file if(RFC1123StrToTime(StrValidUntil.c_str(), ValidUntil) == false) { strprintf(ErrorText, _("Invalid 'Valid-Until' entry in Release file %s"), Filename.c_str()); return false; } - } else { - // if we don't have a valid-until string, check if we have a default - int MaxAge = _config->FindI("APT::Acquire::Max-Default-Age", 0); - if (Label.empty() == true) - MaxAge = _config->FindI(string("APT::Acquire::Max-Default-Age::"+Label).c_str(), MaxAge); + } + // get the user settings for this archive and use what expires earlier + int MaxAge = _config->FindI("APT::Acquire::Max-Default-Age", 0); + if (Label.empty() == true) + MaxAge = _config->FindI(string("APT::Acquire::Max-Default-Age::" + Label).c_str(), MaxAge); - if(MaxAge > 0 && RFC1123StrToTime(StrDate.c_str(), ValidUntil) == false) - { - strprintf(ErrorText, _("Invalid 'Date' entry in Release file %s"), Filename.c_str()); - return false; - } - ValidUntil += 24*60*60*MaxAge; + if(MaxAge == 0) // No user settings, use the one from the Release file + return true; + + time_t date; + if (RFC1123StrToTime(StrDate.c_str(), date) == false) + { + strprintf(ErrorText, _("Invalid 'Date' entry in Release file %s"), Filename.c_str()); + return false; } + date += 24*60*60*MaxAge; + + if (ValidUntil == 0 || ValidUntil > date) + ValidUntil = date; return true; } -- cgit v1.2.3 From c99e48ec26e693d9aa4a2a9f868284f7aa49784d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 9 Jun 2010 00:12:14 +0200 Subject: * ftparchive/writer.cc: - add ValidTime option to generate a Valid-Until header in Release file --- debian/changelog | 2 ++ doc/apt-ftparchive.1.xml | 3 ++- ftparchive/writer.cc | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 2a40d084..fa0e667e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -47,6 +47,8 @@ apt (0.7.26~exp5) experimental; urgency=low * apt-pkg/contrib/strutl.cc: - split StrToTime() into HTTP1.1 and FTP date parser methods and use strptime() instead of some selfmade scanf mangling + * ftparchive/writer.cc: + - add ValidTime option to generate a Valid-Until header in Release file [ Michael Vogt ] * methods/http.{cc,h}: diff --git a/doc/apt-ftparchive.1.xml b/doc/apt-ftparchive.1.xml index a3ac45bd..549aa6a3 100644 --- a/doc/apt-ftparchive.1.xml +++ b/doc/apt-ftparchive.1.xml @@ -122,7 +122,8 @@ e.g. APT::FTPArchive::Release::Origin. The supported fields are: Origin, Label, Suite, Version, Codename, Date, - Architectures, Components, Description. + Valid-Until, Architectures, + Components, Description. diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index 6cda29b2..650eec57 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -924,6 +924,15 @@ ReleaseWriter::ReleaseWriter(string const &DB) datestr[0] = '\0'; } + time_t const validuntil = now + _config->FindI("APT::FTPArchive::Release::ValidTime", 0); + char validstr[128]; + if (now == validuntil || + strftime(validstr, sizeof(validstr), "%a, %d %b %Y %H:%M:%S UTC", + gmtime(&validuntil)) == 0) + { + datestr[0] = '\0'; + } + map Fields; Fields["Origin"] = ""; Fields["Label"] = ""; @@ -931,6 +940,7 @@ ReleaseWriter::ReleaseWriter(string const &DB) Fields["Version"] = ""; Fields["Codename"] = ""; Fields["Date"] = datestr; + Fields["Valid-Until"] = validstr; Fields["Architectures"] = ""; Fields["Components"] = ""; Fields["Description"] = ""; -- cgit v1.2.3 From 550891457ff63db01b57d9057a5fe447a165e10c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 9 Jun 2010 00:27:22 +0200 Subject: use the portable timegm shown in his manpage instead of a strange looking code copycat from wget --- apt-pkg/contrib/strutl.cc | 36 ++++++++++++++++-------------------- debian/changelog | 2 ++ 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 96e8143e..16045036 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -827,31 +827,27 @@ static int MonthConv(char *Month) } } /*}}}*/ -// timegm - Internal timegm function if gnu is not available /*{{{*/ +// timegm - Internal timegm if the gnu version is not available /*{{{*/ // --------------------------------------------------------------------- -/* Ripped this evil little function from wget - I prefer the use of - GNU timegm if possible as this technique will have interesting problems - with leap seconds, timezones and other. - - Converts struct tm to time_t, assuming the data in tm is UTC rather +/* Converts struct tm to time_t, assuming the data in tm is UTC rather than local timezone (mktime assumes the latter). - - Contributed by Roger Beeman , with the help of - Mark Baushke and the rest of the Gurus at CISCO. */ - -/* Turned it into an autoconf check, because GNU is not the only thing which - can provide timegm. -- 2002-09-22, Joel Baker */ -#ifndef HAVE_TIMEGM // Now with autoconf! + This function is a nonstandard GNU extension that is also present on + the BSDs and maybe other systems. For others we follow the advice of + the manpage of timegm and use his portable replacement. */ +#ifndef HAVE_TIMEGM static time_t timegm(struct tm *t) { - time_t tl, tb; - - tl = mktime (t); - if (tl == -1) - return -1; - tb = mktime (gmtime (&tl)); - return (tl <= tb ? (tl + (tl - tb)) : (tl - (tb - tl))); + char *tz = getenv("TZ"); + setenv("TZ", "", 1); + tzset(); + time_t ret = mktime(t); + if (tz) + setenv("TZ", tz, 1); + else + unsetenv("TZ"); + tzset(); + return ret; } #endif /*}}}*/ diff --git a/debian/changelog b/debian/changelog index fa0e667e..04999923 100644 --- a/debian/changelog +++ b/debian/changelog @@ -47,6 +47,8 @@ apt (0.7.26~exp5) experimental; urgency=low * apt-pkg/contrib/strutl.cc: - split StrToTime() into HTTP1.1 and FTP date parser methods and use strptime() instead of some selfmade scanf mangling + - use the portable timegm shown in his manpage instead of a strange + looking code copycat from wget * ftparchive/writer.cc: - add ValidTime option to generate a Valid-Until header in Release file -- cgit v1.2.3 From 96cc64a521957d63704de72ed95f1c839698c53c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 9 Jun 2010 00:53:44 +0200 Subject: move the users away from the deprecated StrToTime() method --- apt-pkg/acquire-method.cc | 2 +- apt-pkg/contrib/strutl.h | 4 ++-- methods/ftp.cc | 3 +-- methods/http.cc | 2 +- methods/rsh.cc | 3 +-- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/apt-pkg/acquire-method.cc b/apt-pkg/acquire-method.cc index fe066741..b82dceec 100644 --- a/apt-pkg/acquire-method.cc +++ b/apt-pkg/acquire-method.cc @@ -373,7 +373,7 @@ int pkgAcqMethod::Run(bool Single) Tmp->Uri = LookupTag(Message,"URI"); Tmp->DestFile = LookupTag(Message,"FileName"); - if (StrToTime(LookupTag(Message,"Last-Modified"),Tmp->LastModified) == false) + if (RFC1123StrToTime(LookupTag(Message,"Last-Modified").c_str(),Tmp->LastModified) == false) Tmp->LastModified = 0; Tmp->IndexFile = StringToBool(LookupTag(Message,"Index-File"),false); Tmp->Next = 0; diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index b5de0802..a457ff04 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -45,8 +45,8 @@ string Base64Encode(const string &Str); string OutputInDepth(const unsigned long Depth, const char* Separator=" "); string URItoFileName(const string &URI); string TimeRFC1123(time_t Date); -bool RFC1123StrToTime(const char* const str,time_t &time) __attrib_const; -bool FTPMDTMStrToTime(const char* const str,time_t &time) __attrib_const; +bool RFC1123StrToTime(const char* const str,time_t &time) __must_check; +bool FTPMDTMStrToTime(const char* const str,time_t &time) __must_check; __deprecated bool StrToTime(const string &Val,time_t &Result); string LookupTag(const string &Message,const char *Tag,const char *Default = 0); int StringToBool(const string &Text,int Default = -1); diff --git a/methods/ftp.cc b/methods/ftp.cc index 3e172582..97248f90 100644 --- a/methods/ftp.cc +++ b/methods/ftp.cc @@ -661,8 +661,7 @@ bool FTPConn::ModTime(const char *Path, time_t &Time) return true; // Parse it - StrToTime(Msg,Time); - return true; + return FTPMDTMStrToTime(Msg.c_str(), Time); } /*}}}*/ // FTPConn::CreateDataFd - Get a data connection /*{{{*/ diff --git a/methods/http.cc b/methods/http.cc index d43dd14c..5fdc6269 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -631,7 +631,7 @@ bool ServerState::HeaderLine(string Line) if (stringcasecmp(Tag,"Last-Modified:") == 0) { - if (StrToTime(Val,Date) == false) + if (RFC1123StrToTime(Val.c_str(), Date) == false) return _error->Error(_("Unknown date format")); return true; } diff --git a/methods/rsh.cc b/methods/rsh.cc index f0ccfc42..97b4ef15 100644 --- a/methods/rsh.cc +++ b/methods/rsh.cc @@ -278,8 +278,7 @@ bool RSHConn::ModTime(const char *Path, time_t &Time) return false; // Parse it - StrToTime(Msg,Time); - return true; + return FTPMDTMStrToTime(Msg.c_str(), Time); } /*}}}*/ // RSHConn::Get - Get a file /*{{{*/ -- cgit v1.2.3 From b02fffa64833e1f8e2617669d89de0a6d0882747 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 9 Jun 2010 10:46:35 +0200 Subject: rename the options, document them and reorder the changelog a bit --- apt-pkg/indexrecords.cc | 4 ++-- debian/changelog | 24 ++++++++++++++++-------- doc/apt.conf.5.xml | 24 ++++++++++++++++++++++++ doc/examples/configure-index | 4 ++++ 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/apt-pkg/indexrecords.cc b/apt-pkg/indexrecords.cc index cdc2897b..3bde7437 100644 --- a/apt-pkg/indexrecords.cc +++ b/apt-pkg/indexrecords.cc @@ -104,9 +104,9 @@ bool indexRecords::Load(const string Filename) /*{{{*/ } } // get the user settings for this archive and use what expires earlier - int MaxAge = _config->FindI("APT::Acquire::Max-Default-Age", 0); + int MaxAge = _config->FindI("Acquire::Max-ValidTime", 0); if (Label.empty() == true) - MaxAge = _config->FindI(string("APT::Acquire::Max-Default-Age::" + Label).c_str(), MaxAge); + MaxAge = _config->FindI(string("Acquire::Max-ValidTime::" + Label).c_str(), MaxAge); if(MaxAge == 0) // No user settings, use the one from the Release file return true; diff --git a/debian/changelog b/debian/changelog index 04999923..c3f7a3e2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,10 +1,25 @@ -apt (0.7.26~exp5) experimental; urgency=low +apt (0.7.26~exp6) UNRELEASED; urgency=low [ David Kalnischkies ] + * doc/apt.conf.5.xml: + - document the new Valid-Until related options * apt-pkg/indexrecords.cc: - backport forgotten Valid-Until patch from the obsolete experimental branch to prevent replay attacks better, thanks to Thomas Viehmann for the initial patch! (Closes: #499897) + * apt-pkg/contrib/strutl.cc: + - split StrToTime() into HTTP1.1 and FTP date parser methods and + use strptime() instead of some self-made scanf mangling + - use the portable timegm shown in his manpage instead of a strange + looking code copycat from wget + * ftparchive/writer.cc: + - add ValidTime option to generate a Valid-Until header in Release file + + -- David Kalnischkies Wed, 09 Jun 2010 10:43:58 +0200 + +apt (0.7.26~exp5) experimental; urgency=low + + [ David Kalnischkies ] * cmdline/apt-get.cc: - rerun dpkg-source in source if --fix-broken is given (Closes: #576752) - don't suggest held packages as they are installed (Closes: #578135) @@ -44,13 +59,6 @@ apt (0.7.26~exp5) experimental; urgency=low - add 'disappear' to the known processing states, thanks Jonathan Nieder * apt-pkg/packagemanager.h: - export info about disappeared packages with GetDisappearedPackages() - * apt-pkg/contrib/strutl.cc: - - split StrToTime() into HTTP1.1 and FTP date parser methods and - use strptime() instead of some selfmade scanf mangling - - use the portable timegm shown in his manpage instead of a strange - looking code copycat from wget - * ftparchive/writer.cc: - - add ValidTime option to generate a Valid-Until header in Release file [ Michael Vogt ] * methods/http.{cc,h}: diff --git a/doc/apt.conf.5.xml b/doc/apt.conf.5.xml index fe005e0f..0cf4bb66 100644 --- a/doc/apt.conf.5.xml +++ b/doc/apt.conf.5.xml @@ -230,6 +230,30 @@ DPkg::Pre-Install-Pkgs {"/usr/sbin/dpkg-preconfigure --apt";}; and the URI handlers. + Check-Valid-Until + Security related option defaulting to true as an + expiring validation for a Release file prevents longtime replay attacks + and can e.g. also help users to identify no longer updated mirrors - + but the feature depends on the correctness of the time on the user system. + Archive maintainers are encouraged to create Release files with the + Valid-Until header, but if they don't or a stricter value + is volitional the following Max-ValidTime option can be used. + + + + Max-ValidTime + Seconds the Release file should be considered valid after + it was created. The default is "for ever" (0) if the Release file of the + archive doesn't include a Valid-Until header. + If it does then this date is the default. The date from the Release file or + the date specified by the creation time of the Release file + (Date header) plus the seconds specified with this + options are used to check if the validation of a file has expired by using + the earlier date of the two. Archive specific settings can be made by + appending the label of the archive to the option name. + + + PDiffs Try to download deltas called PDiffs for Packages or Sources files instead of downloading whole ones. True diff --git a/doc/examples/configure-index b/doc/examples/configure-index index d168417d..127feb9e 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -176,6 +176,10 @@ Acquire PDiffs::SizeLimit "50"; // don't use diffs if size of all patches excess // 50% of the size of the original file + Check-Valid-Until "true"; + Max-ValidTime "864000"; // 10 days + Max-ValidTime::Debian-Security "604800"; // 7 days, label specific configuration + // HTTP method configuration http { -- cgit v1.2.3