summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2022-04-24 00:03:38 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2024-11-22 12:21:24 +0000
commit496c8b4191790231258e644ac8cd4096d54f445f (patch)
tree64712f5e0cc56eda6b29a7a2c2d1fe097bb89fd1
parent39304fb440f62b3a9f4dd85871b7049fb5b8eb8f (diff)
Show hashes calculated by main thread in error messages
The main thread calculates the hash sums if the method hasn't to be able to verify the files, but while a failure is detected and reported, the error messages did not include the hash sums which looks at least puzzling. So to have a complete error message we ensure that the hashes we calculated are appended to the message from the method so that it looks for the higher level code as if the method had calculated the hashes.
-rw-r--r--apt-pkg/acquire-item.cc14
-rw-r--r--apt-pkg/acquire-worker.cc12
-rwxr-xr-xtest/integration/test-apt-update-incomplete-file-mirror1
3 files changed, 26 insertions, 1 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index 1fc07ec05..7e1c5dad6 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -976,13 +976,25 @@ void pkgAcquire::Item::FailMessage(string const &Message)
if (failreason == HASHSUM_MISMATCH)
{
out << "Hashes of received file:" << std::endl;
+ size_t hashes = 0;
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)
+ if (not hashsum.empty())
+ {
formatHashsum(out, HashString(*type, hashsum));
+ ++hashes;
+ }
}
+ if (hashes == 0)
+ for (char const *const *type = HashString::SupportedHashes(); *type != nullptr; ++type)
+ {
+ std::string const tagname = std::string("Alt-") + *type + "-Hash";
+ std::string const hashsum = LookupTag(Message, tagname.c_str());
+ if (not hashsum.empty())
+ formatHashsum(out, HashString(*type, hashsum));
+ }
}
auto const lastmod = LookupTag(Message, "Last-Modified", "");
if (lastmod.empty() == false)
diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc
index 035d8ce10..4c2acb5cc 100644
--- a/apt-pkg/acquire-worker.cc
+++ b/apt-pkg/acquire-worker.cc
@@ -457,6 +457,18 @@ bool pkgAcquire::Worker::RunMessages()
FileFd file(filename, FileFd::ReadOnly, FileFd::None);
calc.AddFD(file);
ReceivedHashes = calc.GetHashStringList();
+ for (auto const &h : ReceivedHashes)
+ {
+ std::string tagname;
+ if (AltFile)
+ tagname = "Alt-";
+ tagname.append(h.HashType()).append("-Hash");
+ if (not LookupTag(Message, tagname.c_str()).empty())
+ continue;
+ if (not APT::String::Endswith(Message, "\n"))
+ Message.append("\n");
+ Message.append(tagname).append(": ").append(h.HashValue());
+ }
}
}
diff --git a/test/integration/test-apt-update-incomplete-file-mirror b/test/integration/test-apt-update-incomplete-file-mirror
index d6894d607..86eb890a7 100755
--- a/test/integration/test-apt-update-incomplete-file-mirror
+++ b/test/integration/test-apt-update-incomplete-file-mirror
@@ -29,3 +29,4 @@ find aptarchive/dists -name 'Packages' | while read FILE; do
echo 'hacked' > $FILE
done
testfailure apt update
+testsuccessequal '4' grep -c -- '- Filesize:' rootdir/tmp/testfailure.output