diff options
-rw-r--r-- | apt-pkg/algorithms.cc | 65 | ||||
-rw-r--r-- | apt-pkg/algorithms.h | 10 | ||||
-rw-r--r-- | apt-pkg/deb/dpkgpm.cc | 49 | ||||
-rw-r--r-- | apt-pkg/deb/dpkgpm.h | 9 | ||||
-rw-r--r-- | apt-pkg/packagemanager.cc | 7 | ||||
-rw-r--r-- | apt-pkg/packagemanager.h | 2 |
6 files changed, 111 insertions, 31 deletions
diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index b173979c3..65c5ff85d 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -25,22 +25,29 @@ #include <apt-pkg/pkgcache.h> #include <apt-pkg/cacheiterators.h> #include <apt-pkg/prettyprinters.h> +#include <apt-pkg/dpkgpm.h> #include <string.h> #include <string> #include <cstdlib> #include <iostream> +#include <utility> #include <apti18n.h> /*}}}*/ using namespace std; +class APT_HIDDEN pkgSimulatePrivate +{ +public: + std::vector<pkgDPkgPM::Item> List; +}; // Simulate::Simulate - Constructor /*{{{*/ // --------------------------------------------------------------------- /* The legacy translations here of input Pkg iterators is obsolete, this is not necessary since the pkgCaches are fully shared now. */ pkgSimulate::pkgSimulate(pkgDepCache *Cache) : pkgPackageManager(Cache), - d(NULL), iPolicy(Cache), + d(new pkgSimulatePrivate()), iPolicy(Cache), Sim(&Cache->GetCache(),&iPolicy), group(Sim) { @@ -58,6 +65,7 @@ pkgSimulate::pkgSimulate(pkgDepCache *Cache) : pkgPackageManager(Cache), pkgSimulate::~pkgSimulate() { delete[] Flags; + delete d; } /*}}}*/ // Simulate::Describe - Describe a package /*{{{*/ @@ -90,7 +98,14 @@ void pkgSimulate::Describe(PkgIterator Pkg,ostream &out,bool Current,bool Candid // Simulate::Install - Simulate unpacking of a package /*{{{*/ // --------------------------------------------------------------------- /* */ -bool pkgSimulate::Install(PkgIterator iPkg,string /*File*/) +bool pkgSimulate::Install(PkgIterator iPkg,string File) +{ + if (iPkg.end() || File.empty()) + return false; + d->List.emplace_back(pkgDPkgPM::Item::Install, iPkg, File); + return true; +} +bool pkgSimulate::RealInstall(PkgIterator iPkg,string /*File*/) { // Adapt the iterator PkgIterator Pkg = Sim.FindPkg(iPkg.Name(), iPkg.Arch()); @@ -138,6 +153,13 @@ bool pkgSimulate::Install(PkgIterator iPkg,string /*File*/) however. */ bool pkgSimulate::Configure(PkgIterator iPkg) { + if (iPkg.end()) + return false; + d->List.emplace_back(pkgDPkgPM::Item::Configure, iPkg); + return true; +} +bool pkgSimulate::RealConfigure(PkgIterator iPkg) +{ // Adapt the iterator PkgIterator Pkg = Sim.FindPkg(iPkg.Name(), iPkg.Arch()); @@ -188,6 +210,13 @@ bool pkgSimulate::Configure(PkgIterator iPkg) /* */ bool pkgSimulate::Remove(PkgIterator iPkg,bool Purge) { + if (iPkg.end()) + return false; + d->List.emplace_back(Purge ? pkgDPkgPM::Item::Purge : pkgDPkgPM::Item::Remove, iPkg); + return true; +} +bool pkgSimulate::RealRemove(PkgIterator iPkg,bool Purge) +{ // Adapt the iterator PkgIterator Pkg = Sim.FindPkg(iPkg.Name(), iPkg.Arch()); if (Pkg.end() == true) @@ -232,6 +261,38 @@ void pkgSimulate::ShortBreaks() cout << ']' << endl; } /*}}}*/ +bool pkgSimulate::Go2(APT::Progress::PackageManager *) /*{{{*/ +{ + if (pkgDPkgPM::ExpandPendingCalls(d->List, Cache) == false) + return false; + for (auto && I : d->List) + switch (I.Op) + { + case pkgDPkgPM::Item::Install: + if (RealInstall(I.Pkg, I.File) == false) + return false; + break; + case pkgDPkgPM::Item::Configure: + if (RealConfigure(I.Pkg) == false) + return false; + break; + case pkgDPkgPM::Item::Remove: + if (RealRemove(I.Pkg, false) == false) + return false; + break; + case pkgDPkgPM::Item::Purge: + if (RealRemove(I.Pkg, true) == false) + return false; + break; + case pkgDPkgPM::Item::ConfigurePending: + case pkgDPkgPM::Item::TriggersPending: + case pkgDPkgPM::Item::RemovePending: + case pkgDPkgPM::Item::PurgePending: + return _error->Error("Internal error, simulation encountered unexpected pending item"); + } + return true; +} + /*}}}*/ // ApplyStatus - Adjust for non-ok packages /*{{{*/ // --------------------------------------------------------------------- /* We attempt to change the state of the all packages that have failed diff --git a/apt-pkg/algorithms.h b/apt-pkg/algorithms.h index c1a26587d..5148ff19d 100644 --- a/apt-pkg/algorithms.h +++ b/apt-pkg/algorithms.h @@ -52,9 +52,10 @@ using std::ostream; #endif +class pkgSimulatePrivate; class pkgSimulate : public pkgPackageManager /*{{{*/ { - void * const d; + pkgSimulatePrivate * const d; protected: class Policy : public pkgDepCache::Policy @@ -81,9 +82,16 @@ class pkgSimulate : public pkgPackageManager /*{{{*/ virtual bool Configure(PkgIterator Pkg) APT_OVERRIDE; virtual bool Remove(PkgIterator Pkg,bool Purge) APT_OVERRIDE; + // FIXME: trick to avoid ABI break for virtual reimplementation; fix on next ABI break +public: + APT_HIDDEN bool Go2(APT::Progress::PackageManager * progress); + private: APT_HIDDEN void ShortBreaks(); APT_HIDDEN void Describe(PkgIterator iPkg,std::ostream &out,bool Current,bool Candidate); + APT_HIDDEN bool RealInstall(PkgIterator Pkg,std::string File); + APT_HIDDEN bool RealConfigure(PkgIterator Pkg); + APT_HIDDEN bool RealRemove(PkgIterator Pkg,bool Purge); public: diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index d14155d01..4a49774f8 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1297,37 +1297,34 @@ static void cleanUpTmpDir(char * const tmpdir) /*{{{*/ * through to human readable (and i10n-able) * names and calculates a percentage for each step. */ -bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) +static bool ItemIsEssential(pkgDPkgPM::Item const &I) +{ + static auto const cachegen = _config->Find("pkgCacheGen::Essential"); + if (cachegen == "none" || cachegen == "native") + return true; + if (unlikely(I.Pkg.end())) + return true; + return (I.Pkg->Flags & pkgCache::Flag::Essential) != 0; +} +bool pkgDPkgPM::ExpandPendingCalls(std::vector<Item> &List, pkgDepCache &Cache) { - // we remove the last configures (and after that removes) from the list here - // as they will be covered by the pending calls, so explicit calls are busy work - decltype(List)::const_iterator::difference_type explicitIdx = - std::distance(List.cbegin(), - _config->FindB("Dpkg::ExplicitLastConfigure", false) ? List.cend() : - std::find_if_not( - std::find_if_not(List.crbegin(), List.crend(), [](Item const &i) { return i.Op == Item::Configure; }), - List.crend(), [](Item const &i) { return i.Op == Item::Remove || i.Op == Item::Purge; }).base()); - - // explicitely remove everything for hookscripts and progress building { std::unordered_set<decltype(pkgCache::Package::ID)> alreadyRemoved; for (auto && I : List) if (I.Op == Item::Remove || I.Op == Item::Purge) alreadyRemoved.insert(I.Pkg->ID); - decltype(List) AppendList; + std::remove_reference<decltype(List)>::type AppendList; for (auto Pkg = Cache.PkgBegin(); Pkg.end() == false; ++Pkg) if (Cache[Pkg].Delete() && alreadyRemoved.insert(Pkg->ID).second == true) AppendList.emplace_back(Cache[Pkg].Purge() ? Item::Purge : Item::Remove, Pkg); std::move(AppendList.begin(), AppendList.end(), std::back_inserter(List)); } - - // explicitely configure everything for hookscripts and progress building { std::unordered_set<decltype(pkgCache::Package::ID)> alreadyConfigured; for (auto && I : List) if (I.Op == Item::Configure) alreadyConfigured.insert(I.Pkg->ID); - decltype(List) AppendList; + std::remove_reference<decltype(List)>::type AppendList; for (auto && I : List) if (I.Op == Item::Install && alreadyConfigured.insert(I.Pkg->ID).second == true) AppendList.emplace_back(Item::Configure, I.Pkg); @@ -1336,15 +1333,21 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) AppendList.emplace_back(Item::Configure, Pkg); std::move(AppendList.begin(), AppendList.end(), std::back_inserter(List)); } + return true; +} +bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) +{ + // we remove the last configures (and after that removes) from the list here + // as they will be covered by the pending calls, so explicit calls are busy work + decltype(List)::const_iterator::difference_type explicitIdx = + std::distance(List.cbegin(), + _config->FindB("Dpkg::ExplicitLastConfigure", false) ? List.cend() : + std::find_if_not( + std::find_if_not(List.crbegin(), List.crend(), [](Item const &i) { return i.Op == Item::Configure; }), + List.crend(), [](Item const &i) { return i.Op == Item::Remove || i.Op == Item::Purge; }).base()); - auto const ItemIsEssential = [](pkgDPkgPM::Item const &I) { - static auto const cachegen = _config->Find("pkgCacheGen::Essential"); - if (cachegen == "none" || cachegen == "native") - return true; - if (unlikely(I.Pkg.end())) - return true; - return (I.Pkg->Flags & pkgCache::Flag::Essential) != 0; - }; + // explicitely remove&configure everything for hookscripts and progress building + ExpandPendingCalls(List, Cache); auto const StripAlreadyDoneFromPending = [&](APT::VersionVector & Pending) { Pending.erase(std::remove_if(Pending.begin(), Pending.end(), [&](pkgCache::VerIterator const &Ver) { diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h index 07c99aead..193754644 100644 --- a/apt-pkg/deb/dpkgpm.h +++ b/apt-pkg/deb/dpkgpm.h @@ -76,7 +76,8 @@ class pkgDPkgPM : public pkgPackageManager // progress reporting unsigned int PackagesDone; unsigned int PackagesTotal; - + + public: struct Item { enum Ops {Install, Configure, Remove, Purge, ConfigurePending, TriggersPending, @@ -86,8 +87,8 @@ class pkgDPkgPM : public pkgPackageManager Item(Ops Op,PkgIterator Pkg,std::string File = "") : Op(Op), File(File), Pkg(Pkg) {}; Item() {}; - }; + protected: std::vector<Item> List; // Helpers @@ -126,7 +127,7 @@ class pkgDPkgPM : public pkgPackageManager virtual bool Remove(PkgIterator Pkg,bool Purge = false) APT_OVERRIDE; virtual bool Go(APT::Progress::PackageManager *progress) APT_OVERRIDE; - virtual bool Go(int StatusFd=-1) APT_OVERRIDE; + APT_DEPRECATED_MSG("Use overload with explicit progress manager") virtual bool Go(int StatusFd=-1) APT_OVERRIDE; virtual void Reset() APT_OVERRIDE; @@ -134,6 +135,8 @@ class pkgDPkgPM : public pkgPackageManager pkgDPkgPM(pkgDepCache *Cache); virtual ~pkgDPkgPM(); + + APT_HIDDEN static bool ExpandPendingCalls(std::vector<Item> &List, pkgDepCache &Cache); }; void SigINT(int sig); diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 7fdd0393f..3d9c44555 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -1148,7 +1148,12 @@ pkgPackageManager::DoInstallPostFork(int statusFd) pkgPackageManager::OrderResult pkgPackageManager::DoInstallPostFork(APT::Progress::PackageManager *progress) { - bool goResult = Go(progress); + bool goResult; + auto simulation = dynamic_cast<pkgSimulate*>(this); + if (simulation == nullptr) + goResult = Go(progress); + else + goResult = simulation->Go2(progress); if(goResult == false) return Failed; diff --git a/apt-pkg/packagemanager.h b/apt-pkg/packagemanager.h index 25b6ee7c9..5046e2dc0 100644 --- a/apt-pkg/packagemanager.h +++ b/apt-pkg/packagemanager.h @@ -99,7 +99,7 @@ class pkgPackageManager : protected pkgCache::Namespace virtual bool Configure(PkgIterator /*Pkg*/) {return false;}; virtual bool Remove(PkgIterator /*Pkg*/,bool /*Purge*/=false) {return false;}; virtual bool Go(APT::Progress::PackageManager * /*progress*/) {return true;}; - virtual bool Go(int /*statusFd*/=-1) {return true;}; + APT_DEPRECATED_MSG("Use overload with explicit progress manager") virtual bool Go(int /*statusFd*/=-1) {return true;}; virtual void Reset() {}; |