]> git.saurik.com Git - apt.git/commitdiff
show more details for "Writing more data" errors, too
authorDavid Kalnischkies <david@kalnischkies.de>
Sun, 24 Apr 2016 08:35:08 +0000 (10:35 +0200)
committerDavid Kalnischkies <david@kalnischkies.de>
Mon, 25 Apr 2016 13:35:52 +0000 (15:35 +0200)
They are the small brothers of the hashsum mismatch, so they deserve a
similar treatment even through we have for architectual reasons not a
much to display as for hashsum mismatches for now.

apt-pkg/acquire-item.cc
apt-pkg/acquire-worker.cc
test/integration/test-apt-update-expected-size
test/integration/test-ubuntu-bug-1098738-apt-get-source-md5sum

index aeadbcfc7994613f4719b3f9d83c3a3874ce5ac8..ceed5a510fc4a847c69fd5d8dd25eadbf67e758a 100644 (file)
@@ -679,35 +679,59 @@ void pkgAcquire::Item::Failed(string const &Message,pkgAcquire::MethodConfig con
       Dequeue();
    }
 
+   string const FailReason = LookupTag(Message, "FailReason");
+   enum { MAXIMUM_SIZE_EXCEEDED, HASHSUM_MISMATCH, OTHER } failreason = OTHER;
+   if ( FailReason == "MaximumSizeExceeded")
+      failreason = MAXIMUM_SIZE_EXCEEDED;
+   else if (Status == StatAuthError)
+      failreason = HASHSUM_MISMATCH;
+
    if(ErrorText.empty())
    {
       if (Status == StatAuthError)
       {
         std::ostringstream out;
-        out << _("Hash Sum mismatch") << std::endl;
-        out << "Hashes of expected file:" << std::endl;
-        for (auto const &hs: GetExpectedHashes())
-           out << " - " << hs.toStr() << std::endl;
-        out << "Hashes of received file:" << std::endl;
-        for (char const * const * type = HashString::SupportedHashes(); *type != NULL; ++type)
+        switch (failreason)
+        {
+           case HASHSUM_MISMATCH:
+              out << _("Hash Sum mismatch") << std::endl;
+              break;
+           case MAXIMUM_SIZE_EXCEEDED:
+           case OTHER:
+              out << LookupTag(Message, "Message") << std::endl;
+              break;
+        }
+        auto const ExpectedHashes = GetExpectedHashes();
+        if (ExpectedHashes.empty() == false)
         {
-           std::string const tagname = std::string(*type) + "-Hash";
-           std::string const hashsum = LookupTag(Message, tagname.c_str());
-           if (hashsum.empty() == false)
-              out << " - " << HashString(*type, hashsum).toStr() << std::endl;
+           out << "Hashes of expected file:" << std::endl;
+           for (auto const &hs: ExpectedHashes)
+              out << " - " << hs.toStr() << std::endl;
+        }
+        if (failreason == HASHSUM_MISMATCH)
+        {
+           out << "Hashes of received file:" << std::endl;
+           for (char const * const * type = HashString::SupportedHashes(); *type != NULL; ++type)
+           {
+              std::string const tagname = std::string(*type) + "-Hash";
+              std::string const hashsum = LookupTag(Message, tagname.c_str());
+              if (hashsum.empty() == false)
+                 out << " - " << HashString(*type, hashsum).toStr() << std::endl;
+           }
+           out << "Last modification reported: " << LookupTag(Message, "Last-Modified", "<none>") << std::endl;
         }
-        out << "Last modification reported: " << LookupTag(Message, "Last-Modified", "<none>") << std::endl;
         ErrorText = out.str();
       }
       else
         ErrorText = LookupTag(Message,"Message");
    }
 
-   string const FailReason = LookupTag(Message, "FailReason");
-   if (FailReason == "MaximumSizeExceeded")
-      RenameOnError(MaximumSizeExceeded);
-   else if (Status == StatAuthError)
-      RenameOnError(HashSumMismatch);
+   switch (failreason)
+   {
+      case MAXIMUM_SIZE_EXCEEDED: RenameOnError(MaximumSizeExceeded); break;
+      case HASHSUM_MISMATCH: RenameOnError(HashSumMismatch); break;
+      case OTHER: break;
+   }
 
    if (FailReason.empty() == false)
       ReportMirrorFailureToCentral(*this, FailReason, ErrorText);
@@ -800,7 +824,6 @@ bool pkgAcquire::Item::RenameOnError(pkgAcquire::Item::RenameOnErrorState const
    {
       case HashSumMismatch:
         errtext = _("Hash Sum mismatch");
-        Status = StatAuthError;
         break;
       case SizeMismatch:
         errtext = _("Size mismatch");
@@ -821,7 +844,6 @@ bool pkgAcquire::Item::RenameOnError(pkgAcquire::Item::RenameOnErrorState const
         break;
       case MaximumSizeExceeded:
         // the method is expected to report a good error for this
-        Status = StatError;
         break;
       case PDiffError:
         // no handling here, done by callers
@@ -1791,9 +1813,8 @@ pkgAcqBaseIndex::pkgAcqBaseIndex(pkgAcquire * const Owner,
 void pkgAcqBaseIndex::Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf)/*{{{*/
 {
    pkgAcquire::Item::Failed(Message, Cnf);
-   if (TransactionManager == nullptr || ErrorText.empty() ||
-        TransactionManager->MetaIndexParser == nullptr ||
-        LookupTag(Message, "FailReason") != "HashSumMismatch")
+   if (TransactionManager == nullptr || TransactionManager->MetaIndexParser == nullptr ||
+        Status != StatAuthError)
       return;
 
    ErrorText.append("Release file created at: ");
index c009f402e11f170eba3f280af6020b960d0b0cdc..69ca6a28e19a8740c72634bb1ef2dcbae9775648 100644 (file)
@@ -471,18 +471,28 @@ bool pkgAcquire::Worker::RunMessages()
            OwnerQ->ItemDone(Itm);
            Itm = nullptr;
 
-           bool errTransient;
+           bool errTransient = false, errAuthErr = false;
            {
               std::string const failReason = LookupTag(Message, "FailReason");
-              std::string const reasons[] = { "Timeout", "ConnectionRefused",
-                 "ConnectionTimedOut", "ResolveFailure", "TmpResolveFailure" };
-              errTransient = std::find(std::begin(reasons), std::end(reasons), failReason) != std::end(reasons);
+              {
+                 auto const reasons = { "Timeout", "ConnectionRefused",
+                    "ConnectionTimedOut", "ResolveFailure", "TmpResolveFailure" };
+                 errTransient = std::find(std::begin(reasons), std::end(reasons), failReason) != std::end(reasons);
+              }
+              if (errTransient == false)
+              {
+                 auto const reasons = { "HashSumMismatch", "MaximumSizeExceeded" };
+                 errAuthErr = std::find(std::begin(reasons), std::end(reasons), failReason) != std::end(reasons);
+              }
            }
 
            for (auto const Owner: ItmOwners)
            {
-              if (errTransient)
+              if (errAuthErr && Owner->GetExpectedHashes().empty() == false)
+                 Owner->Status = pkgAcquire::Item::StatAuthError;
+              else if (errTransient)
                  Owner->Status = pkgAcquire::Item::StatTransientNetworkError;
+
               if (isDoomedItem(Owner) == false)
                  Owner->Failed(Message,Config);
               if (Log != nullptr)
index 4981e72c3510ff7464dbaa449b3816febbaf034a..ee0eae981fe68f8b1613ae86ea8b10e2d6202a31 100755 (executable)
@@ -5,7 +5,8 @@ TESTDIR="$(readlink -f "$(dirname "$0")")"
 . "$TESTDIR/framework"
 
 setupenvironment
-configarchitecture "i386"
+configarchitecture 'i386'
+configcompression '.' 'gz'
 
 insertpackage 'unstable' 'apt' 'i386' '1.0'
 
@@ -30,13 +31,13 @@ test_packagestoobig() {
        buildaptarchivefromfiles '+1 hour'
        signreleasefiles
        # append junk at the end of the Packages.gz/Packages
-       SIZE="$(stat --printf=%s aptarchive/dists/unstable/main/binary-i386/Packages)"
+       SIZE="$(stat --printf=%s aptarchive/dists/unstable/main/binary-i386/Packages.gz)"
        find aptarchive/dists -name 'Packages*' | while read pkg; do
                echo "1234567890" >> "$pkg"
                touch -d '+1hour' "$pkg"
        done
-       NEW_SIZE="$(stat --printf=%s aptarchive/dists/unstable/main/binary-i386/Packages)"
-       testfailuremsg "E: Failed to fetch ${1}/dists/unstable/main/binary-i386/Packages  Writing more data than expected ($NEW_SIZE > $SIZE)
+       NEW_SIZE="$(stat --printf=%s aptarchive/dists/unstable/main/binary-i386/Packages.gz)"
+       testfailuremsg "E: Failed to fetch ${1}/dists/unstable/main/binary-i386/Packages.gz  Writing more data than expected ($NEW_SIZE > $SIZE)
 E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::Transaction=0
 }
 
index 8994fa24e1b3f6b607aaa688eb30d2e771fb9870..ac5dd11b862165504e2807b9514c0edf621504da 100755 (executable)
@@ -217,6 +217,9 @@ Need to get 6 B of source archives.
 Get:1 http://localhost:${APTHTTPPORT}  $1 1.0 (dsc) [2 B]
 Err:1 http://localhost:${APTHTTPPORT}  $1 1.0 (dsc)
   Writing more data than expected (3 > 2)
+  Hashes of expected file:
+   - SHA256:943d3bf22ac661fb0f59bc4ff68cc12b04ff17a838dfcc2537008eb9c7f3770a
+   - Checksum-FileSize:2
 Get:2 http://localhost:${APTHTTPPORT}  $1 1.0 (tar) [4 B]
 Err:2 http://localhost:${APTHTTPPORT}  $1 1.0 (tar)
   Hash Sum mismatch
@@ -228,6 +231,9 @@ Err:2 http://localhost:${APTHTTPPORT}  $1 1.0 (tar)
    - Checksum-FileSize:3
   Last modification reported: $(lastmodification "aptarchive/${1}_1.0.dsc")
 E: Failed to fetch http://localhost:${APTHTTPPORT}/${1}_1.0.dsc  Writing more data than expected (3 > 2)
+   Hashes of expected file:
+    - SHA256:943d3bf22ac661fb0f59bc4ff68cc12b04ff17a838dfcc2537008eb9c7f3770a
+    - Checksum-FileSize:2
 E: Failed to fetch http://localhost:${APTHTTPPORT}/${1}_1.0.tar.gz  Hash Sum mismatch
    Hashes of expected file:
     - SHA256:90aebae315675cbf04612de4f7d5874850f48e0b8dd82becbeaa47ca93f5ebfb