From d8a8f9d7f01c75a7bbad7a488bf359a94291d1de Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 27 Aug 2013 08:50:06 +0200 Subject: [PATCH] allow pkg manipulation in the upgrade/dist-upgrade commandline, e.g. apt-get dist-upgrade 2vcard- 4g8+ --- apt-private/private-install.cc | 62 +++++++++++++++++++++------------- apt-private/private-install.h | 3 ++ apt-private/private-upgrade.cc | 14 ++++---- cmdline/apt-get.cc | 7 ++-- 4 files changed, 54 insertions(+), 32 deletions(-) diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 4e29fbbf..b03f131a 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -577,19 +577,19 @@ bool DoAutomaticRemove(CacheFile &Cache) } /*}}}*/ +static const unsigned short MOD_REMOVE = 1; +static const unsigned short MOD_INSTALL = 2; +bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache) +{ + std::map verset; + return DoCacheManipulationFromCommandLine(CmdL, Cache, verset); +} - -// DoInstall - Install packages from the command line /*{{{*/ -// --------------------------------------------------------------------- -/* Install named packages */ -bool DoInstall(CommandLine &CmdL) +bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, + std::map &verset) { - CacheFile Cache; - if (Cache.OpenForInstall() == false || - Cache.CheckDeps(CmdL.FileSize() != 1) == false) - return false; - + // Enter the special broken fixing mode if the user specified arguments bool BrokenFix = false; if (Cache->BrokenCount() != 0) @@ -599,9 +599,6 @@ bool DoInstall(CommandLine &CmdL) if (_config->FindB("APT::Get::CallResolver", true) == true) Fix = new pkgProblemResolver(Cache); - static const unsigned short MOD_REMOVE = 1; - static const unsigned short MOD_INSTALL = 2; - unsigned short fallback = MOD_INSTALL; if (strcasecmp(CmdL.FileList[0],"remove") == 0) fallback = MOD_REMOVE; @@ -622,7 +619,7 @@ bool DoInstall(CommandLine &CmdL) mods.push_back(APT::VersionSet::Modifier(MOD_REMOVE, "-", APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::NEWEST)); CacheSetHelperAPTGet helper(c0out); - std::map verset = APT::VersionSet::GroupedFromCommandLine(Cache, + verset = APT::VersionSet::GroupedFromCommandLine(Cache, CmdL.FileList + 1, mods, fallback, helper); if (_error->PendingError() == true) @@ -711,6 +708,34 @@ bool DoInstall(CommandLine &CmdL) if (!DoAutomaticRemove(Cache)) return false; + // if nothing changed in the cache, but only the automark information + // we write the StateFile here, otherwise it will be written in + // cache.commit() + if (InstallAction.AutoMarkChanged > 0 && + Cache->DelCount() == 0 && Cache->InstCount() == 0 && + Cache->BadCount() == 0 && + _config->FindB("APT::Get::Simulate",false) == false) + Cache->writeStateFile(NULL); + + return true; +} + + +// DoInstall - Install packages from the command line /*{{{*/ +// --------------------------------------------------------------------- +/* Install named packages */ +bool DoInstall(CommandLine &CmdL) +{ + CacheFile Cache; + if (Cache.OpenForInstall() == false || + Cache.CheckDeps(CmdL.FileSize() != 1) == false) + return false; + + std::map verset; + + if(!DoCacheManipulationFromCommandLine(CmdL, Cache, verset)) + return false; + /* Print out a list of packages that are going to be installed extra to what the user asked */ if (Cache->InstCount() != verset[MOD_INSTALL].size()) @@ -826,15 +851,6 @@ bool DoInstall(CommandLine &CmdL) } - // if nothing changed in the cache, but only the automark information - // we write the StateFile here, otherwise it will be written in - // cache.commit() - if (InstallAction.AutoMarkChanged > 0 && - Cache->DelCount() == 0 && Cache->InstCount() == 0 && - Cache->BadCount() == 0 && - _config->FindB("APT::Get::Simulate",false) == false) - Cache->writeStateFile(NULL); - // See if we need to prompt // FIXME: check if really the packages in the set are going to be installed if (Cache->InstCount() == verset[MOD_INSTALL].size() && Cache->DelCount() == 0) diff --git a/apt-private/private-install.h b/apt-private/private-install.h index fcf4cbce..439c8971 100644 --- a/apt-private/private-install.h +++ b/apt-private/private-install.h @@ -14,6 +14,9 @@ bool DoInstall(CommandLine &Cmd); +bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, + std::map &verset); +bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache); bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, bool Safety = true); diff --git a/apt-private/private-upgrade.cc b/apt-private/private-upgrade.cc index eb546e3e..09085c2d 100644 --- a/apt-private/private-upgrade.cc +++ b/apt-private/private-upgrade.cc @@ -13,9 +13,6 @@ packages */ bool DoUpgradeNoNewPackages(CommandLine &CmdL) { - if (CmdL.FileSize() != 1) - return _error->Error(_("The upgrade command takes no arguments")); - CacheFile Cache; if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false) return false; @@ -26,6 +23,10 @@ bool DoUpgradeNoNewPackages(CommandLine &CmdL) ShowBroken(c1out,Cache,false); return _error->Error(_("Internal error, AllUpgrade broke stuff")); } + + // parse additional cmdline pkg manipulation switches + if(!DoCacheManipulationFromCommandLine(CmdL, Cache)) + return false; return InstallPackages(Cache,true); } @@ -34,9 +35,6 @@ bool DoUpgradeNoNewPackages(CommandLine &CmdL) // DoSafeUpgrade - Upgrade all packages with install but not remove /*{{{*/ bool DoUpgradeWithAllowNewPackages(CommandLine &CmdL) { - if (CmdL.FileSize() != 1) - return _error->Error(_("The upgrade command takes no arguments")); - CacheFile Cache; if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false) return false; @@ -47,6 +45,10 @@ bool DoUpgradeWithAllowNewPackages(CommandLine &CmdL) ShowBroken(c1out,Cache,false); return _error->Error(_("Internal error, AllUpgrade broke stuff")); } + + // parse additional cmdline pkg manipulation switches + if(!DoCacheManipulationFromCommandLine(CmdL, Cache)) + return false; return InstallPackages(Cache,true); } diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 93c21651..c273dfaa 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -350,9 +350,6 @@ bool DoMarkAuto(CommandLine &CmdL) /* Intelligent upgrader that will install and remove packages at will */ bool DoDistUpgrade(CommandLine &CmdL) { - if (CmdL.FileSize() != 1) - return _error->Error(_("The dist-upgrade command takes no arguments")); - CacheFile Cache; if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false) return false; @@ -365,6 +362,10 @@ bool DoDistUpgrade(CommandLine &CmdL) return false; } + // parse additional cmdline pkg manipulation switches + if(!DoCacheManipulationFromCommandLine(CmdL, Cache)) + return false; + c0out << _("Done") << endl; return InstallPackages(Cache,true); -- 2.20.1