Просмотр исходного кода

show upgradable packages after apt update

Closes: 748389
Michael Vogt лет назад: 12
Родитель
Сommit
8f41898133
3 измененных файлов с 36 добавлено и 0 удалено
  1. 18 0
      apt-private/private-update.cc
  2. 1 0
      cmdline/apt.cc
  3. 17 0
      test/integration/test-apt-cli-update

+ 18 - 0
apt-private/private-update.cc

@@ -75,6 +75,24 @@ bool DoUpdate(CommandLine &CmdL)
 	 return false;
    }
 
+   // show basic stats (if the user whishes)
+   if (_config->FindB("APT::Cmd::Show-Update-Stats", false) == true)
+   {
+      int upgradable = 0;
+      Cache.Open();
+      for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() != true; ++I)
+      {
+         pkgDepCache::StateCache &state = Cache[I];
+         if (I->CurrentVer != 0 && state.Upgradable())
+            upgradable++;
+      }
+      const char *msg = ngettext(
+         "%i package can be upgraded. Run 'apt list --upgradable' to see it.\n",
+         "%i packages can be upgraded. Run 'apt list --upgradable' to see them.\n",
+         upgradable);
+      ioprintf(c1out, msg, upgradable);
+   }
+
    return true;
 }
 									/*}}}*/

+ 1 - 0
cmdline/apt.cc

@@ -112,6 +112,7 @@ int main(int argc, const char *argv[])					/*{{{*/
    _config->CndSet("DPkg::Progress-Fancy", "1");
    _config->CndSet("Apt::Color", "1");
    _config->CndSet("APT::Get::Upgrade-Allow-New", true);
+   _config->CndSet("APT::Cmd::Show-Update-Stats", true);
 
    // Parse the command line and initialize the package library
    CommandLine CmdL(Args.data(), _config);

+ 17 - 0
test/integration/test-apt-cli-update

@@ -0,0 +1,17 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+
+setupenvironment
+configarchitecture "i386"
+
+insertpackage 'unstable' 'foo' 'all' '2.0'
+insertinstalledpackage 'foo' 'all' '1.0'
+
+setupaptarchive
+
+APTARCHIVE=$(readlink -f ./aptarchive)
+
+testequal "1 package can be upgraded. Run 'apt list --upgradable' to see it." apt update -q