diff options
Diffstat (limited to 'cmdline')
-rw-r--r-- | cmdline/apt-cache.cc | 2 | ||||
-rw-r--r-- | cmdline/apt-config.cc | 2 | ||||
-rw-r--r-- | cmdline/apt-get.cc | 1 | ||||
-rw-r--r-- | cmdline/apt-mark.cc | 122 | ||||
-rw-r--r-- | cmdline/apt.cc | 1 |
5 files changed, 126 insertions, 2 deletions
diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index f1b1e144d..3c0e477b1 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -182,7 +182,7 @@ static void ShowHashTableStats(std::string Type, static bool Stats(CommandLine &CmdL) { if (CmdL.FileSize() > 1) { - _error->Error(_("apt-cache stats does not take any arguments")); + _error->Error(_("%s does not take any arguments"), "apt-cache stats"); return false; } diff --git a/cmdline/apt-config.cc b/cmdline/apt-config.cc index 252a56833..8ad7cac68 100644 --- a/cmdline/apt-config.cc +++ b/cmdline/apt-config.cc @@ -67,7 +67,7 @@ static bool DoShell(CommandLine &CmdL) static bool DoDump(CommandLine &CmdL) { bool const empty = _config->FindB("APT::Config::Dump::EmptyValue", true); - std::string const format = _config->Find("APT::Config::Dump::Format", "%f \"%v\";\n"); + std::string const format = _config->Find("APT::Config::Dump::Format", "%F \"%v\";\n"); if (CmdL.FileSize() == 1) _config->Dump(cout, NULL, format.c_str(), empty); else diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 39855e05a..6d25ed509 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -409,6 +409,7 @@ static std::vector<aptDispatchWithHelp> GetCommands() /*{{{*/ {"purge", &DoInstall, _("Remove packages and config files")}, {"autoremove", &DoInstall, _("Remove automatically all unused packages")}, {"auto-remove", &DoInstall, nullptr}, + {"autopurge",&DoInstall, nullptr}, {"markauto", &DoMarkAuto, nullptr}, {"unmarkauto", &DoMarkAuto, nullptr}, {"dist-upgrade", &DoDistUpgrade, _("Distribution upgrade, see apt-get(8)")}, diff --git a/cmdline/apt-mark.cc b/cmdline/apt-mark.cc index 927b31d2f..161845b53 100644 --- a/cmdline/apt-mark.cc +++ b/cmdline/apt-mark.cc @@ -125,6 +125,127 @@ static bool DoMarkAuto(CommandLine &CmdL) return true; } /*}}}*/ +// helper for Install-Recommends-Sections and Never-MarkAuto-Sections /*{{{*/ +static bool +ConfigValueInSubTree(const char *SubTree, const char *needle) +{ + // copied from depcache.cc + Configuration::Item const *Opts; + Opts = _config->Tree(SubTree); + if (Opts != 0 && Opts->Child != 0) + { + Opts = Opts->Child; + for (; Opts != 0; Opts = Opts->Next) + { + if (Opts->Value.empty() == true) + continue; + if (strcmp(needle, Opts->Value.c_str()) == 0) + return true; + } + } + return false; +} + /*}}}*/ +/* DoMinimize - minimize manually installed {{{*/ +/* Traverses dependencies of meta packages and marks them as manually + * installed. */ +static bool DoMinimize(CommandLine &CmdL) +{ + + pkgCacheFile CacheFile; + pkgDepCache *const DepCache = CacheFile.GetDepCache(); + if (unlikely(DepCache == nullptr)) + return false; + + if (CmdL.FileList[1] != nullptr) + return _error->Error(_("%s does not take any arguments"), "apt-mark minimize-manual"); + + auto Debug = _config->FindB("Debug::AptMark::Minimize", false); + auto is_root = [&DepCache](pkgCache::PkgIterator const &pkg) { + auto ver = pkg.CurrentVer(); + return ver.end() == false && ((*DepCache)[pkg].Flags & pkgCache::Flag::Auto) == 0 && + ver->Section != 0 && + ConfigValueInSubTree("APT::Never-MarkAuto-Sections", ver.Section()); + }; + + APT::PackageSet roots; + for (auto Pkg = DepCache->PkgBegin(); Pkg.end() == false; ++Pkg) + { + if (is_root(Pkg)) + { + if (Debug) + std::clog << "Found root " << Pkg.Name() << std::endl; + roots.insert(Pkg); + } + } + + APT::PackageSet workset(roots); + APT::PackageSet seen; + APT::PackageSet changed; + + pkgDepCache::ActionGroup group(*DepCache); + + while (workset.empty() == false) + { + if (Debug) + std::clog << "Iteration\n"; + + APT::PackageSet workset2; + for (auto &Pkg : workset) + { + if (seen.find(Pkg) != seen.end()) + continue; + + seen.insert(Pkg); + + if (Debug) + std::cerr << " Visiting " << Pkg.FullName(true) << "\n"; + if (roots.find(Pkg) == roots.end() && ((*DepCache)[Pkg].Flags & pkgCache::Flag::Auto) == 0) + { + DepCache->MarkAuto(Pkg, true); + changed.insert(Pkg); + } + + // Visit dependencies, add them to next working set + for (auto Dep = Pkg.CurrentVer().DependsList(); !Dep.end(); ++Dep) + { + if (DepCache->IsImportantDep(Dep) == false) + continue; + std::unique_ptr<pkgCache::Version *[]> targets(Dep.AllTargets()); + for (int i = 0; targets[i] != nullptr; i++) + { + pkgCache::VerIterator Tgt(*DepCache, targets[i]); + if (Tgt.ParentPkg()->CurrentVer != 0 && Tgt.ParentPkg().CurrentVer()->ID == Tgt->ID) + workset2.insert(Tgt.ParentPkg()); + } + } + } + + workset = std::move(workset2); + } + + if (changed.empty()) { + cout << _("No changes necessary") << endl; + return true; + } + + ShowList(c1out, _("The following packages will be marked as automatically installed:"), changed, + [](const pkgCache::PkgIterator &) { return true; }, + &PrettyFullName, + &PrettyFullName); + + if (_config->FindB("APT::Mark::Simulate", false) == false) + { + if (YnPrompt(_("Do you want to continue?"), false) == false) + return true; + + return DepCache->writeStateFile(NULL); + } + + return true; +} + /*}}}*/ + /* ShowAuto - show automatically installed packages (sorted) {{{*/ static bool ShowAuto(CommandLine &CmdL) { @@ -293,6 +414,7 @@ static std::vector<aptDispatchWithHelp> GetCommands() /*{{{*/ return { {"auto",&DoAuto, _("Mark the given packages as automatically installed")}, {"manual",&DoAuto, _("Mark the given packages as manually installed")}, + {"minimize-manual", &DoMinimize, _("Mark all dependencies of meta packages as automatically installed.")}, {"hold",&DoSelection, _("Mark a package as held back")}, {"unhold",&DoSelection, _("Unset a package set as held back")}, {"install",&DoSelection, nullptr}, diff --git a/cmdline/apt.cc b/cmdline/apt.cc index 99e281261..f508406d1 100644 --- a/cmdline/apt.cc +++ b/cmdline/apt.cc @@ -66,6 +66,7 @@ static std::vector<aptDispatchWithHelp> GetCommands() /*{{{*/ {"remove", &DoInstall, _("remove packages")}, {"autoremove", &DoInstall, _("Remove automatically all unused packages")}, {"auto-remove", &DoInstall, nullptr}, + {"autopurge",&DoInstall, nullptr}, {"purge", &DoInstall, nullptr}, // system wide stuff |