summaryrefslogtreecommitdiff
path: root/apt-pkg/acquire-worker.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2022-04-23 22:46:33 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2024-11-22 12:21:24 +0000
commit39304fb440f62b3a9f4dd85871b7049fb5b8eb8f (patch)
treee775f2fae0152407f301d0d0819bb9b5a45480a0 /apt-pkg/acquire-worker.cc
parentdcb81196776f5c31063e5f57104b4b021f37aa00 (diff)
Support uncompressed indexes from partial file:/ mirrors
If a file:/ mirror does not contain the requested compressed file, but the uncompressed variant of that file the method will sent us a fitting Done message with data only about the Alt-Filename, but the central hash verification code in the acquire system does not expect that looking for the non-existent compressed file to compare its hashes with the expected result – which fails (if we are verifying at least). That file:/ as well as the item code deals with this suggests that this feature was broken by 448c38bdcd72b52f11ec5f326f822cf57653f81c, but I couldn't (easily) compile that to verify, so this is only a guess. Supporting this allows using index files from /var/lib/apt/lists – which are likely uncompressed or can at least made so easily – to construct a file:/ mirror.
Diffstat (limited to 'apt-pkg/acquire-worker.cc')
-rw-r--r--apt-pkg/acquire-worker.cc30
1 files changed, 25 insertions, 5 deletions
diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc
index 0f22f71e8..035d8ce10 100644
--- a/apt-pkg/acquire-worker.cc
+++ b/apt-pkg/acquire-worker.cc
@@ -20,6 +20,7 @@
#include <apt-pkg/error.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/hashes.h>
+#include <apt-pkg/metaindex.h>
#include <apt-pkg/proxy.h>
#include <apt-pkg/strutl.h>
@@ -434,11 +435,18 @@ bool pkgAcquire::Worker::RunMessages()
Log->Pulse((*O)->GetOwner());
HashStringList ReceivedHashes;
+ bool AltFile = false;
{
- std::string const givenfilename = LookupTag(Message, "Filename");
- std::string const filename = givenfilename.empty() ? Itm->Owner->DestFile : givenfilename;
+ std::string filename;
+ if (filename = LookupTag(Message, "Filename"); filename.empty())
+ {
+ if (filename = LookupTag(Message, "Alt-Filename"); not filename.empty())
+ AltFile = true;
+ else
+ filename = Itm->Owner->DestFile;
+ }
// see if we got hashes to verify
- ReceivedHashes = GetHashesFromMessage("", Message);
+ ReceivedHashes = GetHashesFromMessage(AltFile ? "Alt-" : "", Message);
// not all methods always sent Hashes our way
if (ReceivedHashes.usable() == false)
{
@@ -453,7 +461,7 @@ bool pkgAcquire::Worker::RunMessages()
}
// only local files can refer other filenames and counting them as fetched would be unfair
- if (Log != NULL && Itm->Owner->Complete == false && Itm->Owner->Local == false && givenfilename == filename)
+ if (Log != nullptr && not Itm->Owner->Complete && not Itm->Owner->Local && not AltFile && Itm->Owner->DestFile == filename)
Log->Fetched(ReceivedHashes.FileSize(),atoi(LookupTag(Message,"Resume-Point","0").c_str()));
}
@@ -466,7 +474,19 @@ bool pkgAcquire::Worker::RunMessages()
auto const forcedHash = _config->Find("Acquire::ForceHash");
for (auto const Owner: ItmOwners)
{
- HashStringList const ExpectedHashes = Owner->GetExpectedHashes();
+ HashStringList const ExpectedHashes = [&]() {
+ if (AltFile)
+ {
+ auto const * const transOwner = dynamic_cast<pkgAcqTransactionItem const * const>(Owner);
+ if (transOwner != nullptr && transOwner->TransactionManager != nullptr && transOwner->TransactionManager->MetaIndexParser != nullptr)
+ {
+ auto const * const hashes = transOwner->TransactionManager->MetaIndexParser->Lookup(transOwner->Target.MetaKey);
+ if (hashes != nullptr)
+ return hashes->Hashes;
+ }
+ }
+ return Owner->GetExpectedHashes();
+ }();
if(_config->FindB("Debug::pkgAcquire::Auth", false) == true)
{
std::clog << "201 URI Done: " << Owner->DescURI() << endl