diff options
| author | Julian Andres Klode <julian.klode@canonical.com> | 2024-04-12 14:24:33 +0200 |
|---|---|---|
| committer | Julian Andres Klode <julian.klode@canonical.com> | 2024-04-12 15:57:36 +0200 |
| commit | d3274a11d9e153cd996b89436b01d00b218a4985 (patch) | |
| tree | 1aab3596377651a3ae9c8a0d77de3ce972fe35e9 | |
| parent | abfae1aec588c1b4ae46f229d8312a3c5e6b8b7a (diff) | |
Show Recommends/Suggests for upgrades too, move them down
Extract the code to show them into its own function and call
it in the old place for output version < 30, or after the
dependencies being installed for new output format.
| -rw-r--r-- | apt-private/private-install.cc | 189 |
1 files changed, 98 insertions, 91 deletions
diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 70356ea28..26b81b052 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -139,6 +139,7 @@ struct WarnUsrMerge { } }; #endif +static void ShowWeakDependencies(CacheFile &Cache); bool InstallPackages(CacheFile &Cache, APT::PackageVector &HeldBackPackages, bool ShwKept, bool Ask, bool Safety, std::string const &Hook, CommandLine const &CmdL) { auto outVer = _config->FindI("APT::Output-Version"); @@ -225,6 +226,8 @@ bool InstallPackages(CacheFile &Cache, APT::PackageVector &HeldBackPackages, boo if (_config->FindI("APT::Output-Version") < 30) ShowDel(c1out,Cache); ShowNew(c1out,Cache); + if (_config->FindI("APT::Output-Version") >= 30) + ShowWeakDependencies(Cache); if (_config->FindI("APT::Output-Version") >= 30 && _config->FindB("APT::Get::Show-Upgraded",true) == true) ShowUpgraded(c1out,Cache); if (ShwKept == true) @@ -912,6 +915,99 @@ struct PkgIsExtraInstalled { return std::find(verset->begin(), verset->end(), Cand) == verset->end(); } }; +/* Print out a list of suggested and recommended packages */ +static void ShowWeakDependencies(CacheFile &Cache) +{ + std::list<std::string> Recommends, Suggests, SingleRecommends, SingleSuggests; + SortedPackageUniverse Universe(Cache); + for (auto const &Pkg: Universe) + { + /* Just look at the ones we want to install */ + if ((*Cache)[Pkg].Install() == false) + continue; + + // get the recommends/suggests for the candidate ver + pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache); + for (pkgCache::DepIterator D = CV.DependsList(); D.end() == false; ) + { + pkgCache::DepIterator Start; + pkgCache::DepIterator End; + D.GlobOr(Start,End); // advances D + if (Start->Type != pkgCache::Dep::Recommends && Start->Type != pkgCache::Dep::Suggests) + continue; + + { + // Skip if we already saw this + std::string target; + for (pkgCache::DepIterator I = Start; I != D; ++I) + { + if (target.empty() == false) + target.append(" | "); + target.append(I.TargetPkg().FullName(true)); + } + std::list<std::string> &Type = Start->Type == pkgCache::Dep::Recommends ? SingleRecommends : SingleSuggests; + if (std::find(Type.begin(), Type.end(), target) != Type.end()) + continue; + Type.push_back(target); + } + + std::list<std::string> OrList; + bool foundInstalledInOrGroup = false; + for (pkgCache::DepIterator I = Start; I != D; ++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()) + { + foundInstalledInOrGroup = true; + break; + } + } + + { + // 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 (OrList.empty()) + OrList.push_back(I.TargetPkg().FullName(true)); + else + OrList.push_back("| " + I.TargetPkg().FullName(true)); + } + + if(foundInstalledInOrGroup == false) + { + std::list<std::string> &Type = Start->Type == pkgCache::Dep::Recommends ? Recommends : Suggests; + std::move(OrList.begin(), OrList.end(), std::back_inserter(Type)); + } + } + } + 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); +} + bool DoInstall(CommandLine &CmdL) { CacheFile Cache; @@ -947,98 +1043,9 @@ bool DoInstall(CommandLine &CmdL) PkgIsExtraInstalled(&Cache, &verset[MOD_INSTALL]), &PrettyFullName, CandidateVersion(&Cache), "APT::Color::Green"); - /* Print out a list of suggested and recommended packages */ - { - std::list<std::string> Recommends, Suggests, SingleRecommends, SingleSuggests; - SortedPackageUniverse Universe(Cache); - for (auto const &Pkg: Universe) - { - /* Just look at the ones we want to install */ - if ((*Cache)[Pkg].Install() == false) - continue; - - // get the recommends/suggests for the candidate ver - pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache); - for (pkgCache::DepIterator D = CV.DependsList(); D.end() == false; ) - { - pkgCache::DepIterator Start; - pkgCache::DepIterator End; - D.GlobOr(Start,End); // advances D - if (Start->Type != pkgCache::Dep::Recommends && Start->Type != pkgCache::Dep::Suggests) - continue; - - { - // Skip if we already saw this - std::string target; - for (pkgCache::DepIterator I = Start; I != D; ++I) - { - if (target.empty() == false) - target.append(" | "); - target.append(I.TargetPkg().FullName(true)); - } - std::list<std::string> &Type = Start->Type == pkgCache::Dep::Recommends ? SingleRecommends : SingleSuggests; - if (std::find(Type.begin(), Type.end(), target) != Type.end()) - continue; - Type.push_back(target); - } - - std::list<std::string> OrList; - bool foundInstalledInOrGroup = false; - for (pkgCache::DepIterator I = Start; I != D; ++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()) - { - foundInstalledInOrGroup = true; - break; - } - } - - { - // 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 (OrList.empty()) - OrList.push_back(I.TargetPkg().FullName(true)); - else - OrList.push_back("| " + I.TargetPkg().FullName(true)); - } - - if(foundInstalledInOrGroup == false) - { - std::list<std::string> &Type = Start->Type == pkgCache::Dep::Recommends ? Recommends : Suggests; - std::move(OrList.begin(), OrList.end(), std::back_inserter(Type)); - } - } - } - 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); - } + if (_config->FindI("APT::Output-Version") < 30) + ShowWeakDependencies(Cache); RunJsonHook("AptCli::Hooks::Install", "org.debian.apt.hooks.install.pre-prompt", CmdL.FileList, Cache); |
