From 4c4e306a1be1e074ca07bec542c1469b909e2bfa Mon Sep 17 00:00:00 2001
From: David Kalnischkies <david@kalnischkies.de>
Date: Mon, 29 May 2017 18:02:28 +0200
Subject: [PATCH] don't show incorrect 'How odd' errror in no-download mode
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Showing messages related to downloading in a mode which can't download
is pretty pointless, so instead of trying harder to make it so that
these messages do not trigger just skip them entirely.

That the message triggered here is an artifact of the implementation in
which the download items are finished, while the code expects them to be
still pending – even the in a previous run completely downloaded files.

Closes: 863635
---
 apt-private/private-install.cc | 49 +++++++++++++++++++++++-------------------
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc
index 73a03a828..e37ff5390 100644
--- a/apt-private/private-install.cc
+++ b/apt-private/private-install.cc
@@ -109,6 +109,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
 	    Cache->MarkDelete(I,true);
 
    // Create the download object
+   auto const DownloadAllowed = _config->FindB("APT::Get::Download",true);
    aptAcquireWithTextStatus Fetcher;
    if (_config->FindB("APT::Get::Print-URIs", false) == true)
    {
@@ -136,7 +137,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
        _error->PendingError() == true)
       return false;
 
-   if (_config->FindB("APT::Get::Download",true) == false)
+   if (DownloadAllowed == false)
    {
       bool Missing = false;
       RemoveDownloadNeedingItemsFromFetcher(Fetcher, Missing);
@@ -218,27 +219,30 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
       return true;
    }
 
-   // Display statistics
-   auto const FetchBytes = Fetcher.FetchNeeded();
-   auto const FetchPBytes = Fetcher.PartialPresent();
-   auto const DebBytes = Fetcher.TotalNeeded();
-   if (DebBytes != Cache->DebSize())
+   auto const FetchBytes = DownloadAllowed ? Fetcher.FetchNeeded() : 0;
+   auto const FetchPBytes = DownloadAllowed ? Fetcher.PartialPresent() : 0;
+   if (DownloadAllowed)
    {
-      c0out << DebBytes << ',' << Cache->DebSize() << std::endl;
-      c0out << _("How odd... The sizes didn't match, email apt@packages.debian.org") << std::endl;
-   }
-   
-   // Number of bytes
-   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"),
+      // Display statistics
+      auto const DebBytes = Fetcher.TotalNeeded();
+      if (DebBytes != Cache->DebSize())
+      {
+	 c0out << "E: " << DebBytes << ',' << Cache->DebSize() << std::endl;
+	 c0out << "E: " << _("How odd... The sizes didn't match, email apt@packages.debian.org") << std::endl;
+      }
+
+      // Number of bytes
+      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"),
 	       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"),
+      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"),
 	       SizeToStr(DebBytes).c_str());
+   }
 
    // Size delta
    if (Cache->UsrSize() >= 0)
@@ -252,8 +256,9 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
       ioprintf(c1out,_("After this operation, %sB disk space will be freed.\n"),
 	       SizeToStr(-1*Cache->UsrSize()).c_str());
 
-   if (CheckFreeSpaceBeforeDownload(_config->FindDir("Dir::Cache::Archives"), (FetchBytes - FetchPBytes)) == false)
-      return false;
+   if (DownloadAllowed)
+      if (CheckFreeSpaceBeforeDownload(_config->FindDir("Dir::Cache::Archives"), (FetchBytes - FetchPBytes)) == false)
+	 return false;
 
    if (_error->PendingError() == true)
       return false;
@@ -362,7 +367,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
 	 return false;
 
       Failed = false;
-      if (_config->FindB("APT::Get::Download",true) == false)
+      if (DownloadAllowed == false)
 	 RemoveDownloadNeedingItemsFromFetcher(Fetcher, Failed);
    }
 
-- 
2.11.0

