diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 10:18:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 10:18:18 +0000 |
commit | 8f0b97043bf4c0dde04805ded9ba11fd923419ca (patch) | |
tree | 71ed941d427ca5077b761de4cff106d23611e0e9 /apt-private/private-install.cc | |
parent | Adding upstream version 2.7.14. (diff) | |
download | apt-8f0b97043bf4c0dde04805ded9ba11fd923419ca.tar.xz apt-8f0b97043bf4c0dde04805ded9ba11fd923419ca.zip |
Adding upstream version 2.9.0.upstream/2.9.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'apt-private/private-install.cc')
-rw-r--r-- | apt-private/private-install.cc | 214 |
1 files changed, 116 insertions, 98 deletions
diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 254d934..3efae01 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -139,8 +139,10 @@ 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"); #ifdef REQUIRE_MERGED_USR WarnUsrMerge warnUsrMerge(Cache); #endif @@ -221,8 +223,13 @@ bool InstallPackages(CacheFile &Cache, APT::PackageVector &HeldBackPackages, boo } // Show all the various warning indicators - ShowDel(c1out,Cache); + 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) { ShowPhasing(c1out, Cache, PhasingPackages); @@ -231,10 +238,13 @@ bool InstallPackages(CacheFile &Cache, APT::PackageVector &HeldBackPackages, boo _error->Notice("Some packages may have been kept back due to phasing."); } bool const Hold = not ShowHold(c1out,Cache); - if (_config->FindB("APT::Get::Show-Upgraded",true) == true) + if (_config->FindI("APT::Output-Version") < 30 && _config->FindB("APT::Get::Show-Upgraded",true) == true) ShowUpgraded(c1out,Cache); bool const Downgrade = !ShowDowngraded(c1out,Cache); + // Show removed packages last + if (_config->FindI("APT::Output-Version") >= 30) + ShowDel(c1out,Cache); bool Essential = false; if (_config->FindB("APT::Get::Download-Only",false) == false) Essential = !ShowEssential(c1out,Cache); @@ -312,12 +322,12 @@ bool InstallPackages(CacheFile &Cache, APT::PackageVector &HeldBackPackages, boo if (DebBytes != FetchBytes) //TRANSLATOR: The required space between number and unit is already included // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB - ioprintf(c1out,_("Need to get %sB/%sB of archives.\n"), + ioprintf(c1out,outVer < 30 ? _("Need to get %sB/%sB of archives.\n") : _(" Download size: %sB/%sB\n"), SizeToStr(FetchBytes).c_str(),SizeToStr(DebBytes).c_str()); else if (DebBytes != 0) //TRANSLATOR: The required space between number and unit is already included // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB - ioprintf(c1out,_("Need to get %sB of archives.\n"), + ioprintf(c1out,outVer < 30 ? _("Need to get %sB of archives.\n") : _(" Download size: %sB\n"), SizeToStr(DebBytes).c_str()); } @@ -325,14 +335,16 @@ bool InstallPackages(CacheFile &Cache, APT::PackageVector &HeldBackPackages, boo if (Cache->UsrSize() >= 0) //TRANSLATOR: The required space between number and unit is already included // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB - ioprintf(c1out,_("After this operation, %sB of additional disk space will be used.\n"), + ioprintf(c1out,outVer < 30 ? _("After this operation, %sB of additional disk space will be used.\n") : _(" Installed size: %sB\n"), SizeToStr(Cache->UsrSize()).c_str()); else //TRANSLATOR: The required space between number and unit is already included // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB - ioprintf(c1out,_("After this operation, %sB disk space will be freed.\n"), + ioprintf(c1out,outVer < 30 ? _("After this operation, %sB disk space will be freed.\n") : _(" Freed space: %sB\n"), SizeToStr(-1*Cache->UsrSize()).c_str()); + if (outVer >= 30) + ioprintf(c1out,"\n"); if (DownloadAllowed) if (CheckFreeSpaceBeforeDownload(_config->FindDir("Dir::Cache::Archives"), (FetchBytes - FetchPBytes)) == false) return false; @@ -368,7 +380,7 @@ bool InstallPackages(CacheFile &Cache, APT::PackageVector &HeldBackPackages, boo if (_config->FindI("quiet",0) < 2 && _config->FindB("APT::Get::Assume-Yes",false) == false) { - if (YnPrompt(_("Do you want to continue?")) == false) + if (YnPrompt(outVer < 30 ? _("Do you want to continue?") : _("Continue?")) == false) { c2out << _("Abort.") << std::endl; exit(1); @@ -903,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].NewInstall() == 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; @@ -933,101 +1038,14 @@ 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()) + if (_config->FindI("APT::Output-Version") < 30 && Cache->InstCount() != verset[MOD_INSTALL].size()) ShowList(c1out, _("The following additional packages will be installed:"), Universe, PkgIsExtraInstalled(&Cache, &verset[MOD_INSTALL]), - &PrettyFullName, CandidateVersion(&Cache)); + &PrettyFullName, CandidateVersion(&Cache), "APT::Color::Green"); /* Print out a list of suggested and recommended packages */ - { - std::list<std::string> Recommends, Suggests, SingleRecommends, SingleSuggests; - 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); |