+ APT::StateChanges approvedStates;
+ if (_config->FindB("dpkg::selection::remove::approved", true))
+ {
+ for (auto && I: List)
+ if (I.Op == Item::Remove && Cache[I.Pkg].Delete())
+ approvedStates.Remove(FindToBeRemovedVersion(I.Pkg));
+ else if (I.Op == Item::Purge && Cache[I.Pkg].Purge())
+ approvedStates.Purge(FindToBeRemovedVersion(I.Pkg));
+ if (approvedStates.Save(false) == false)
+ {
+ _error->Error("Couldn't record the approved state changes as dpkg selection states");
+ if (currentStates.Save(false) == false)
+ _error->Error("Couldn't restore dpkg selection states which were present before this interaction!");
+ return false;
+ }
+
+ {
+ std::vector<bool> toBeRemoved(Cache.Head().PackageCount, false);
+ std::vector<bool> toBePurged(Cache.Head().PackageCount, false);
+ for (auto Pkg = Cache.PkgBegin(); Pkg.end() == false; ++Pkg)
+ if (Cache[Pkg].Purge())
+ toBePurged[Pkg->ID] = true;
+ else if (Cache[Pkg].Delete())
+ toBeRemoved[Pkg->ID] = true;
+ for (auto && I: approvedStates.Remove())
+ toBeRemoved[I.ParentPkg()->ID] = false;
+ for (auto && I: approvedStates.Purge())
+ toBePurged[I.ParentPkg()->ID] = false;
+ if (std::find(toBeRemoved.begin(), toBeRemoved.end(), true) != toBeRemoved.end())
+ {
+ if (ConfigurePending)
+ List.emplace(std::prev(List.end()), Item::RemovePending, pkgCache::PkgIterator());
+ else
+ List.emplace_back(Item::RemovePending, pkgCache::PkgIterator());
+ }
+ if (std::find(toBePurged.begin(), toBePurged.end(), true) != toBePurged.end())
+ {
+ if (ConfigurePending)
+ List.emplace(std::prev(List.end()), Item::PurgePending, pkgCache::PkgIterator());
+ else
+ List.emplace_back(Item::PurgePending, pkgCache::PkgIterator());
+ }
+ }
+ }