From 8881b11eacd735148d087c8c0f53827cb537b582 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 11 Jun 2015 16:40:45 +0200 Subject: implement 'apt-get files' to access index targets Downloading additional files is only half the job. We still need a way to allow external tools to know where the files are they requested for download given that we don't want them to choose their own location. 'apt-get files' is our answer to this showing by default in a deb822 format information about each IndexTarget with the potential to filter the records based on lines and an option to change the output format. The command serves also as an example on how to get to this information via libapt. --- apt-private/private-cmndline.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'apt-private') diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index 41aab81f6..458051bf2 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -163,6 +163,10 @@ static bool addArgumentsAPTGet(std::vector &Args, char const // once sbuild is fixed, this option can be removed addArg('f', "fix-broken", "APT::Get::Fix-Broken", 0); } + else if (CmdMatches("files")) + { + addArg(0,"format","APT::Get::Files::Format", CommandLine::HasArg); + } else if (CmdMatches("clean", "autoclean", "check", "download", "changelog") || CmdMatches("markauto", "unmarkauto")) // deprecated commands ; -- cgit v1.2.3 From 3fd89e62e985c89b1f9a545ab72c20987b756aff Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 12 Jun 2015 12:06:29 +0200 Subject: implement default apt-get file --release-info mode Selecting targets based on the Release they belong to isn't to unrealistic. In fact, it is assumed to be the most used case so it is made the default especially as this allows to bundle another thing we have to be careful with: Filenames and only showing targets we have acquired. Closes: 752702 --- apt-private/private-cmndline.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'apt-private') diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index 458051bf2..11e88b1e7 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -166,6 +166,7 @@ static bool addArgumentsAPTGet(std::vector &Args, char const else if (CmdMatches("files")) { addArg(0,"format","APT::Get::Files::Format", CommandLine::HasArg); + addArg(0,"release-info","APT::Get::Files::ReleaseInfo", 0); } else if (CmdMatches("clean", "autoclean", "check", "download", "changelog") || CmdMatches("markauto", "unmarkauto")) // deprecated commands -- cgit v1.2.3 From 1eb1836f4b5397497bd34f0cf516e6e4e73117bf Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 15 Jun 2015 16:41:43 +0200 Subject: show item ID in Hit, Ign and Err lines as well Again, consistency is the main sellingpoint here, but this way it is now also easier to explain that some files move through different stages and lines are printed for them hence multiple times: That is a bit hard to believe if the number is changing all the time, but now that it keeps consistent. --- apt-private/acqprogress.cc | 38 +++++++++++++++++++++++++++++--------- apt-private/acqprogress.h | 3 ++- 2 files changed, 31 insertions(+), 10 deletions(-) (limited to 'apt-private') diff --git a/apt-private/acqprogress.cc b/apt-private/acqprogress.cc index 0c606e48e..dc92e3b2a 100644 --- a/apt-private/acqprogress.cc +++ b/apt-private/acqprogress.cc @@ -49,6 +49,16 @@ void AcqTextStatus::Start() ID = 1; } /*}}}*/ +void AcqTextStatus::AssignItemID(pkgAcquire::ItemDesc &Itm) /*{{{*/ +{ + /* In theory calling it from Fetch() would be enough, but to be + safe we call it from IMSHit and Fail as well. + Also, an Item can pass through multiple stages, so ensure + that it keeps the same number */ + if (Itm.Owner->ID == 0) + Itm.Owner->ID = ID++; +} + /*}}}*/ // AcqTextStatus::IMSHit - Called when an item got a HIT response /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -57,9 +67,11 @@ void AcqTextStatus::IMSHit(pkgAcquire::ItemDesc &Itm) if (Quiet > 1) return; + AssignItemID(Itm); clearLastLine(); - out << _("Hit ") << Itm.Description; + // TRANSLATOR: Very short word to be displayed before unchanged files in 'apt-get update' + ioprintf(out, _("Hit:%lu %s"), Itm.Owner->ID, Itm.Description.c_str()); out << std::endl; Update = true; } @@ -72,15 +84,16 @@ void AcqTextStatus::Fetch(pkgAcquire::ItemDesc &Itm) Update = true; if (Itm.Owner->Complete == true) return; - - Itm.Owner->ID = ID++; + AssignItemID(Itm); if (Quiet > 1) return; clearLastLine(); - out << _("Get:") << Itm.Owner->ID << ' ' << Itm.Description; + // TRANSLATOR: Very short word to be displayed for files processed in 'apt-get update' + // Potentially replaced later by "Hit:", "Ign:" or "Err:" if something (bad) happens + ioprintf(out, _("Get:%lu %s"), Itm.Owner->ID, Itm.Description.c_str()); if (Itm.Owner->FileSize != 0) out << " [" << SizeToStr(Itm.Owner->FileSize) << "B]"; out << std::endl; @@ -89,9 +102,10 @@ void AcqTextStatus::Fetch(pkgAcquire::ItemDesc &Itm) // AcqTextStatus::Done - Completed a download /*{{{*/ // --------------------------------------------------------------------- /* We don't display anything... */ -void AcqTextStatus::Done(pkgAcquire::ItemDesc &/*Itm*/) +void AcqTextStatus::Done(pkgAcquire::ItemDesc &Itm) { Update = true; + AssignItemID(Itm); } /*}}}*/ // AcqTextStatus::Fail - Called when an item fails to download /*{{{*/ @@ -106,19 +120,25 @@ void AcqTextStatus::Fail(pkgAcquire::ItemDesc &Itm) if (Itm.Owner->Status == pkgAcquire::Item::StatIdle) return; + AssignItemID(Itm); clearLastLine(); if (Itm.Owner->Status == pkgAcquire::Item::StatDone) { - out << _("Ign ") << Itm.Description << std::endl; + // TRANSLATOR: Very short word to be displayed for files in 'apt-get update' + // which failed to download, but the error is ignored (compare "Err:") + ioprintf(out, _("Ign:%lu %s"), Itm.Owner->ID, Itm.Description.c_str()); if (Itm.Owner->ErrorText.empty() == false && _config->FindB("Acquire::Progress::Ignore::ShowErrorText", false) == true) - out << " " << Itm.Owner->ErrorText << std::endl; + out << std::endl << " " << Itm.Owner->ErrorText; + out << std::endl; } else { - out << _("Err ") << Itm.Description << std::endl; - out << " " << Itm.Owner->ErrorText << std::endl; + // TRANSLATOR: Very short word to be displayed for files in 'apt-get update' + // which failed to download and the error is critical (compare "Ign:") + ioprintf(out, _("Err:%lu %s"), Itm.Owner->ID, Itm.Description.c_str()); + out << std::endl << " " << Itm.Owner->ErrorText << std::endl; } Update = true; diff --git a/apt-private/acqprogress.h b/apt-private/acqprogress.h index 7cf990c65..cbb06fbec 100644 --- a/apt-private/acqprogress.h +++ b/apt-private/acqprogress.h @@ -23,7 +23,8 @@ class APT_PUBLIC AcqTextStatus : public pkgAcquireStatus unsigned long ID; unsigned long Quiet; - void clearLastLine(); + APT_HIDDEN void clearLastLine(); + APT_HIDDEN void AssignItemID(pkgAcquire::ItemDesc &Itm); public: -- cgit v1.2.3 From 9d2a8a7388cf3b0bbbe92f6b0b30a533e1167f40 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 15 Jun 2015 23:06:56 +0200 Subject: condense parallel requests with the same hashes to one It shouldn't be too common, but sometimes people have multiple mirrors in the sources or otherwise repositories with the same content. Now that we gracefully can handle multiple requests to the same URI, we can also fold multiple requests with the same expected hashes into one. Note that this isn't trying to find oppertunities for merging, but just merges if it happens to encounter the oppertunity for it. This is most obvious in the new testcase actually as it needs to delay the action to give the acquire system enough time to figure out that they can be merged. --- apt-private/acqprogress.cc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'apt-private') diff --git a/apt-private/acqprogress.cc b/apt-private/acqprogress.cc index dc92e3b2a..f6c3d1204 100644 --- a/apt-private/acqprogress.cc +++ b/apt-private/acqprogress.cc @@ -116,14 +116,10 @@ void AcqTextStatus::Fail(pkgAcquire::ItemDesc &Itm) if (Quiet > 1) return; - // Ignore certain kinds of transient failures (bad code) - if (Itm.Owner->Status == pkgAcquire::Item::StatIdle) - return; - AssignItemID(Itm); clearLastLine(); - if (Itm.Owner->Status == pkgAcquire::Item::StatDone) + if (Itm.Owner->Status == pkgAcquire::Item::StatDone || Itm.Owner->Status == pkgAcquire::Item::StatIdle) { // TRANSLATOR: Very short word to be displayed for files in 'apt-get update' // which failed to download, but the error is ignored (compare "Err:") -- cgit v1.2.3 From 3d8232bf97ce11818fb07813a71136484ea1a44a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 18 Jun 2015 17:33:15 +0200 Subject: fix memory leaks reported by -fsanitize Various small leaks here and there. Nothing particularily big, but still good to fix. Found by the sanitizers while running our testcases. Reported-By: gcc -fsanitize Git-Dch: Ignore --- apt-private/private-cacheset.h | 13 +++++++++---- apt-private/private-output.cc | 23 ++++++++++++++--------- 2 files changed, 23 insertions(+), 13 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-cacheset.h b/apt-private/private-cacheset.h index 059c7637e..0eb22b788 100644 --- a/apt-private/private-cacheset.h +++ b/apt-private/private-cacheset.h @@ -32,10 +32,15 @@ struct VersionSortDescriptionLocality bool operator () (const pkgCache::VerIterator &v_lhs, const pkgCache::VerIterator &v_rhs) { - pkgCache::DescFile *A = v_lhs.TranslatedDescription().FileList(); - pkgCache::DescFile *B = v_rhs.TranslatedDescription().FileList(); - if (A == 0 && B == 0) - return false; + pkgCache::DescFile const *A = NULL; + pkgCache::DescFile const *B = NULL; + if (v_lhs->DescriptionList != 0) + A = v_lhs.TranslatedDescription().FileList(); + if (v_rhs->DescriptionList != 0) + B = v_rhs.TranslatedDescription().FileList(); + + if (A == 0 && B == 0) + return false; if (A == 0) return true; diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 4e18030ab..9944ab002 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -199,10 +199,12 @@ static std::string GetShortDescription(pkgCacheFile &CacheFile, pkgRecords &reco std::string ShortDescription = "(none)"; if(ver) { - pkgCache::DescIterator Desc = ver.TranslatedDescription(); - pkgRecords::Parser & parser = records.Lookup(Desc.FileList()); - - ShortDescription = parser.ShortDesc(); + pkgCache::DescIterator const Desc = ver.TranslatedDescription(); + if (Desc.end() == false) + { + pkgRecords::Parser & parser = records.Lookup(Desc.FileList()); + ShortDescription = parser.ShortDesc(); + } } return ShortDescription; } @@ -222,11 +224,14 @@ static std::string GetLongDescription(pkgCacheFile &CacheFile, pkgRecords &recor return EmptyDescription; pkgCache::DescIterator const Desc = ver.TranslatedDescription(); - pkgRecords::Parser & parser = records.Lookup(Desc.FileList()); - std::string const longdesc = parser.LongDesc(); - if (longdesc.empty() == true) - return EmptyDescription; - return SubstVar(longdesc, "\n ", "\n "); + if (Desc.end() == false) + { + pkgRecords::Parser & parser = records.Lookup(Desc.FileList()); + std::string const longdesc = parser.LongDesc(); + if (longdesc.empty() == false) + return SubstVar(longdesc, "\n ", "\n "); + } + return EmptyDescription; } /*}}}*/ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/ -- cgit v1.2.3 From ffb081b79263a699a612583fcf1b9957b5900a77 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 8 Jul 2015 16:37:04 +0200 Subject: prepare cachesets for -std=c++11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "problem" is mostly in the erase() definitions as they slightly conflict and in pre-c++11 are not uniformly in different containers. By differenciating based on the standard we can provide erase() methods for both standards – and as the method is in a template and inline we don't need to worry about symbols here. The rest is adding wrappings for the new forward_list and unordered_set containers and correcting our iterators to use the same trait as the iterator they are wrapping instead of having all of them be simple forward iterators. This allows the use of specialized algorithms which are picked based on iterator_traits and implementing them all is simple to do as we can declare all methods easily and only if they are called they will generate errors (if the underlying iterator doesn't support these). Git-Dch: Ignore --- apt-private/private-install.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index acc6d42c2..3474d262a 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -419,7 +419,7 @@ static bool DoAutomaticRemove(CacheFile &Cache) bool Changed; do { Changed = false; - for (APT::PackageSet::const_iterator Pkg = tooMuch.begin(); + for (APT::PackageSet::iterator Pkg = tooMuch.begin(); Pkg != tooMuch.end(); ++Pkg) { APT::PackageSet too; -- cgit v1.2.3 From 3b3028467ceccca0b73a8f53051c0fa4de313111 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 9 Jul 2015 00:35:40 +0200 Subject: add c++11 override marker to overridden methods C++11 adds the 'override' specifier to mark that a method is overriding a base class method and error out if not. We hide it in the APT_OVERRIDE macro to ensure that we keep compiling in pre-c++11 standards. Reported-By: clang-modernize -add-override -override-macros Git-Dch: Ignore --- apt-private/acqprogress.h | 18 +++++++++--------- apt-private/private-cacheset.h | 16 ++++++++-------- apt-private/private-moo.h | 2 ++ 3 files changed, 19 insertions(+), 17 deletions(-) (limited to 'apt-private') diff --git a/apt-private/acqprogress.h b/apt-private/acqprogress.h index cbb06fbec..6b6d555b1 100644 --- a/apt-private/acqprogress.h +++ b/apt-private/acqprogress.h @@ -28,15 +28,15 @@ class APT_PUBLIC AcqTextStatus : public pkgAcquireStatus public: - virtual bool MediaChange(std::string Media,std::string Drive); - virtual void IMSHit(pkgAcquire::ItemDesc &Itm); - virtual void Fetch(pkgAcquire::ItemDesc &Itm); - virtual void Done(pkgAcquire::ItemDesc &Itm); - virtual void Fail(pkgAcquire::ItemDesc &Itm); - virtual void Start(); - virtual void Stop(); - - bool Pulse(pkgAcquire *Owner); + virtual bool MediaChange(std::string Media,std::string Drive) APT_OVERRIDE; + virtual void IMSHit(pkgAcquire::ItemDesc &Itm) APT_OVERRIDE; + virtual void Fetch(pkgAcquire::ItemDesc &Itm) APT_OVERRIDE; + virtual void Done(pkgAcquire::ItemDesc &Itm) APT_OVERRIDE; + virtual void Fail(pkgAcquire::ItemDesc &Itm) APT_OVERRIDE; + virtual void Start() APT_OVERRIDE; + virtual void Stop() APT_OVERRIDE; + + bool Pulse(pkgAcquire *Owner) APT_OVERRIDE; AcqTextStatus(std::ostream &out, unsigned int &ScreenWidth,unsigned int const Quiet); }; diff --git a/apt-private/private-cacheset.h b/apt-private/private-cacheset.h index 0eb22b788..518f179f3 100644 --- a/apt-private/private-cacheset.h +++ b/apt-private/private-cacheset.h @@ -81,13 +81,13 @@ class CacheSetHelperVirtuals: public APT::CacheSetHelper { public: APT::PackageSet virtualPkgs; - virtual pkgCache::VerIterator canNotGetVersion(enum CacheSetHelper::VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + virtual pkgCache::VerIterator canNotGetVersion(enum CacheSetHelper::VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE { if (select == NEWEST || select == CANDIDATE || select == ALL) virtualPkgs.insert(Pkg); return CacheSetHelper::canNotGetVersion(select, Cache, Pkg); } - virtual void canNotFindVersion(enum CacheSetHelper::VerSelector const select, APT::VersionContainerInterface * vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + virtual void canNotFindVersion(enum CacheSetHelper::VerSelector const select, APT::VersionContainerInterface * vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE { if (select == NEWEST || select == CANDIDATE || select == ALL) virtualPkgs.insert(Pkg); return CacheSetHelper::canNotFindVersion(select, vci, Cache, Pkg); @@ -113,23 +113,23 @@ public: explicitlyNamed = true; } - virtual void showTaskSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) { + virtual void showTaskSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) APT_OVERRIDE { ioprintf(out, _("Note, selecting '%s' for task '%s'\n"), Pkg.FullName(true).c_str(), pattern.c_str()); explicitlyNamed = false; } - virtual void showFnmatchSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) { + virtual void showFnmatchSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) APT_OVERRIDE { ioprintf(out, _("Note, selecting '%s' for glob '%s'\n"), Pkg.FullName(true).c_str(), pattern.c_str()); explicitlyNamed = false; } - virtual void showRegExSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) { + virtual void showRegExSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) APT_OVERRIDE { ioprintf(out, _("Note, selecting '%s' for regex '%s'\n"), Pkg.FullName(true).c_str(), pattern.c_str()); explicitlyNamed = false; } virtual void showSelectedVersion(pkgCache::PkgIterator const &/*Pkg*/, pkgCache::VerIterator const Ver, - std::string const &ver, bool const /*verIsRel*/) { + std::string const &ver, bool const /*verIsRel*/) APT_OVERRIDE { if (ver == Ver.VerStr()) return; selectedByRelease.push_back(make_pair(Ver, ver)); @@ -191,7 +191,7 @@ public: return false; } - virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE { APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, CacheSetHelper::CANDIDATE); if (verset.empty() == false) return *(verset.begin()); @@ -202,7 +202,7 @@ public: return pkgCache::VerIterator(Cache, 0); } - virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE { if (Pkg->ProvidesList != 0) { APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, CacheSetHelper::NEWEST); diff --git a/apt-private/private-moo.h b/apt-private/private-moo.h index b8e1cfed6..bc8b3e7dd 100644 --- a/apt-private/private-moo.h +++ b/apt-private/private-moo.h @@ -1,6 +1,8 @@ #ifndef APT_PRIVATE_MOO_H #define APT_PRIVATE_MOO_H +#include + class CommandLine; APT_PUBLIC bool DoMoo(CommandLine &CmdL); -- cgit v1.2.3 From 0d5b9da9f597fecae9b912d37d4e58bc903bdd4f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 9 Jul 2015 21:10:53 +0200 Subject: disable locking even for root in --simulate Six years ago in 55a5a46c235a30bf024fb2301066553953701cc5 apt-get learned to disable locking if run as normal user and show a message. Helmut Grohne rightly suggests on IRC now that there isn't much point in getting the locks for root either as the output isn't in any way more authoritive than without locking given that after this call the lock is freed and any action can sneak in before we make the next call. So we exchange no benefit for the disavantage of blocking real calls. This can be especially confusing with the aliases --no-act and --just-print. We do not print the message we print for users through as the non-root users can be confronted with a lot more difference via unreadable files. --- apt-private/private-main.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-main.cc b/apt-private/private-main.cc index 668b1733a..3886c7df6 100644 --- a/apt-private/private-main.cc +++ b/apt-private/private-main.cc @@ -22,13 +22,15 @@ void InitSignals() void CheckSimulateMode(CommandLine &CmdL) { - // simulate user-friendly if apt-get has no root privileges - if (getuid() != 0 && _config->FindB("APT::Get::Simulate") == true && + // disable locking in simulation, but show the message only for users + // as root hasn't the same problems like unreadable files which can heavily + // distort the simulation. + if (_config->FindB("APT::Get::Simulate") == true && (CmdL.FileSize() == 0 || (strcmp(CmdL.FileList[0], "source") != 0 && strcmp(CmdL.FileList[0], "download") != 0 && strcmp(CmdL.FileList[0], "changelog") != 0))) { - if (_config->FindB("APT::Get::Show-User-Simulation-Note",true) == true) + if (getuid() != 0 && _config->FindB("APT::Get::Show-User-Simulation-Note",true) == true) std::cout << _("NOTE: This is only a simulation!\n" " apt-get needs root privileges for real execution.\n" " Keep also in mind that locking is deactivated,\n" -- cgit v1.2.3 From c2a4a8dded2dfb56dbcab9689b6cb4b96c9999b6 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 10 Jul 2015 00:07:37 +0200 Subject: rename 'apt-get files' to 'apt-get indextargets' 'files' is a bit too generic as a name for a command usually only used programmatically (if at all) by developers, so instead of "wasting" this generic name for this we use "indextargets" which is actually the name of the datastructure the displayed data is stored in. Along with this rename the config options are renamed accordingly. --- apt-private/private-cmndline.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index 11e88b1e7..71dceb559 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -163,10 +163,10 @@ static bool addArgumentsAPTGet(std::vector &Args, char const // once sbuild is fixed, this option can be removed addArg('f', "fix-broken", "APT::Get::Fix-Broken", 0); } - else if (CmdMatches("files")) + else if (CmdMatches("indextargets")) { - addArg(0,"format","APT::Get::Files::Format", CommandLine::HasArg); - addArg(0,"release-info","APT::Get::Files::ReleaseInfo", 0); + addArg(0,"format","APT::Get::IndexTargets::Format", CommandLine::HasArg); + addArg(0,"release-info","APT::Get::IndexTargets::ReleaseInfo", 0); } else if (CmdMatches("clean", "autoclean", "check", "download", "changelog") || CmdMatches("markauto", "unmarkauto")) // deprecated commands -- cgit v1.2.3 From a0c19a217ca2ed38ae0ecb4b8d2d4f8c4e53289f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 12 Jul 2015 13:41:12 +0200 Subject: implement a more generic ShowList method apt-get is displaying various lists of package names, which until now it was building as a string before passing it to ShowList, which inserted linebreaks at fitting points and showed a title if needed, but it never really understood what it was working with. With the help of C++11 the new generic knows not only what it works with, but generates the list on the fly rather than asking for it and potentially discarding parts of the input (= the non-default verbose display). It also doubles as a test for how usable the CacheSets are with C++11. (Not all callers are adapted yet.) Git-Dch: Ignore --- apt-private/private-cachefile.cc | 61 ++++----- apt-private/private-cachefile.h | 59 ++++++--- apt-private/private-cacheset.h | 16 +-- apt-private/private-install.cc | 69 ++++------ apt-private/private-output.cc | 263 +++++++++++++++++++-------------------- apt-private/private-output.h | 67 +++++++++- 6 files changed, 299 insertions(+), 236 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-cachefile.cc b/apt-private/private-cachefile.cc index 29e665245..2b2050684 100644 --- a/apt-private/private-cachefile.cc +++ b/apt-private/private-cachefile.cc @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include @@ -21,39 +21,40 @@ using namespace std; -// CacheFile::NameComp - QSort compare by name /*{{{*/ -// --------------------------------------------------------------------- -/* */ -pkgCache *CacheFile::SortCache = 0; -int CacheFile::NameComp(const void *a,const void *b) +static bool SortPackagesByName(pkgCache * const Owner, + map_pointer_t const A, map_pointer_t const B) { - if (*(pkgCache::Package **)a == 0 || *(pkgCache::Package **)b == 0) - return *(pkgCache::Package **)a - *(pkgCache::Package **)b; - - const pkgCache::Package &A = **(pkgCache::Package **)a; - const pkgCache::Package &B = **(pkgCache::Package **)b; - const pkgCache::Group * const GA = SortCache->GrpP + A.Group; - const pkgCache::Group * const GB = SortCache->GrpP + B.Group; - - return strcmp(SortCache->StrP + GA->Name,SortCache->StrP + GB->Name); + if (A == 0) + return false; + if (B == 0 || A == B) + return true; + pkgCache::Group const * const GA = Owner->GrpP + A; + pkgCache::Group const * const GB = Owner->GrpP + B; + return strcmp(Owner->StrP + GA->Name, Owner->StrP + GB->Name) <= 0; } - /*}}}*/ -// CacheFile::Sort - Sort by name /*{{{*/ -// --------------------------------------------------------------------- -/* */ -void CacheFile::Sort() +SortedPackageUniverse::SortedPackageUniverse(CacheFile &Cache) : + PackageUniverse{Cache}, List{Cache.UniverseList} { - delete [] List; - List = new pkgCache::Package *[Cache->Head().PackageCount]; - memset(List,0,sizeof(*List)*Cache->Head().PackageCount); - pkgCache::PkgIterator I = Cache->PkgBegin(); - for (;I.end() != true; ++I) - List[I->ID] = I; - - SortCache = *this; - qsort(List,Cache->Head().PackageCount,sizeof(*List),NameComp); } - /*}}}*/ +void SortedPackageUniverse::LazyInit() const +{ + if (List.empty() == false) + return; + pkgCache * const Owner = data(); + // In Multi-Arch systems Grps are easier to sort than Pkgs + std::vector GrpList; + List.reserve(Owner->Head().GroupCount); + for (pkgCache::GrpIterator I{Owner->GrpBegin()}; I.end() != true; ++I) + GrpList.emplace_back(I - Owner->GrpP); + std::stable_sort(GrpList.begin(), GrpList.end(), std::bind( &SortPackagesByName, Owner, std::placeholders::_1, std::placeholders::_2 )); + List.reserve(Owner->Head().PackageCount); + for (auto G : GrpList) + { + pkgCache::GrpIterator const Grp(*Owner, Owner->GrpP + G); + for (pkgCache::PkgIterator P = Grp.PackageList(); P.end() != true; P = Grp.NextPkg(P)) + List.emplace_back(P - Owner->PkgP); + } +} // CacheFile::CheckDeps - Open the cache file /*{{{*/ // --------------------------------------------------------------------- /* This routine generates the caches and then opens the dependency cache diff --git a/apt-private/private-cachefile.h b/apt-private/private-cachefile.h index 1fddabfbd..4a68d9733 100644 --- a/apt-private/private-cachefile.h +++ b/apt-private/private-cachefile.h @@ -7,12 +7,13 @@ #include #include #include +#include + #include -// FIXME: we need to find a way to export this +// FIXME: we need to find a way to export this class APT_PUBLIC SourceList : public pkgSourceList { - public: // Add custom metaIndex (e.g. local files) void AddMetaIndex(metaIndex *mi) { @@ -22,17 +23,11 @@ class APT_PUBLIC SourceList : public pkgSourceList }; // class CacheFile - Cover class for some dependency cache functions /*{{{*/ -// --------------------------------------------------------------------- -/* */ class APT_PUBLIC CacheFile : public pkgCacheFile { - static pkgCache *SortCache; - APT_HIDDEN static int NameComp(const void *a,const void *b) APT_PURE; - public: - pkgCache::Package **List; - - void Sort(); + std::vector UniverseList; + bool CheckDeps(bool AllowBroken = false); bool BuildCaches(bool WithLock = true) { @@ -51,14 +46,10 @@ class APT_PUBLIC CacheFile : public pkgCacheFile return _error->Error(_("The list of sources could not be read.")); return true; } - bool Open(bool WithLock = true) + bool Open(bool WithLock = true) { OpTextProgress Prog(*_config); - if (pkgCacheFile::Open(&Prog,WithLock) == false) - return false; - Sort(); - - return true; + return pkgCacheFile::Open(&Prog,WithLock); }; bool OpenForInstall() { @@ -67,11 +58,39 @@ class APT_PUBLIC CacheFile : public pkgCacheFile else return Open(true); } - CacheFile() : List(0) {}; - ~CacheFile() { - delete[] List; - } }; /*}}}*/ +class APT_PUBLIC SortedPackageUniverse : public APT::PackageUniverse +{ + std::vector &List; + void LazyInit() const; + +public: + SortedPackageUniverse(CacheFile &Cache); + + class const_iterator : public APT::Container_iterator_base::const_iterator, pkgCache::PkgIterator> + { + pkgCache * const Cache; + protected: + inline virtual pkgCache::PkgIterator getType(void) const APT_OVERRIDE + { + if (*_iter == 0) return pkgCache::PkgIterator(*Cache); + return pkgCache::PkgIterator(*Cache, Cache->PkgP + *_iter); + } + public: + explicit const_iterator(pkgCache * const Owner, std::vector::const_iterator i): + Container_iterator_base::const_iterator, pkgCache::PkgIterator>(i), Cache(Owner) {} + + }; + typedef const_iterator iterator; + + APT_PUBLIC const_iterator begin() const { LazyInit(); return const_iterator(data(), List.begin()); } + APT_PUBLIC const_iterator end() const { LazyInit(); return const_iterator(data(), List.end()); } + APT_PUBLIC const_iterator cbegin() const { LazyInit(); return const_iterator(data(), List.begin()); } + APT_PUBLIC const_iterator cend() const { LazyInit(); return const_iterator(data(), List.end()); } + APT_PUBLIC iterator begin() { LazyInit(); return iterator(data(), List.begin()); } + APT_PUBLIC iterator end() { LazyInit(); return iterator(data(), List.end()); } +}; + #endif diff --git a/apt-private/private-cacheset.h b/apt-private/private-cacheset.h index 518f179f3..7cafe4fdd 100644 --- a/apt-private/private-cacheset.h +++ b/apt-private/private-cacheset.h @@ -12,6 +12,8 @@ #include #include +#include + #include #include #include @@ -21,8 +23,6 @@ #include #include -#include "private-output.h" - #include class OpProgress; @@ -174,17 +174,19 @@ public: std::string VersionsList; SPtrArray Seen = new bool[Cache.GetPkgCache()->Head().PackageCount]; memset(Seen,0,Cache.GetPkgCache()->Head().PackageCount*sizeof(*Seen)); + APT::PackageList pkglist; for (pkgCache::DepIterator Dep = Pkg.RevDependsList(); Dep.end() == false; ++Dep) { if (Dep->Type != pkgCache::Dep::Replaces) continue; - if (Seen[Dep.ParentPkg()->ID] == true) + pkgCache::PkgIterator const DP = Dep.ParentPkg(); + if (Seen[DP->ID] == true) continue; - Seen[Dep.ParentPkg()->ID] = true; - List += Dep.ParentPkg().FullName(true) + " "; - //VersionsList += std::string(Dep.ParentPkg().CurVersion) + "\n"; ??? + Seen[DP->ID] = true; + pkglist.insert(DP); } - ShowList(c1out,_("However the following packages replace it:"),List,VersionsList); + ShowList(c1out, _("However the following packages replace it:"), pkglist, + &AlwaysTrue, &PrettyFullName, &EmptyString); } c1out << std::endl; } diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 3474d262a..cdca45755 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -374,11 +374,10 @@ static bool DoAutomaticRemove(CacheFile &Cache) unsigned long autoRemoveCount = 0; APT::PackageSet tooMuch; - APT::PackageList autoRemoveList; + SortedPackageUniverse Universe(Cache); // look over the cache to see what can be removed - for (unsigned J = 0; J < Cache->Head().PackageCount; ++J) + for (auto const &Pkg: Universe) { - pkgCache::PkgIterator Pkg(Cache,Cache.List[J]); if (Cache[Pkg].Garbage) { if(Pkg.CurrentVer() != 0 || Cache[Pkg].Install()) @@ -395,8 +394,6 @@ static bool DoAutomaticRemove(CacheFile &Cache) } else { - if (hideAutoRemove == false && Cache[Pkg].Delete() == false) - autoRemoveList.insert(Pkg); // if the package is a new install and already garbage we don't need to // install it in the first place, so nuke it instead of show it if (Cache[Pkg].Install() == true && Pkg.CurrentVer() == 0) @@ -456,18 +453,6 @@ static bool DoAutomaticRemove(CacheFile &Cache) } while (Changed == true); } - std::string autoremovelist, autoremoveversions; - if (smallList == false && autoRemoveCount != 0) - { - for (APT::PackageList::const_iterator Pkg = autoRemoveList.begin(); Pkg != autoRemoveList.end(); ++Pkg) - { - if (Cache[Pkg].Garbage == false) - continue; - autoremovelist += Pkg.FullName(true) + " "; - autoremoveversions += std::string(Cache[Pkg].CandVersion) + "\n"; - } - } - // Now see if we had destroyed anything (if we had done anything) if (Cache->BrokenCount() != 0) { @@ -482,12 +467,17 @@ static bool DoAutomaticRemove(CacheFile &Cache) } // if we don't remove them, we should show them! - if (doAutoRemove == false && (autoremovelist.empty() == false || autoRemoveCount != 0)) + if (doAutoRemove == false && autoRemoveCount != 0) { if (smallList == false) + { + SortedPackageUniverse Universe(Cache); ShowList(c1out, P_("The following package was automatically installed and is no longer required:", "The following packages were automatically installed and are no longer required:", - autoRemoveCount), autoremovelist, autoremoveversions); + autoRemoveCount), Universe, + [&Cache](pkgCache::PkgIterator const &Pkg) { return (*Cache)[Pkg].Garbage == true && (*Cache)[Pkg].Delete() == false; }, + &PrettyFullName, CandidateVersion(&Cache)); + } else ioprintf(c1out, P_("%lu package was automatically installed and is no longer required.\n", "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount), autoRemoveCount); @@ -651,6 +641,18 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, // DoInstall - Install packages from the command line /*{{{*/ // --------------------------------------------------------------------- /* Install named packages */ +struct PkgIsExtraInstalled { + pkgCacheFile * const Cache; + APT::VersionSet const * const verset; + PkgIsExtraInstalled(pkgCacheFile * const Cache, APT::VersionSet const * const Container) : Cache(Cache), verset(Container) {} + bool operator() (pkgCache::PkgIterator const Pkg) + { + if ((*Cache)[Pkg].Install() == false) + return false; + pkgCache::VerIterator const Cand = (*Cache)[Pkg].CandidateVerIter(*Cache); + return verset->find(Cand) == verset->end(); + } +}; bool DoInstall(CommandLine &CmdL) { CacheFile Cache; @@ -689,35 +691,18 @@ bool DoInstall(CommandLine &CmdL) /* Print out a list of packages that are going to be installed extra to what the user asked */ + SortedPackageUniverse Universe(Cache); if (Cache->InstCount() != verset[MOD_INSTALL].size()) - { - std::string List; - std::string VersionsList; - for (unsigned J = 0; J < Cache->Head().PackageCount; J++) - { - pkgCache::PkgIterator I(Cache,Cache.List[J]); - if ((*Cache)[I].Install() == false) - continue; - pkgCache::VerIterator Cand = Cache[I].CandidateVerIter(Cache); - - if (verset[MOD_INSTALL].find(Cand) != verset[MOD_INSTALL].end()) - continue; - - List += I.FullName(true) + " "; - VersionsList += std::string(Cache[I].CandVersion) + "\n"; - } - - ShowList(c1out,_("The following extra packages will be installed:"),List,VersionsList); - } + ShowList(c1out, _("The following extra packages will be installed:"), Universe, + PkgIsExtraInstalled(&Cache, &verset[MOD_INSTALL]), + &PrettyFullName, CandidateVersion(&Cache)); /* Print out a list of suggested and recommended packages */ { std::string SuggestsList, RecommendsList; std::string SuggestsVersions, RecommendsVersions; - for (unsigned J = 0; J < Cache->Head().PackageCount; J++) + for (auto const &Pkg: Universe) { - pkgCache::PkgIterator Pkg(Cache,Cache.List[J]); - /* Just look at the ones we want to install */ if ((*Cache)[Pkg].Install() == false) continue; @@ -738,7 +723,6 @@ bool DoInstall(CommandLine &CmdL) for(;;) { /* Skip if package is installed already, or is about to be */ - std::string target = Start.TargetPkg().FullName(true) + " "; pkgCache::PkgIterator const TarPkg = Start.TargetPkg(); if (TarPkg->SelectedState == pkgCache::State::Install || TarPkg->SelectedState == pkgCache::State::Hold || @@ -749,6 +733,7 @@ bool DoInstall(CommandLine &CmdL) } /* Skip if we already saw it */ + std::string target = Start.TargetPkg().FullName(true) + " "; if (int(SuggestsList.find(target)) != -1 || int(RecommendsList.find(target)) != -1) { foundInstalledInOrGroup=true; diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 9944ab002..b77efff86 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -25,6 +25,8 @@ #include #include +#include + #include /*}}}*/ @@ -491,11 +493,9 @@ void ShowBroken(ostream &out, CacheFile &Cache, bool const Now) return; out << _("The following packages have unmet dependencies:") << endl; - for (unsigned J = 0; J < Cache->Head().PackageCount; J++) - { - pkgCache::PkgIterator const I(Cache,Cache.List[J]); - ShowBrokenPackage(out, &Cache, I, Now); - } + SortedPackageUniverse Universe(Cache); + for (auto const &Pkg: Universe) + ShowBrokenPackage(out, &Cache, Pkg, Now); } void ShowBroken(ostream &out, pkgCacheFile &Cache, bool const Now) { @@ -503,98 +503,64 @@ void ShowBroken(ostream &out, pkgCacheFile &Cache, bool const Now) return; out << _("The following packages have unmet dependencies:") << endl; - for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; ++Pkg) + APT::PackageUniverse Universe(Cache); + for (auto const &Pkg: Universe) ShowBrokenPackage(out, &Cache, Pkg, Now); } /*}}}*/ // ShowNew - Show packages to newly install /*{{{*/ -// --------------------------------------------------------------------- -/* */ void ShowNew(ostream &out,CacheFile &Cache) { - /* Print out a list of packages that are going to be installed extra - to what the user asked */ - string List; - string VersionsList; - for (unsigned J = 0; J < Cache->Head().PackageCount; J++) - { - pkgCache::PkgIterator I(Cache,Cache.List[J]); - if (Cache[I].NewInstall() == true) { - List += I.FullName(true) + " "; - VersionsList += string(Cache[I].CandVersion) + "\n"; - } - } - - ShowList(out,_("The following NEW packages will be installed:"),List,VersionsList); + SortedPackageUniverse Universe(Cache); + ShowList(out,_("The following NEW packages will be installed:"), Universe, + [&Cache](pkgCache::PkgIterator const &Pkg) { return Cache[Pkg].NewInstall(); }, + &PrettyFullName, + CandidateVersion(&Cache)); } /*}}}*/ // ShowDel - Show packages to delete /*{{{*/ -// --------------------------------------------------------------------- -/* */ void ShowDel(ostream &out,CacheFile &Cache) { - /* Print out a list of packages that are going to be removed extra - to what the user asked */ - string List; - string VersionsList; - for (unsigned J = 0; J < Cache->Head().PackageCount; J++) - { - pkgCache::PkgIterator I(Cache,Cache.List[J]); - if (Cache[I].Delete() == true) - { - if ((Cache[I].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge) - List += I.FullName(true) + "* "; - else - List += I.FullName(true) + " "; - - VersionsList += string(Cache[I].CandVersion)+ "\n"; - } - } - - ShowList(out,_("The following packages will be REMOVED:"),List,VersionsList); + SortedPackageUniverse Universe(Cache); + ShowList(out,_("The following packages will be REMOVED:"), Universe, + [&Cache](pkgCache::PkgIterator const &Pkg) { return Cache[Pkg].Delete(); }, + [&Cache](pkgCache::PkgIterator const &Pkg) + { + std::string str = PrettyFullName(Pkg); + if (((*Cache)[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge) + str.append("*"); + return str; + }, + CandidateVersion(&Cache)); } /*}}}*/ // ShowKept - Show kept packages /*{{{*/ -// --------------------------------------------------------------------- -/* */ void ShowKept(ostream &out,CacheFile &Cache) { - string List; - string VersionsList; - for (unsigned J = 0; J < Cache->Head().PackageCount; J++) - { - pkgCache::PkgIterator I(Cache,Cache.List[J]); - - // Not interesting - if (Cache[I].Upgrade() == true || Cache[I].Upgradable() == false || - I->CurrentVer == 0 || Cache[I].Delete() == true) - continue; - - List += I.FullName(true) + " "; - VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n"; - } - ShowList(out,_("The following packages have been kept back:"),List,VersionsList); + SortedPackageUniverse Universe(Cache); + ShowList(out,_("The following packages have been kept back:"), Universe, + [&Cache](pkgCache::PkgIterator const &Pkg) + { + return Cache[Pkg].Upgrade() == false && + Cache[Pkg].Upgradable() == true && + Pkg->CurrentVer != 0 && + Cache[Pkg].Delete() == false; + }, + &PrettyFullName, + CurrentToCandidateVersion(&Cache)); } /*}}}*/ // ShowUpgraded - Show upgraded packages /*{{{*/ -// --------------------------------------------------------------------- -/* */ void ShowUpgraded(ostream &out,CacheFile &Cache) { - string List; - string VersionsList; - for (unsigned J = 0; J < Cache->Head().PackageCount; J++) - { - pkgCache::PkgIterator I(Cache,Cache.List[J]); - - // Not interesting - if (Cache[I].Upgrade() == false || Cache[I].NewInstall() == true) - continue; - - List += I.FullName(true) + " "; - VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n"; - } - ShowList(out,_("The following packages will be upgraded:"),List,VersionsList); + SortedPackageUniverse Universe(Cache); + ShowList(out,_("The following packages will be upgraded:"), Universe, + [&Cache](pkgCache::PkgIterator const &Pkg) + { + return Cache[Pkg].Upgrade() == true && Cache[Pkg].NewInstall() == false; + }, + &PrettyFullName, + CurrentToCandidateVersion(&Cache)); } /*}}}*/ // ShowDowngraded - Show downgraded packages /*{{{*/ @@ -602,74 +568,73 @@ void ShowUpgraded(ostream &out,CacheFile &Cache) /* */ bool ShowDowngraded(ostream &out,CacheFile &Cache) { - string List; - string VersionsList; - for (unsigned J = 0; J < Cache->Head().PackageCount; J++) - { - pkgCache::PkgIterator I(Cache,Cache.List[J]); - - // Not interesting - if (Cache[I].Downgrade() == false || Cache[I].NewInstall() == true) - continue; - - List += I.FullName(true) + " "; - VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n"; - } - return ShowList(out,_("The following packages will be DOWNGRADED:"),List,VersionsList); + SortedPackageUniverse Universe(Cache); + return ShowList(out,_("The following packages will be DOWNGRADED:"), Universe, + [&Cache](pkgCache::PkgIterator const &Pkg) + { + return Cache[Pkg].Downgrade() == true && Cache[Pkg].NewInstall() == false; + }, + &PrettyFullName, + CurrentToCandidateVersion(&Cache)); } /*}}}*/ // ShowHold - Show held but changed packages /*{{{*/ -// --------------------------------------------------------------------- -/* */ bool ShowHold(ostream &out,CacheFile &Cache) { - string List; - string VersionsList; - for (unsigned J = 0; J < Cache->Head().PackageCount; J++) - { - pkgCache::PkgIterator I(Cache,Cache.List[J]); - if (Cache[I].InstallVer != (pkgCache::Version *)I.CurrentVer() && - I->SelectedState == pkgCache::State::Hold) { - List += I.FullName(true) + " "; - VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n"; - } - } - - return ShowList(out,_("The following held packages will be changed:"),List,VersionsList); + SortedPackageUniverse Universe(Cache); + return ShowList(out,_("The following held packages will be changed:"), Universe, + [&Cache](pkgCache::PkgIterator const &Pkg) + { + return Pkg->SelectedState == pkgCache::State::Hold && + Cache[Pkg].InstallVer != (pkgCache::Version *)Pkg.CurrentVer(); + }, + &PrettyFullName, + CurrentToCandidateVersion(&Cache)); } /*}}}*/ // ShowEssential - Show an essential package warning /*{{{*/ // --------------------------------------------------------------------- /* This prints out a warning message that is not to be ignored. It shows - all essential packages and their dependents that are to be removed. + all essential packages and their dependents that are to be removed. It is insanely risky to remove the dependents of an essential package! */ +struct APT_HIDDEN PrettyFullNameWithDue { + std::map due; + PrettyFullNameWithDue() {} + std::string operator() (pkgCache::PkgIterator const &Pkg) + { + std::string const A = PrettyFullName(Pkg); + std::map::const_iterator d = due.find(Pkg->ID); + if (d == due.end()) + return A; + + std::string const B = PrettyFullName(d->second); + std::ostringstream outstr; + ioprintf(outstr, _("%s (due to %s)"), A.c_str(), B.c_str()); + return outstr.str(); + } +}; bool ShowEssential(ostream &out,CacheFile &Cache) { - string List; - string VersionsList; - bool *Added = new bool[Cache->Head().PackageCount]; - for (unsigned int I = 0; I != Cache->Head().PackageCount; I++) - Added[I] = false; - - for (unsigned J = 0; J < Cache->Head().PackageCount; J++) + std::vector Added(Cache->Head().PackageCount, false); + APT::PackageDeque pkglist; + PrettyFullNameWithDue withdue; + + SortedPackageUniverse Universe(Cache); + for (pkgCache::PkgIterator const &I: Universe) { - pkgCache::PkgIterator I(Cache,Cache.List[J]); if ((I->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential && (I->Flags & pkgCache::Flag::Important) != pkgCache::Flag::Important) continue; - + // The essential package is being removed - if (Cache[I].Delete() == true) + if (Cache[I].Delete() == false) + continue; + + if (Added[I->ID] == false) { - if (Added[I->ID] == false) - { - Added[I->ID] = true; - List += I.FullName(true) + " "; - //VersionsList += string(Cache[I].CurVersion) + "\n"; ??? - } + Added[I->ID] = true; + pkglist.insert(I); } - else - continue; if (I->CurrentVer == 0) continue; @@ -681,27 +646,23 @@ bool ShowEssential(ostream &out,CacheFile &Cache) if (D->Type != pkgCache::Dep::PreDepends && D->Type != pkgCache::Dep::Depends) continue; - + pkgCache::PkgIterator P = D.SmartTargetPkg(); if (Cache[P].Delete() == true) { if (Added[P->ID] == true) continue; Added[P->ID] = true; - - char S[300]; - snprintf(S,sizeof(S),_("%s (due to %s) "),P.FullName(true).c_str(),I.FullName(true).c_str()); - List += S; - //VersionsList += "\n"; ??? - } - } + + pkglist.insert(P); + withdue.due[P->ID] = I; + } + } } - - delete [] Added; return ShowList(out,_("WARNING: The following essential packages will be removed.\n" - "This should NOT be done unless you know exactly what you are doing!"),List,VersionsList); + "This should NOT be done unless you know exactly what you are doing!"), + pkglist, &AlwaysTrue, withdue, &EmptyString); } - /*}}}*/ // Stats - Show some statistics /*{{{*/ // --------------------------------------------------------------------- @@ -829,3 +790,33 @@ bool AnalPrompt(const char *Text) return false; } /*}}}*/ + +std::string PrettyFullName(pkgCache::PkgIterator const &Pkg) +{ + return Pkg.FullName(true); +} +std::string CandidateVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg) +{ + return (*Cache)[Pkg].CandVersion; +} +std::function CandidateVersion(pkgCacheFile * const Cache) +{ + return std::bind(static_cast(&CandidateVersion), Cache, std::placeholders::_1); +} +std::string CurrentToCandidateVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg) +{ + return std::string((*Cache)[Pkg].CurVersion) + " => " + (*Cache)[Pkg].CandVersion; +} +std::function CurrentToCandidateVersion(pkgCacheFile * const Cache) +{ + return std::bind(static_cast(&CurrentToCandidateVersion), Cache, std::placeholders::_1); +} +bool AlwaysTrue(pkgCache::PkgIterator const &) +{ + return true; +} +std::string EmptyString(pkgCache::PkgIterator const &) +{ + return std::string(); +} + diff --git a/apt-private/private-output.h b/apt-private/private-output.h index d5b57adec..b9151b245 100644 --- a/apt-private/private-output.h +++ b/apt-private/private-output.h @@ -1,9 +1,11 @@ #ifndef APT_PRIVATE_OUTPUT_H #define APT_PRIVATE_OUTPUT_H +#include #include #include +#include #include #include #include @@ -32,8 +34,63 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, APT_PUBLIC void ShowBroken(std::ostream &out, CacheFile &Cache, bool const Now); APT_PUBLIC void ShowBroken(std::ostream &out, pkgCacheFile &Cache, bool const Now); -APT_PUBLIC bool ShowList(std::ostream &out, std::string Title, std::string List, +template APT_PUBLIC bool ShowList(std::ostream &out, std::string const &Title, + Container const &cont, + std::function Predicate, + std::function PkgDisplay, + std::function VerboseDisplay) +{ + size_t const ScreenWidth = (::ScreenWidth > 3) ? ::ScreenWidth - 3 : 0; + int ScreenUsed = 0; + bool const ShowVersions = _config->FindB("APT::Get::Show-Versions", false); + bool printedTitle = false; + + for (auto const &Pkg: cont) + { + if (Predicate(Pkg) == false) + continue; + + if (printedTitle == false) + { + out << Title; + printedTitle = true; + } + + if (ShowVersions == true) + { + out << std::endl << " " << PkgDisplay(Pkg); + std::string const verbose = VerboseDisplay(Pkg); + if (verbose.empty() == false) + out << " (" << verbose << ")"; + } + else + { + std::string const PkgName = PkgDisplay(Pkg); + if (ScreenUsed == 0 || (ScreenUsed + PkgName.length()) >= ScreenWidth) + { + out << std::endl << " "; + ScreenUsed = 0; + } + else if (ScreenUsed != 0) + { + out << " "; + ++ScreenUsed; + } + out << PkgName; + ScreenUsed += PkgName.length(); + } + } + + if (printedTitle == true) + { + out << std::endl; + return false; + } + return true; +} +APT_DEPRECATED APT_PUBLIC bool ShowList(std::ostream &out, std::string Title, std::string List, std::string VersionsList); + void ShowNew(std::ostream &out,CacheFile &Cache); void ShowDel(std::ostream &out,CacheFile &Cache); void ShowKept(std::ostream &out,CacheFile &Cache); @@ -49,4 +106,12 @@ void Stats(std::ostream &out, pkgDepCache &Dep); bool YnPrompt(bool Default=true); bool AnalPrompt(const char *Text); +APT_PUBLIC std::string PrettyFullName(pkgCache::PkgIterator const &Pkg); +APT_PUBLIC std::string CandidateVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg); +APT_PUBLIC std::function CandidateVersion(pkgCacheFile * const Cache); +APT_PUBLIC std::string CurrentToCandidateVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg); +APT_PUBLIC std::function CurrentToCandidateVersion(pkgCacheFile * const Cache); +APT_PUBLIC std::string EmptyString(pkgCache::PkgIterator const &); +APT_PUBLIC bool AlwaysTrue(pkgCache::PkgIterator const &); + #endif -- cgit v1.2.3 From 6cfadda161ce19e6c8076d0aa118f8f436805a6a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 12 Jul 2015 18:28:34 +0200 Subject: headers are for declarations only Housekeeping. This used to be embedded in apt-get directly, then moved to into our (then new) private lib and now header and code get a proper separation. Git-Dch: Ignore --- apt-private/private-cacheset.cc | 209 ++++++++++++++++++++++++++++++++- apt-private/private-cacheset.h | 249 ++++++---------------------------------- 2 files changed, 242 insertions(+), 216 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-cacheset.cc b/apt-private/private-cacheset.cc index cb68024db..36d40117c 100644 --- a/apt-private/private-cacheset.cc +++ b/apt-private/private-cacheset.cc @@ -4,9 +4,11 @@ #include #include #include +#include #include #include #include +#include #include @@ -14,7 +16,7 @@ #include -bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, +bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, /*{{{*/ APT::VersionContainerInterface * const vci, OpProgress * const progress) { @@ -22,7 +24,6 @@ bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, return GetLocalitySortedVersionSet(CacheFile, vci, null_matcher, progress); } - bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, APT::VersionContainerInterface * const vci, Matcher &matcher, @@ -88,3 +89,207 @@ bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, progress->Done(); return true; } + /*}}}*/ + +// CacheSetHelper saving virtual packages /*{{{*/ +pkgCache::VerIterator CacheSetHelperVirtuals::canNotGetVersion( + enum CacheSetHelper::VerSelector const select, + pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg) +{ + if (select == NEWEST || select == CANDIDATE || select == ALL) + virtualPkgs.insert(Pkg); + return CacheSetHelper::canNotGetVersion(select, Cache, Pkg); +} +void CacheSetHelperVirtuals::canNotFindVersion( + enum CacheSetHelper::VerSelector const select, + APT::VersionContainerInterface * vci, + pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg) +{ + if (select == NEWEST || select == CANDIDATE || select == ALL) + virtualPkgs.insert(Pkg); + return CacheSetHelper::canNotFindVersion(select, vci, Cache, Pkg); +} +CacheSetHelperVirtuals::CacheSetHelperVirtuals(bool const ShowErrors, GlobalError::MsgType const &ErrorType) : + CacheSetHelper{ShowErrors, ErrorType} +{} + /*}}}*/ + +// CacheSetHelperAPTGet - responsible for message telling from the CacheSets/*{{{*/ +CacheSetHelperAPTGet::CacheSetHelperAPTGet(std::ostream &out) : + APT::CacheSetHelper{true}, out{out} +{ + explicitlyNamed = true; +} +void CacheSetHelperAPTGet::showTaskSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) +{ + ioprintf(out, _("Note, selecting '%s' for task '%s'\n"), + Pkg.FullName(true).c_str(), pattern.c_str()); + explicitlyNamed = false; +} +void CacheSetHelperAPTGet::showFnmatchSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) +{ + ioprintf(out, _("Note, selecting '%s' for glob '%s'\n"), + Pkg.FullName(true).c_str(), pattern.c_str()); + explicitlyNamed = false; +} +void CacheSetHelperAPTGet::showRegExSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) +{ + ioprintf(out, _("Note, selecting '%s' for regex '%s'\n"), + Pkg.FullName(true).c_str(), pattern.c_str()); + explicitlyNamed = false; +} +void CacheSetHelperAPTGet::showSelectedVersion(pkgCache::PkgIterator const &/*Pkg*/, pkgCache::VerIterator const Ver, + std::string const &ver, bool const /*verIsRel*/) +{ + if (ver == Ver.VerStr()) + return; + selectedByRelease.push_back(make_pair(Ver, ver)); +} +bool CacheSetHelperAPTGet::showVirtualPackageErrors(pkgCacheFile &Cache) +{ + if (virtualPkgs.empty() == true) + return true; + for (APT::PackageSet::const_iterator Pkg = virtualPkgs.begin(); + Pkg != virtualPkgs.end(); ++Pkg) { + if (Pkg->ProvidesList != 0) { + ioprintf(c1out,_("Package %s is a virtual package provided by:\n"), + Pkg.FullName(true).c_str()); + + pkgCache::PrvIterator I = Pkg.ProvidesList(); + unsigned short provider = 0; + for (; I.end() == false; ++I) { + pkgCache::PkgIterator Pkg = I.OwnerPkg(); + + if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer()) { + c1out << " " << Pkg.FullName(true) << " " << I.OwnerVer().VerStr(); + if (Cache[Pkg].Install() == true && Cache[Pkg].NewInstall() == false) + c1out << _(" [Installed]"); + c1out << std::endl; + ++provider; + } + } + // if we found no candidate which provide this package, show non-candidates + if (provider == 0) + for (I = Pkg.ProvidesList(); I.end() == false; ++I) + c1out << " " << I.OwnerPkg().FullName(true) << " " << I.OwnerVer().VerStr() + << _(" [Not candidate version]") << std::endl; + else + out << _("You should explicitly select one to install.") << std::endl; + } else { + ioprintf(c1out, + _("Package %s is not available, but is referred to by another package.\n" + "This may mean that the package is missing, has been obsoleted, or\n" + "is only available from another source\n"),Pkg.FullName(true).c_str()); + + std::string List; + std::string VersionsList; + std::vector Seen(Cache.GetPkgCache()->Head().PackageCount, false); + APT::PackageList pkglist; + for (pkgCache::DepIterator Dep = Pkg.RevDependsList(); + Dep.end() == false; ++Dep) { + if (Dep->Type != pkgCache::Dep::Replaces) + continue; + pkgCache::PkgIterator const DP = Dep.ParentPkg(); + if (Seen[DP->ID] == true) + continue; + Seen[DP->ID] = true; + pkglist.insert(DP); + } + ShowList(c1out, _("However the following packages replace it:"), pkglist, + &AlwaysTrue, &PrettyFullName, &EmptyString); + } + c1out << std::endl; + } + return false; +} +pkgCache::VerIterator CacheSetHelperAPTGet::canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) +{ + APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, CacheSetHelper::CANDIDATE); + if (verset.empty() == false) + return *(verset.begin()); + else if (ShowError == true) { + _error->Error(_("Package '%s' has no installation candidate"),Pkg.FullName(true).c_str()); + virtualPkgs.insert(Pkg); + } + return pkgCache::VerIterator(Cache, 0); +} +pkgCache::VerIterator CacheSetHelperAPTGet::canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) +{ + if (Pkg->ProvidesList != 0) + { + APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, CacheSetHelper::NEWEST); + if (verset.empty() == false) + return *(verset.begin()); + if (ShowError == true) + ioprintf(out, _("Virtual packages like '%s' can't be removed\n"), Pkg.FullName(true).c_str()); + } + else + { + pkgCache::GrpIterator Grp = Pkg.Group(); + pkgCache::PkgIterator P = Grp.PackageList(); + for (; P.end() != true; P = Grp.NextPkg(P)) + { + if (P == Pkg) + continue; + if (P->CurrentVer != 0) { + // TRANSLATORS: Note, this is not an interactive question + ioprintf(c1out,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"), + Pkg.FullName(true).c_str(), P.FullName(true).c_str()); + break; + } + } + if (P.end() == true) + ioprintf(c1out,_("Package '%s' is not installed, so not removed\n"),Pkg.FullName(true).c_str()); + } + return pkgCache::VerIterator(Cache, 0); +} +APT::VersionSet CacheSetHelperAPTGet::tryVirtualPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg, + CacheSetHelper::VerSelector const select) +{ + /* This is a pure virtual package and there is a single available + candidate providing it. */ + if (unlikely(Cache[Pkg].CandidateVer != 0) || Pkg->ProvidesList == 0) + return APT::VersionSet(); + + pkgCache::PkgIterator Prov; + bool found_one = false; + for (pkgCache::PrvIterator P = Pkg.ProvidesList(); P; ++P) { + pkgCache::VerIterator const PVer = P.OwnerVer(); + pkgCache::PkgIterator const PPkg = PVer.ParentPkg(); + + /* Ignore versions that are not a candidate. */ + if (Cache[PPkg].CandidateVer != PVer) + continue; + + if (found_one == false) { + Prov = PPkg; + found_one = true; + } else if (PPkg != Prov) { + // same group, so it's a foreign package + if (PPkg->Group == Prov->Group) { + // do we already have the requested arch? + if (strcmp(Pkg.Arch(), Prov.Arch()) == 0 || + strcmp(Prov.Arch(), "all") == 0 || + unlikely(strcmp(PPkg.Arch(), Prov.Arch()) == 0)) // packages have only on candidate, but just to be sure + continue; + // see which architecture we prefer more and switch to it + std::vector archs = APT::Configuration::getArchitectures(); + if (std::find(archs.begin(), archs.end(), PPkg.Arch()) < std::find(archs.begin(), archs.end(), Prov.Arch())) + Prov = PPkg; + continue; + } + found_one = false; // we found at least two + break; + } + } + + if (found_one == true) { + ioprintf(out, _("Note, selecting '%s' instead of '%s'\n"), + Prov.FullName(true).c_str(), Pkg.FullName(true).c_str()); + return APT::VersionSet::FromPackage(Cache, Prov, select, *this); + } + return APT::VersionSet(); +} + /*}}}*/ diff --git a/apt-private/private-cacheset.h b/apt-private/private-cacheset.h index 7cafe4fdd..892993e58 100644 --- a/apt-private/private-cacheset.h +++ b/apt-private/private-cacheset.h @@ -1,60 +1,48 @@ #ifndef APT_PRIVATE_CACHESET_H #define APT_PRIVATE_CACHESET_H -#include -#include #include -#include -#include -#include -#include -#include -#include #include #include -#include #include -#include #include -#include #include #include -#include #include class OpProgress; -struct VersionSortDescriptionLocality +struct APT_PUBLIC VersionSortDescriptionLocality /*{{{*/ { - bool operator () (const pkgCache::VerIterator &v_lhs, - const pkgCache::VerIterator &v_rhs) - { - pkgCache::DescFile const *A = NULL; - pkgCache::DescFile const *B = NULL; - if (v_lhs->DescriptionList != 0) - A = v_lhs.TranslatedDescription().FileList(); - if (v_rhs->DescriptionList != 0) - B = v_rhs.TranslatedDescription().FileList(); + bool operator () (const pkgCache::VerIterator &v_lhs, + const pkgCache::VerIterator &v_rhs) + { + pkgCache::DescFile const *A = nullptr; + pkgCache::DescFile const *B = nullptr; + if (v_lhs->DescriptionList != 0) + A = v_lhs.TranslatedDescription().FileList(); + if (v_rhs->DescriptionList != 0) + B = v_rhs.TranslatedDescription().FileList(); - if (A == 0 && B == 0) - return false; + if (A == nullptr && B == nullptr) + return false; - if (A == 0) - return true; + if (A == nullptr) + return true; - if (B == 0) - return false; + if (B == nullptr) + return false; - if (A->File == B->File) - return A->Offset < B->Offset; + if (A->File == B->File) + return A->Offset < B->Offset; - return A->File < B->File; - } + return A->File < B->File; + } }; - + /*}}}*/ // sorted by locality which makes iterating much faster typedef APT::VersionContainer< std::set > selectedByRelease; - CacheSetHelperAPTGet(std::ostream &out) : APT::CacheSetHelper(true), out(out) { - explicitlyNamed = true; - } + CacheSetHelperAPTGet(std::ostream &out); - virtual void showTaskSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) APT_OVERRIDE { - ioprintf(out, _("Note, selecting '%s' for task '%s'\n"), - Pkg.FullName(true).c_str(), pattern.c_str()); - explicitlyNamed = false; - } - virtual void showFnmatchSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) APT_OVERRIDE { - ioprintf(out, _("Note, selecting '%s' for glob '%s'\n"), - Pkg.FullName(true).c_str(), pattern.c_str()); - explicitlyNamed = false; - } - virtual void showRegExSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) APT_OVERRIDE { - ioprintf(out, _("Note, selecting '%s' for regex '%s'\n"), - Pkg.FullName(true).c_str(), pattern.c_str()); - explicitlyNamed = false; - } + virtual void showTaskSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) APT_OVERRIDE; + virtual void showFnmatchSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) APT_OVERRIDE; + virtual void showRegExSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) APT_OVERRIDE; virtual void showSelectedVersion(pkgCache::PkgIterator const &/*Pkg*/, pkgCache::VerIterator const Ver, - std::string const &ver, bool const /*verIsRel*/) APT_OVERRIDE { - if (ver == Ver.VerStr()) - return; - selectedByRelease.push_back(make_pair(Ver, ver)); - } - - bool showVirtualPackageErrors(pkgCacheFile &Cache) { - if (virtualPkgs.empty() == true) - return true; - for (APT::PackageSet::const_iterator Pkg = virtualPkgs.begin(); - Pkg != virtualPkgs.end(); ++Pkg) { - if (Pkg->ProvidesList != 0) { - ioprintf(c1out,_("Package %s is a virtual package provided by:\n"), - Pkg.FullName(true).c_str()); - - pkgCache::PrvIterator I = Pkg.ProvidesList(); - unsigned short provider = 0; - for (; I.end() == false; ++I) { - pkgCache::PkgIterator Pkg = I.OwnerPkg(); + std::string const &ver, bool const /*verIsRel*/) APT_OVERRIDE; + bool showVirtualPackageErrors(pkgCacheFile &Cache); - if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer()) { - c1out << " " << Pkg.FullName(true) << " " << I.OwnerVer().VerStr(); - if (Cache[Pkg].Install() == true && Cache[Pkg].NewInstall() == false) - c1out << _(" [Installed]"); - c1out << std::endl; - ++provider; - } - } - // if we found no candidate which provide this package, show non-candidates - if (provider == 0) - for (I = Pkg.ProvidesList(); I.end() == false; ++I) - c1out << " " << I.OwnerPkg().FullName(true) << " " << I.OwnerVer().VerStr() - << _(" [Not candidate version]") << std::endl; - else - out << _("You should explicitly select one to install.") << std::endl; - } else { - ioprintf(c1out, - _("Package %s is not available, but is referred to by another package.\n" - "This may mean that the package is missing, has been obsoleted, or\n" - "is only available from another source\n"),Pkg.FullName(true).c_str()); - - std::string List; - std::string VersionsList; - SPtrArray Seen = new bool[Cache.GetPkgCache()->Head().PackageCount]; - memset(Seen,0,Cache.GetPkgCache()->Head().PackageCount*sizeof(*Seen)); - APT::PackageList pkglist; - for (pkgCache::DepIterator Dep = Pkg.RevDependsList(); - Dep.end() == false; ++Dep) { - if (Dep->Type != pkgCache::Dep::Replaces) - continue; - pkgCache::PkgIterator const DP = Dep.ParentPkg(); - if (Seen[DP->ID] == true) - continue; - Seen[DP->ID] = true; - pkglist.insert(DP); - } - ShowList(c1out, _("However the following packages replace it:"), pkglist, - &AlwaysTrue, &PrettyFullName, &EmptyString); - } - c1out << std::endl; - } - return false; - } - - virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE { - APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, CacheSetHelper::CANDIDATE); - if (verset.empty() == false) - return *(verset.begin()); - else if (ShowError == true) { - _error->Error(_("Package '%s' has no installation candidate"),Pkg.FullName(true).c_str()); - virtualPkgs.insert(Pkg); - } - return pkgCache::VerIterator(Cache, 0); - } - - virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE { - if (Pkg->ProvidesList != 0) - { - APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, CacheSetHelper::NEWEST); - if (verset.empty() == false) - return *(verset.begin()); - if (ShowError == true) - ioprintf(out, _("Virtual packages like '%s' can't be removed\n"), Pkg.FullName(true).c_str()); - } - else - { - pkgCache::GrpIterator Grp = Pkg.Group(); - pkgCache::PkgIterator P = Grp.PackageList(); - for (; P.end() != true; P = Grp.NextPkg(P)) - { - if (P == Pkg) - continue; - if (P->CurrentVer != 0) { - // TRANSLATORS: Note, this is not an interactive question - ioprintf(c1out,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"), - Pkg.FullName(true).c_str(), P.FullName(true).c_str()); - break; - } - } - if (P.end() == true) - ioprintf(c1out,_("Package '%s' is not installed, so not removed\n"),Pkg.FullName(true).c_str()); - } - return pkgCache::VerIterator(Cache, 0); - } + virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE; + virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE; APT::VersionSet tryVirtualPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg, - CacheSetHelper::VerSelector const select) { - /* This is a pure virtual package and there is a single available - candidate providing it. */ - if (unlikely(Cache[Pkg].CandidateVer != 0) || Pkg->ProvidesList == 0) - return APT::VersionSet(); - - pkgCache::PkgIterator Prov; - bool found_one = false; - for (pkgCache::PrvIterator P = Pkg.ProvidesList(); P; ++P) { - pkgCache::VerIterator const PVer = P.OwnerVer(); - pkgCache::PkgIterator const PPkg = PVer.ParentPkg(); - - /* Ignore versions that are not a candidate. */ - if (Cache[PPkg].CandidateVer != PVer) - continue; - - if (found_one == false) { - Prov = PPkg; - found_one = true; - } else if (PPkg != Prov) { - // same group, so it's a foreign package - if (PPkg->Group == Prov->Group) { - // do we already have the requested arch? - if (strcmp(Pkg.Arch(), Prov.Arch()) == 0 || - strcmp(Prov.Arch(), "all") == 0 || - unlikely(strcmp(PPkg.Arch(), Prov.Arch()) == 0)) // packages have only on candidate, but just to be sure - continue; - // see which architecture we prefer more and switch to it - std::vector archs = APT::Configuration::getArchitectures(); - if (std::find(archs.begin(), archs.end(), PPkg.Arch()) < std::find(archs.begin(), archs.end(), Prov.Arch())) - Prov = PPkg; - continue; - } - found_one = false; // we found at least two - break; - } - } - - if (found_one == true) { - ioprintf(out, _("Note, selecting '%s' instead of '%s'\n"), - Prov.FullName(true).c_str(), Pkg.FullName(true).c_str()); - return APT::VersionSet::FromPackage(Cache, Prov, select, *this); - } - return APT::VersionSet(); - } + CacheSetHelper::VerSelector const select); inline bool allPkgNamedExplicitly() const { return explicitlyNamed; } - }; /*}}}*/ -- cgit v1.2.3 From 9112f77703c39d46e2e0471c48c8a5e1f93f4abf Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 13 Jul 2015 03:36:59 +0200 Subject: show or-groups in not-installed recommends and suggests lists Further abstracting our new ShowList allows to use it for containers of strings as well giving us the option to implement an or-groups display for the recommends and suggests lists which is a nice trick given that it also helps with migrating the last remaining other cases of old ShowList. --- apt-private/private-cachefile.h | 14 ++--- apt-private/private-download.cc | 13 ++-- apt-private/private-download.h | 3 +- apt-private/private-install.cc | 135 ++++++++++++++++++++-------------------- apt-private/private-output.cc | 60 ------------------ apt-private/private-output.h | 24 ++++--- 6 files changed, 95 insertions(+), 154 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-cachefile.h b/apt-private/private-cachefile.h index 4a68d9733..221852629 100644 --- a/apt-private/private-cachefile.h +++ b/apt-private/private-cachefile.h @@ -61,7 +61,7 @@ class APT_PUBLIC CacheFile : public pkgCacheFile }; /*}}}*/ -class APT_PUBLIC SortedPackageUniverse : public APT::PackageUniverse +class SortedPackageUniverse : public APT::PackageUniverse { std::vector &List; void LazyInit() const; @@ -85,12 +85,12 @@ public: }; typedef const_iterator iterator; - APT_PUBLIC const_iterator begin() const { LazyInit(); return const_iterator(data(), List.begin()); } - APT_PUBLIC const_iterator end() const { LazyInit(); return const_iterator(data(), List.end()); } - APT_PUBLIC const_iterator cbegin() const { LazyInit(); return const_iterator(data(), List.begin()); } - APT_PUBLIC const_iterator cend() const { LazyInit(); return const_iterator(data(), List.end()); } - APT_PUBLIC iterator begin() { LazyInit(); return iterator(data(), List.begin()); } - APT_PUBLIC iterator end() { LazyInit(); return iterator(data(), List.end()); } + const_iterator begin() const { LazyInit(); return const_iterator(data(), List.begin()); } + const_iterator end() const { LazyInit(); return const_iterator(data(), List.end()); } + const_iterator cbegin() const { LazyInit(); return const_iterator(data(), List.begin()); } + const_iterator cend() const { LazyInit(); return const_iterator(data(), List.end()); } + iterator begin() { LazyInit(); return iterator(data(), List.begin()); } + iterator end() { LazyInit(); return iterator(data(), List.end()); } }; #endif diff --git a/apt-private/private-download.cc b/apt-private/private-download.cc index 37fae18e9..099146187 100644 --- a/apt-private/private-download.cc +++ b/apt-private/private-download.cc @@ -78,20 +78,23 @@ bool CheckDropPrivsMustBeDisabled(pkgAcquire &Fetcher) /*{{{*/ // CheckAuth - check if each download comes form a trusted source /*{{{*/ bool CheckAuth(pkgAcquire& Fetcher, bool const PromptUser) { - std::string UntrustedList; + std::vector UntrustedList; for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I < Fetcher.ItemsEnd(); ++I) if (!(*I)->IsTrusted()) - UntrustedList += std::string((*I)->ShortDesc()) + " "; + UntrustedList.push_back((*I)->ShortDesc()); - if (UntrustedList == "") + if (UntrustedList.empty()) return true; return AuthPrompt(UntrustedList, PromptUser); } -bool AuthPrompt(std::string const &UntrustedList, bool const PromptUser) +bool AuthPrompt(std::vector const &UntrustedList, bool const PromptUser) { - ShowList(c2out,_("WARNING: The following packages cannot be authenticated!"),UntrustedList,""); + ShowList(c2out,_("WARNING: The following packages cannot be authenticated!"), UntrustedList, + [](std::string const&) { return true; }, + [](std::string const&str) { return str; }, + [](std::string const&) { return ""; }); if (_config->FindB("APT::Get::AllowUnauthenticated",false) == true) { diff --git a/apt-private/private-download.h b/apt-private/private-download.h index 0a0ac6b95..0f3db5e7a 100644 --- a/apt-private/private-download.h +++ b/apt-private/private-download.h @@ -4,6 +4,7 @@ #include #include +#include class pkgAcquire; @@ -14,7 +15,7 @@ APT_PUBLIC bool CheckAuth(pkgAcquire& Fetcher, bool const PromptUser); // show a authentication warning prompt and return true if the system // should continue -APT_PUBLIC bool AuthPrompt(std::string const &UntrustedList, bool const PromptUser); +APT_PUBLIC bool AuthPrompt(std::vector const &UntrustedList, bool const PromptUser); APT_PUBLIC bool AcquireRun(pkgAcquire &Fetcher, int const PulseInterval, bool * const Failure, bool * const TransientNetworkFailure); diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index cdca45755..0b5e33ae5 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -330,19 +330,17 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) } std::set const disappearedPkgs = PM->GetDisappearedPackages(); - if (disappearedPkgs.empty() == true) - return true; - - std::string disappear; - for (std::set::const_iterator d = disappearedPkgs.begin(); - d != disappearedPkgs.end(); ++d) - disappear.append(*d).append(" "); - - ShowList(c1out, P_("The following package disappeared from your system as\n" - "all files have been overwritten by other packages:", - "The following packages disappeared from your system as\n" - "all files have been overwritten by other packages:", disappearedPkgs.size()), disappear, ""); - c0out << _("Note: This is done automatically and on purpose by dpkg.") << std::endl; + if (disappearedPkgs.empty() == false) + { + ShowList(c1out, P_("The following package disappeared from your system as\n" + "all files have been overwritten by other packages:", + "The following packages disappeared from your system as\n" + "all files have been overwritten by other packages:", disappearedPkgs.size()), disappearedPkgs, + [](std::string const &Pkg) { return Pkg.empty() == false; }, + [](std::string const &Pkg) { return Pkg; }, + [](std::string const &) { return std::string(); }); + c0out << _("Note: This is done automatically and on purpose by dpkg.") << std::endl; + } return true; } @@ -699,8 +697,7 @@ bool DoInstall(CommandLine &CmdL) /* Print out a list of suggested and recommended packages */ { - std::string SuggestsList, RecommendsList; - std::string SuggestsVersions, RecommendsVersions; + std::list Recommends, Suggests, SingleRecommends, SingleSuggests; for (auto const &Pkg: Universe) { /* Just look at the ones we want to install */ @@ -714,77 +711,79 @@ bool DoInstall(CommandLine &CmdL) pkgCache::DepIterator Start; pkgCache::DepIterator End; D.GlobOr(Start,End); // advances D + if (Start->Type != pkgCache::Dep::Recommends && Start->Type != pkgCache::Dep::Suggests) + continue; - // FIXME: we really should display a or-group as a or-group to the user - // the problem is that ShowList is incapable of doing this - std::string RecommendsOrList,RecommendsOrVersions; - std::string SuggestsOrList,SuggestsOrVersions; - bool foundInstalledInOrGroup = false; - for(;;) { - /* Skip if package is installed already, or is about to be */ - pkgCache::PkgIterator const TarPkg = Start.TargetPkg(); - if (TarPkg->SelectedState == pkgCache::State::Install || - TarPkg->SelectedState == pkgCache::State::Hold || - Cache[Start.TargetPkg()].Install()) - { - foundInstalledInOrGroup=true; - break; - } - - /* Skip if we already saw it */ - std::string target = Start.TargetPkg().FullName(true) + " "; - if (int(SuggestsList.find(target)) != -1 || int(RecommendsList.find(target)) != -1) + // Skip if we already saw this + std::string target; + for (pkgCache::DepIterator I = Start; I != D; ++I) { - foundInstalledInOrGroup=true; - break; + if (target.empty() == false) + target.append(" | "); + target.append(I.TargetPkg().FullName(true)); } + std::list &Type = Start->Type == pkgCache::Dep::Recommends ? SingleRecommends : SingleSuggests; + if (std::find(Type.begin(), Type.end(), target) != Type.end()) + continue; + Type.push_back(target); + } - // this is a dep on a virtual pkg, check if any package that provides it - // should be installed - if(Start.TargetPkg().ProvidesList() != 0) + std::list OrList; + bool foundInstalledInOrGroup = false; + for (pkgCache::DepIterator I = Start; I != D; ++I) + { { - pkgCache::PrvIterator I = Start.TargetPkg().ProvidesList(); - for (; I.end() == false; ++I) + // satisfying package is installed and not marked for deletion + APT::VersionList installed = APT::VersionList::FromDependency(Cache, I, APT::CacheSetHelper::INSTALLED); + if (std::find_if(installed.begin(), installed.end(), + [&Cache](pkgCache::VerIterator const &Ver) { return Cache[Ver.ParentPkg()].Delete() == false; }) != installed.end()) { - pkgCache::PkgIterator Pkg = I.OwnerPkg(); - if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer() && - Pkg.CurrentVer() != 0) - foundInstalledInOrGroup=true; + foundInstalledInOrGroup = true; + break; } } - if (Start->Type == pkgCache::Dep::Suggests) - { - SuggestsOrList += target; - SuggestsOrVersions += std::string(Cache[Start.TargetPkg()].CandVersion) + "\n"; - } - - if (Start->Type == pkgCache::Dep::Recommends) { - RecommendsOrList += target; - RecommendsOrVersions += std::string(Cache[Start.TargetPkg()].CandVersion) + "\n"; + // satisfying package is upgraded to/new install + APT::VersionList upgrades = APT::VersionList::FromDependency(Cache, I, APT::CacheSetHelper::CANDIDATE); + if (std::find_if(upgrades.begin(), upgrades.end(), + [&Cache](pkgCache::VerIterator const &Ver) { return Cache[Ver.ParentPkg()].Upgrade(); }) != upgrades.end()) + { + foundInstalledInOrGroup = true; + break; + } } - if (Start >= End) - break; - ++Start; + if (OrList.empty()) + OrList.push_back(I.TargetPkg().FullName(true)); + else + OrList.push_back("| " + I.TargetPkg().FullName(true)); } - + if(foundInstalledInOrGroup == false) { - RecommendsList += RecommendsOrList; - RecommendsVersions += RecommendsOrVersions; - SuggestsList += SuggestsOrList; - SuggestsVersions += SuggestsOrVersions; + std::list &Type = Start->Type == pkgCache::Dep::Recommends ? Recommends : Suggests; + std::move(OrList.begin(), OrList.end(), std::back_inserter(Type)); } - } } - - ShowList(c1out,_("Suggested packages:"),SuggestsList,SuggestsVersions); - ShowList(c1out,_("Recommended packages:"),RecommendsList,RecommendsVersions); - + auto always_true = [](std::string const&) { return true; }; + auto string_ident = [](std::string const&str) { return str; }; + auto verbose_show_candidate = + [&Cache](std::string str) + { + if (APT::String::Startswith(str, "| ")) + str.erase(0, 2); + pkgCache::PkgIterator const Pkg = Cache->FindPkg(str); + if (Pkg.end() == true) + return ""; + return (*Cache)[Pkg].CandVersion; + }; + ShowList(c1out,_("Suggested packages:"), Suggests, + always_true, string_ident, verbose_show_candidate); + ShowList(c1out,_("Recommended packages:"), Recommends, + always_true, string_ident, verbose_show_candidate); } // See if we need to prompt @@ -792,7 +791,7 @@ bool DoInstall(CommandLine &CmdL) if (Cache->InstCount() == verset[MOD_INSTALL].size() && Cache->DelCount() == 0) return InstallPackages(Cache,false,false); - return InstallPackages(Cache,false); + return InstallPackages(Cache,false); } /*}}}*/ diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index b77efff86..b8e6dec02 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -300,66 +300,6 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/ out << output; } /*}}}*/ -// ShowList - Show a list /*{{{*/ -// --------------------------------------------------------------------- -/* This prints out a string of space separated words with a title and - a two space indent line wraped to the current screen width. */ -bool ShowList(ostream &out,string Title,string List,string VersionsList) -{ - if (List.empty() == true) - return true; - // trim trailing space - int NonSpace = List.find_last_not_of(' '); - if (NonSpace != -1) - { - List = List.erase(NonSpace + 1); - if (List.empty() == true) - return true; - } - - // Acount for the leading space - int ScreenWidth = ::ScreenWidth - 3; - - out << Title << endl; - string::size_type Start = 0; - string::size_type VersionsStart = 0; - while (Start < List.size()) - { - if(_config->FindB("APT::Get::Show-Versions",false) == true && - VersionsList.size() > 0) { - string::size_type End; - string::size_type VersionsEnd; - - End = List.find(' ',Start); - VersionsEnd = VersionsList.find('\n', VersionsStart); - - out << " " << string(List,Start,End - Start) << " (" << - string(VersionsList,VersionsStart,VersionsEnd - VersionsStart) << - ")" << endl; - - if (End == string::npos || End < Start) - End = Start + ScreenWidth; - - Start = End + 1; - VersionsStart = VersionsEnd + 1; - } else { - string::size_type End; - - if (Start + ScreenWidth >= List.size()) - End = List.size(); - else - End = List.rfind(' ',Start+ScreenWidth); - - if (End == string::npos || End < Start) - End = Start + ScreenWidth; - out << " " << string(List,Start,End - Start) << endl; - Start = End + 1; - } - } - - return false; -} - /*}}}*/ // ShowBroken - Debugging aide /*{{{*/ // --------------------------------------------------------------------- /* This prints out the names of all the packages that are broken along diff --git a/apt-private/private-output.h b/apt-private/private-output.h index b9151b245..4930fd981 100644 --- a/apt-private/private-output.h +++ b/apt-private/private-output.h @@ -34,11 +34,11 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, APT_PUBLIC void ShowBroken(std::ostream &out, CacheFile &Cache, bool const Now); APT_PUBLIC void ShowBroken(std::ostream &out, pkgCacheFile &Cache, bool const Now); -template APT_PUBLIC bool ShowList(std::ostream &out, std::string const &Title, +template APT_PUBLIC bool ShowList(std::ostream &out, std::string const &Title, Container const &cont, - std::function Predicate, - std::function PkgDisplay, - std::function VerboseDisplay) + PredicateC Predicate, + DisplayP PkgDisplay, + DisplayV VerboseDisplay) { size_t const ScreenWidth = (::ScreenWidth > 3) ? ::ScreenWidth - 3 : 0; int ScreenUsed = 0; @@ -88,8 +88,6 @@ template APT_PUBLIC bool ShowList(std::ostream &out, std::strin } return true; } -APT_DEPRECATED APT_PUBLIC bool ShowList(std::ostream &out, std::string Title, std::string List, - std::string VersionsList); void ShowNew(std::ostream &out,CacheFile &Cache); void ShowDel(std::ostream &out,CacheFile &Cache); @@ -106,12 +104,12 @@ void Stats(std::ostream &out, pkgDepCache &Dep); bool YnPrompt(bool Default=true); bool AnalPrompt(const char *Text); -APT_PUBLIC std::string PrettyFullName(pkgCache::PkgIterator const &Pkg); -APT_PUBLIC std::string CandidateVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg); -APT_PUBLIC std::function CandidateVersion(pkgCacheFile * const Cache); -APT_PUBLIC std::string CurrentToCandidateVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg); -APT_PUBLIC std::function CurrentToCandidateVersion(pkgCacheFile * const Cache); -APT_PUBLIC std::string EmptyString(pkgCache::PkgIterator const &); -APT_PUBLIC bool AlwaysTrue(pkgCache::PkgIterator const &); +std::string PrettyFullName(pkgCache::PkgIterator const &Pkg); +std::string CandidateVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg); +std::function CandidateVersion(pkgCacheFile * const Cache); +std::string CurrentToCandidateVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg); +std::function CurrentToCandidateVersion(pkgCacheFile * const Cache); +std::string EmptyString(pkgCache::PkgIterator const &); +bool AlwaysTrue(pkgCache::PkgIterator const &); #endif -- cgit v1.2.3 From 3707fd4faab3f2e2521263070b68fd0afaae2900 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 13 Jul 2015 23:10:53 +0200 Subject: avoid virtual in the iterators With a bit of trickery and the Curiously recurring template pattern we can free us from our use of virtual in the iterators were it is unneeded bloat as we never deal with pointers to iterators and similar such. Git-Dch: Ignore --- apt-private/private-cachefile.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-cachefile.h b/apt-private/private-cachefile.h index 221852629..ed9342db0 100644 --- a/apt-private/private-cachefile.h +++ b/apt-private/private-cachefile.h @@ -72,13 +72,12 @@ public: class const_iterator : public APT::Container_iterator_base::const_iterator, pkgCache::PkgIterator> { pkgCache * const Cache; - protected: - inline virtual pkgCache::PkgIterator getType(void) const APT_OVERRIDE + public: + inline pkgCache::PkgIterator getType(void) const { if (*_iter == 0) return pkgCache::PkgIterator(*Cache); return pkgCache::PkgIterator(*Cache, Cache->PkgP + *_iter); } - public: explicit const_iterator(pkgCache * const Owner, std::vector::const_iterator i): Container_iterator_base::const_iterator, pkgCache::PkgIterator>(i), Cache(Owner) {} -- cgit v1.2.3 From 4dc77823d360158d6870a5710cc8c17064f1308f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 15 Jul 2015 13:21:21 +0200 Subject: remove the compatibility markers for 4.13 abi We aren't and we will not be really compatible again with the previous stable abi, so lets drop these markers (which never made it into a released version) for good as they have outlived their intend already. Git-Dch: Ignore --- apt-private/private-install.cc | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 0b5e33ae5..116e01038 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -94,14 +94,9 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) { pkgSimulate PM(Cache); -#if APT_PKG_ABI >= 413 APT::Progress::PackageManager *progress = APT::Progress::PackageManagerProgressFactory(); pkgPackageManager::OrderResult Res = PM.DoInstall(progress); delete progress; -#else - int status_fd = _config->FindI("APT::Status-Fd",-1); - pkgPackageManager::OrderResult Res = PM.DoInstall(status_fd); -#endif if (Res == pkgPackageManager::Failed) return false; @@ -307,14 +302,9 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) _system->UnLock(); -#if APT_PKG_ABI >= 413 APT::Progress::PackageManager *progress = APT::Progress::PackageManagerProgressFactory(); pkgPackageManager::OrderResult Res = PM->DoInstall(progress); delete progress; -#else - int status_fd = _config->FindI("APT::Status-Fd", -1); - pkgPackageManager::OrderResult Res = PM->DoInstall(status_fd); -#endif if (Res == pkgPackageManager::Failed || _error->PendingError() == true) return false; -- cgit v1.2.3 From 8c7af4d4c95d0423fbd0f3baa979792504f4f45f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 16 Jul 2015 11:15:25 +0200 Subject: hide implicit deps in apt-cache again by default Before MultiArch implicits weren't a thing, so they were hidden by default by definition. Adding them for MultiArch solved many problems, but having no reliable way of detecting which dependency (and provides) is implicit or not causes problems everytime we want to output dependencies without confusing our observers with unneeded implementation details. The really notworthy point here is actually that we keep now a better record of how a dependency came to be so that we can later reason about it more easily, but that is hidden so deep down in the library internals that change is more the problems it solves than the change itself. --- apt-private/private-cmndline.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'apt-private') diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index 71dceb559..cfdc13259 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -51,6 +51,7 @@ static bool addArgumentsAPTCache(std::vector &Args, char cons addArg(0, "conflicts", "APT::Cache::ShowConflicts", 0); addArg(0, "enhances", "APT::Cache::ShowEnhances", 0); addArg(0, "recurse", "APT::Cache::RecurseDepends", 0); + addArg(0, "implicit", "APT::Cache::ShowImplicit", 0); } else if (CmdMatches("search")) { -- cgit v1.2.3 From 5465192b9aeb1ccea778950ccf2d1b7b32f2cd91 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 18 Jul 2015 18:03:54 +0200 Subject: add volatile sources support in libapt-pkg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sources are usually defined in sources.list (and co) and are pretty stable, but once in a while a frontend might want to add an additional "source" like a local .deb file to install this package (No support for 'real' sources being added this way as this is a multistep process). We had a hack in place to allow apt-get and apt to pull this of for a short while now, but other frontends are either left in the cold by this and/or the code for it looks dirty with FIXMEs plastering it and has on top of this also some problems (like including these 'volatile' sources in the srcpkgcache.bin file). So the biggest part in this commit is actually the rewrite of the cache generation as it is now potentially a three step process. The biggest problem with adding support now through is that this makes a bunch of previously mostly unusable by externs and therefore hidden classes public, so a bit of further tuneing on this now public API is in order… --- apt-private/private-cachefile.h | 21 --------------------- apt-private/private-install.cc | 21 +++------------------ 2 files changed, 3 insertions(+), 39 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-cachefile.h b/apt-private/private-cachefile.h index ed9342db0..51703b0ad 100644 --- a/apt-private/private-cachefile.h +++ b/apt-private/private-cachefile.h @@ -11,17 +11,6 @@ #include -// FIXME: we need to find a way to export this -class APT_PUBLIC SourceList : public pkgSourceList -{ - public: - // Add custom metaIndex (e.g. local files) - void AddMetaIndex(metaIndex *mi) { - SrcList.push_back(mi); - } - -}; - // class CacheFile - Cover class for some dependency cache functions /*{{{*/ class APT_PUBLIC CacheFile : public pkgCacheFile { @@ -36,16 +25,6 @@ class APT_PUBLIC CacheFile : public pkgCacheFile return false; return true; } - // FIXME: this can go once the "libapt-pkg" pkgSourceList has a way - // to add custom metaIndexes (or custom local files or so) - bool BuildSourceList(OpProgress */*Progress*/ = NULL) { - if (SrcList != NULL) - return true; - SrcList = new SourceList(); - if (SrcList->ReadMainList() == false) - return _error->Error(_("The list of sources could not be read.")); - return true; - } bool Open(bool WithLock = true) { OpTextProgress Prog(*_config); diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 116e01038..074874903 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -647,24 +648,8 @@ bool DoInstall(CommandLine &CmdL) // first check for local pkgs and add them to the cache for (const char **I = CmdL.FileList; *I != 0; I++) { - if(FileExists(*I)) - { - // FIXME: make this more elegant - std::string TypeStr = flExtension(*I) + "-file"; - pkgSourceList::Type *Type = pkgSourceList::Type::GetType(TypeStr.c_str()); - if(Type != 0) - { - std::vector List; - std::map Options; - if(Type->CreateItem(List, *I, "", "", Options)) - { - // we have our own CacheFile that gives us a SourceList - // with superpowerz - SourceList *sources = (SourceList*)Cache.GetSourceList(); - sources->AddMetaIndex(List[0]); - } - } - } + if(FileExists(*I) && flExtension(*I) == "deb") + Cache.GetSourceList()->AddVolatileFile(new debDebPkgFileIndex(*I)); } // then open the cache -- cgit v1.2.3 From 6d7122b5356c0b4d8f51aafdfc1c232392fca695 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 11 Aug 2015 15:58:03 +0200 Subject: Annotate more methods with APT_OVERRIDE Gbp-Dch: ignore Reported-By: g++ -Wsuggest-override Thanks: g++ -Wsuggest-override --- apt-private/private-list.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/private-list.cc b/apt-private/private-list.cc index aa3a2c24b..c4d5e8bc3 100644 --- a/apt-private/private-list.cc +++ b/apt-private/private-list.cc @@ -59,7 +59,7 @@ class PackageNameMatcher : public Matcher for(J=filters.begin(); J != filters.end(); ++J) delete *J; } - virtual bool operator () (const pkgCache::PkgIterator &P) + virtual bool operator () (const pkgCache::PkgIterator &P) APT_OVERRIDE { for(J=filters.begin(); J != filters.end(); ++J) { -- cgit v1.2.3 From 94171725b18be91ddcc2530c5fe5f40e78d041c1 Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Tue, 11 Aug 2015 20:08:43 +0200 Subject: Replace all "press enter" occurrences with "press [Enter]" Thanks: Andre Felipe Machado for initial patch Closes: 414848 --- apt-private/acqprogress.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/acqprogress.cc b/apt-private/acqprogress.cc index f6c3d1204..62b2c13d0 100644 --- a/apt-private/acqprogress.cc +++ b/apt-private/acqprogress.cc @@ -296,7 +296,7 @@ bool AcqTextStatus::MediaChange(std::string Media, std::string Drive) clearLastLine(); ioprintf(out,_("Media change: please insert the disc labeled\n" " '%s'\n" - "in the drive '%s' and press enter\n"), + "in the drive '%s' and press [Enter]\n"), Media.c_str(),Drive.c_str()); char C = 0; -- cgit v1.2.3 From 6c413b188618b9fcb5368b60971dfa5d45b3cd74 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 13 Aug 2015 10:49:31 +0200 Subject: Mark SPtr as deprecated, and convert users to std::unique_ptr Switch to std::unique_ptr, as this is safer than SPtr. --- apt-private/private-install.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 074874903..d2b4bed51 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -128,7 +128,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) pkgSourceList *List = Cache.GetSourceList(); // Create the package manager and prepare to download - SPtr PM= _system->CreatePM(Cache); + std::unique_ptr PM(_system->CreatePM(Cache)); if (PM->GetArchives(&Fetcher,List,&Recs) == false || _error->PendingError() == true) return false; @@ -492,9 +492,9 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, if (Cache->BrokenCount() != 0) BrokenFix = true; - SPtr Fix; + std::unique_ptr Fix(nullptr); if (_config->FindB("APT::Get::CallResolver", true) == true) - Fix = new pkgProblemResolver(Cache); + Fix.reset(new pkgProblemResolver(Cache)); unsigned short fallback = MOD_INSTALL; if (strcasecmp(CmdL.FileList[0],"remove") == 0) @@ -526,8 +526,8 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, } - TryToInstall InstallAction(Cache, Fix, BrokenFix); - TryToRemove RemoveAction(Cache, Fix); + TryToInstall InstallAction(Cache, Fix.get(), BrokenFix); + TryToRemove RemoveAction(Cache, Fix.get()); // new scope for the ActionGroup { -- cgit v1.2.3 From df7c9fd2224c1de4a155796e292fb919f559a674 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 13 Aug 2015 21:14:00 +0200 Subject: Accept --upgradeable as synonym for --upgradable It's a tiny diff, so why not? But no need to document it. Closes: #787846 --- apt-private/private-cmndline.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'apt-private') diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index cfdc13259..fa8416824 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -242,6 +242,7 @@ static bool addArgumentsAPT(std::vector &Args, char const * c if (CmdMatches("list")) { addArg(0,"installed","APT::Cmd::Installed",0); + addArg(0,"upgradeable","APT::Cmd::Upgradable",0); addArg(0,"upgradable","APT::Cmd::Upgradable",0); addArg(0,"manual-installed","APT::Cmd::Manual-Installed",0); addArg('v', "verbose", "APT::Cmd::List-Include-Summary", 0); -- cgit v1.2.3 From b381a482eab0fc7b65b63cf0512ef1f97d775e34 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 14 Aug 2015 11:49:45 +0200 Subject: Replace --force-yes by various options starting with --allow This enables more fine grained control over such exceptions. --- apt-private/private-cmndline.cc | 3 +++ apt-private/private-download.cc | 6 ++++-- apt-private/private-install.cc | 43 +++++++++++++++++++++++++++-------------- 3 files changed, 36 insertions(+), 16 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index fa8416824..487349c8c 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -202,6 +202,9 @@ static bool addArgumentsAPTGet(std::vector &Args, char const addArg(0,"ignore-hold","APT::Ignore-Hold",0); addArg(0,"upgrade","APT::Get::upgrade",0); addArg(0,"only-upgrade","APT::Get::Only-Upgrade",0); + addArg(0,"allow-change-held-packages","APT::Get::allow-change-held-packages",CommandLine::Boolean); + addArg(0,"allow-remove-essential","APT::Get::allow-remove-essential",CommandLine::Boolean); + addArg(0,"allow-downgrades","APT::Get::allow-downgrades",CommandLine::Boolean); addArg(0,"force-yes","APT::Get::force-yes",0); addArg(0,"print-uris","APT::Get::Print-URIs",0); addArg(0,"trivial-only","APT::Get::Trivial-Only",0); diff --git a/apt-private/private-download.cc b/apt-private/private-download.cc index 099146187..18a9b1fbc 100644 --- a/apt-private/private-download.cc +++ b/apt-private/private-download.cc @@ -114,10 +114,12 @@ bool AuthPrompt(std::vector const &UntrustedList, bool const Prompt return true; } - else if (_config->FindB("APT::Get::Force-Yes",false) == true) + else if (_config->FindB("APT::Get::Force-Yes",false) == true) { + _error->Warning(_("--force-yes is deprecated, use one of the options starting with --allow instead.")); return true; + } - return _error->Error(_("There are problems and -y was used without --force-yes")); + return _error->Error(_("There were unauthenticated packages and -y was used without --allow-unauthenticated")); } /*}}}*/ bool AcquireRun(pkgAcquire &Fetcher, int const PulseInterval, bool * const Failure, bool * const TransientNetworkFailure)/*{{{*/ diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index d2b4bed51..96e33f7de 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -58,7 +58,8 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) } } - bool Fail = false; + bool Hold = false; + bool Downgrade = false; bool Essential = false; // Show all the various warning indicators @@ -66,13 +67,17 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) ShowNew(c1out,Cache); if (ShwKept == true) ShowKept(c1out,Cache); - Fail |= !ShowHold(c1out,Cache); + Hold = !ShowHold(c1out,Cache); if (_config->FindB("APT::Get::Show-Upgraded",true) == true) ShowUpgraded(c1out,Cache); - Fail |= !ShowDowngraded(c1out,Cache); + Downgrade = !ShowDowngraded(c1out,Cache); + if (_config->FindB("APT::Get::Download-Only",false) == false) Essential = !ShowEssential(c1out,Cache); - Fail |= Essential; + + // All kinds of failures + bool Fail = (Essential || Downgrade || Hold); + Stats(c1out,Cache); // Sanity check @@ -89,7 +94,25 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) // No remove flag if (Cache->DelCount() != 0 && _config->FindB("APT::Get::Remove",true) == false) return _error->Error(_("Packages need to be removed but remove is disabled.")); - + + // Fail safe check + if (_config->FindI("quiet",0) >= 2 || + _config->FindB("APT::Get::Assume-Yes",false) == true) + { + if (_config->FindB("APT::Get::Force-Yes",false) == true) { + _error->Warning(_("--force-yes is deprecated, use one of the options starting with --allow instead.")); + } + + if (Fail == true && _config->FindB("APT::Get::Force-Yes",false) == false) { + if (Essential == true && _config->FindB("APT::Get::allow-remove-essential", false) == false) + return _error->Error(_("Essential packages were removed and -y was used without --allow-remove-essential.")); + if (Downgrade == true && _config->FindB("APT::Get::allow-downgrades", false) == false) + return _error->Error(_("Packages were downgraded and -y was used without --allow-downgrades.")); + if (Hold == true && _config->FindB("APT::Get::allow-change-held-packages", false) == false) + return _error->Error(_("Held packages were changed and -y was used without --allow-change-held-packages.")); + } + } + // Run the simulator .. if (_config->FindB("APT::Get::Simulate") == true) { @@ -173,15 +196,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety) if (CheckFreeSpaceBeforeDownload(_config->FindDir("Dir::Cache::Archives"), (FetchBytes - FetchPBytes)) == false) return false; - // Fail safe check - if (_config->FindI("quiet",0) >= 2 || - _config->FindB("APT::Get::Assume-Yes",false) == true) - { - if (Fail == true && _config->FindB("APT::Get::Force-Yes",false) == false) - return _error->Error(_("There are problems and -y was used without --force-yes")); - } - - if (Essential == true && Safety == true) + if (Essential == true && Safety == true && _config->FindB("APT::Get::allow-remove-essential", false) == false) { if (_config->FindB("APT::Get::Trivial-Only",false) == true) return _error->Error(_("Trivial Only specified but this is not a trivial operation.")); -- cgit v1.2.3 From f66738d7fb8978eaa30a179ae4f3bcc4ca7aa58f Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 14 Aug 2015 18:27:24 +0200 Subject: Make auto-remove and auto-clean aliases for the versions without - Some people type them instead of autoremove and autoclean, so make them happy. Closes: #274159 Makes-Happy: Ansgar --- apt-private/private-cmndline.cc | 4 ++-- apt-private/private-install.cc | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index 487349c8c..3a1564b23 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -169,14 +169,14 @@ static bool addArgumentsAPTGet(std::vector &Args, char const addArg(0,"format","APT::Get::IndexTargets::Format", CommandLine::HasArg); addArg(0,"release-info","APT::Get::IndexTargets::ReleaseInfo", 0); } - else if (CmdMatches("clean", "autoclean", "check", "download", "changelog") || + else if (CmdMatches("clean", "autoclean", "auto-clean", "check", "download", "changelog") || CmdMatches("markauto", "unmarkauto")) // deprecated commands ; else if (CmdMatches("moo")) addArg(0, "color", "APT::Moo::Color", 0); if (CmdMatches("install", "remove", "purge", "upgrade", "dist-upgrade", - "dselect-upgrade", "autoremove", "clean", "autoclean", "check", + "dselect-upgrade", "autoremove", "auto-remove", "clean", "autoclean", "auto-clean", "check", "build-dep", "full-upgrade", "source")) { addArg('s', "simulate", "APT::Get::Simulate", 0); diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 96e33f7de..e61c4ca51 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -519,7 +519,8 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, _config->Set("APT::Get::Purge", true); fallback = MOD_REMOVE; } - else if (strcasecmp(CmdL.FileList[0], "autoremove") == 0) + else if (strcasecmp(CmdL.FileList[0], "autoremove") == 0 || + strcasecmp(CmdL.FileList[0], "auto-remove") == 0) { _config->Set("APT::Get::AutomaticRemove", "true"); fallback = MOD_REMOVE; -- cgit v1.2.3 From 7a139fa8bf2c18da54b5837c9290ba5b77e9c629 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 15 Aug 2015 10:44:57 +0200 Subject: update: Check if the cache could be opened, don't just assume it This seems to cause Bug#756162, as in that case the depcache was NULL. I'm not entirely sure how that happens, but it's better to be check here rather then crash later on. Closes: #756162 --- apt-private/private-update.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/private-update.cc b/apt-private/private-update.cc index 73a82e988..1323771f0 100644 --- a/apt-private/private-update.cc +++ b/apt-private/private-update.cc @@ -84,7 +84,8 @@ bool DoUpdate(CommandLine &CmdL) if (_config->FindB("APT::Cmd::Show-Update-Stats", false) == true) { int upgradable = 0; - Cache.Open(); + if (Cache.Open() == false) + return false; for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() != true; ++I) { pkgDepCache::StateCache &state = Cache[I]; -- cgit v1.2.3 From 3b9eaca8c6adba831078749c4a3819f76e373df7 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 16 Aug 2015 17:07:43 +0200 Subject: install: If package already is the newest version, display version Also do it unconditionally, as it does not hurt. Closes: #315149 --- apt-private/private-install.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index e61c4ca51..4a589a263 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -816,8 +816,9 @@ void TryToInstall::operator() (pkgCache::VerIterator const &Ver) { else Cache->GetDepCache()->SetReInstall(Pkg, true); } else - ioprintf(c1out,_("%s is already the newest version.\n"), - Pkg.FullName(true).c_str()); + // TRANSLATORS: First string is package name, second is version + ioprintf(c1out,_("%s is already the newest version (%s).\n"), + Pkg.FullName(true).c_str(), Pkg.CurrentVer().VerStr()); } // Install it with autoinstalling enabled (if we not respect the minial -- cgit v1.2.3 From 1040dc888db00fdb0fe059e6b847fdc88fe53d80 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 16 Aug 2015 23:11:07 +0200 Subject: Replace "extra" in "the following extra packages [...]" by "additional" This breaks the translation for no big gain, but we broke enough strings already for that to not really matter anymore. Closes: #82430 --- apt-private/private-install.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 4a589a263..844fcbc7e 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -682,7 +682,7 @@ bool DoInstall(CommandLine &CmdL) to what the user asked */ SortedPackageUniverse Universe(Cache); if (Cache->InstCount() != verset[MOD_INSTALL].size()) - ShowList(c1out, _("The following extra packages will be installed:"), Universe, + ShowList(c1out, _("The following additional packages will be installed:"), Universe, PkgIsExtraInstalled(&Cache, &verset[MOD_INSTALL]), &PrettyFullName, CandidateVersion(&Cache)); -- cgit v1.2.3 From 44d9e9f91b6e87717844a7ec562bd38886a57aa6 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 17 Aug 2015 10:10:57 +0200 Subject: Do not crash in 'apt show' for non-installed packages For a non-installed package, manual_installed was set to the null pointer. This was passed to Tag::Rewrite, which expects an string (empty for null-type values) and the conversion from null pointer to string does not work correctly. --- apt-private/private-show.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-private') diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc index 790bc0092..3a393b746 100644 --- a/apt-private/private-show.cc +++ b/apt-private/private-show.cc @@ -94,7 +94,7 @@ static bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V, if (is_installed) manual_installed = !(state.Flags & pkgCache::Flag::Auto) ? "yes" : "no"; else - manual_installed = 0; + manual_installed = ""; // FIXME: add verbose that does not do the removal of the tags? std::vector RW; -- cgit v1.2.3 From 3dddcdf2432e78f37c74d8c76c2c519a8d935ab2 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 17 Aug 2015 18:33:22 +0200 Subject: Re-add support for G++ 4.8 and configure travis to use it This makes tests work again! Gbp-Dch: ignore --- apt-private/private-cachefile.cc | 2 +- apt-private/private-cacheset.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-cachefile.cc b/apt-private/private-cachefile.cc index 2b2050684..32cad1c33 100644 --- a/apt-private/private-cachefile.cc +++ b/apt-private/private-cachefile.cc @@ -33,7 +33,7 @@ static bool SortPackagesByName(pkgCache * const Owner, return strcmp(Owner->StrP + GA->Name, Owner->StrP + GB->Name) <= 0; } SortedPackageUniverse::SortedPackageUniverse(CacheFile &Cache) : - PackageUniverse{Cache}, List{Cache.UniverseList} + PackageUniverse{Cache}, List(Cache.UniverseList) { } void SortedPackageUniverse::LazyInit() const diff --git a/apt-private/private-cacheset.cc b/apt-private/private-cacheset.cc index 36d40117c..8db736507 100644 --- a/apt-private/private-cacheset.cc +++ b/apt-private/private-cacheset.cc @@ -118,7 +118,7 @@ CacheSetHelperVirtuals::CacheSetHelperVirtuals(bool const ShowErrors, GlobalErro // CacheSetHelperAPTGet - responsible for message telling from the CacheSets/*{{{*/ CacheSetHelperAPTGet::CacheSetHelperAPTGet(std::ostream &out) : - APT::CacheSetHelper{true}, out{out} + APT::CacheSetHelper{true}, out(out) { explicitlyNamed = true; } -- cgit v1.2.3