From 041317084a8f74e4a571f308e4a099f9a8090da0 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 29 Apr 2022 16:36:20 +0200 Subject: Never consider file/copy/cdrom sources bad sites due to errors As the hostname for them is likely empty (for absolute or . or .. for relative paths) considering one a bad site causes all of the sites from this scheme to be considered bad. In a perfect world, we would figure out a good site-path to use for these sources, but as they are local sources which means we don't have to perform costly requests to the internet we just let them happen instead for now. --- apt-pkg/acquire-item.cc | 13 ++++++++++++- apt-pkg/acquire-item.h | 2 +- apt-pkg/acquire-worker.cc | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index c845c9153..c50f46909 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -32,7 +32,9 @@ #include #include +#include #include +#include #include #include #include @@ -843,8 +845,17 @@ void pkgAcquire::Item::PushAlternativeURI(std::string &&NewURI, std::unordered_m d->AlternativeURIs.emplace_front(std::move(NewURI), std::move(fields)); } /*}}}*/ -void pkgAcquire::Item::RemoveAlternativeSite(std::string &&OldSite) /*{{{*/ +void pkgAcquire::Item::RemoveAlternativeSite(std::string const &AltUriStr)/*{{{*/ { + ::URI AltUri{AltUriStr}; + // the hostnames for these methods are empty for absolute paths which would result + // in the elimination of all sites accessed via those methods. On the upside, those + // methods are local and fast to reply with failure, so it doesn't hurt that much to + // keep them in the loop – so we just exit here rather than trying to guess the site. + std::array const badhosts{"file", "copy", "cdrom"}; + if (std::find(badhosts.begin(), badhosts.end(), AltUri.Access) != badhosts.end()) + return; + auto const OldSite = URI::SiteOnly(AltUriStr); d->AlternativeURIs.erase(std::remove_if(d->AlternativeURIs.begin(), d->AlternativeURIs.end(), [&](decltype(*d->AlternativeURIs.cbegin()) AltUri) { return URI::SiteOnly(AltUri.URI) == OldSite; diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h index 22da9815d..b1985ada7 100644 --- a/apt-pkg/acquire-item.h +++ b/apt-pkg/acquire-item.h @@ -240,7 +240,7 @@ class APT_PUBLIC pkgAcquire::Item : public WeakPointable /*{{{*/ APT_HIDDEN bool PopAlternativeURI(std::string &NewURI); APT_HIDDEN bool IsGoodAlternativeURI(std::string const &AltUri) const; APT_HIDDEN void PushAlternativeURI(std::string &&NewURI, std::unordered_map &&fields, bool const at_the_back); - APT_HIDDEN void RemoveAlternativeSite(std::string &&OldSite); + APT_HIDDEN void RemoveAlternativeSite(std::string const &AltUri); /** \brief A "descriptive" URI-like string. * diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc index ba3d52952..4b9d33505 100644 --- a/apt-pkg/acquire-worker.cc +++ b/apt-pkg/acquire-worker.cc @@ -720,7 +720,7 @@ void pkgAcquire::Worker::HandleFailure(std::vector const &It else { if (errAuthErr) - Owner->RemoveAlternativeSite(URI::SiteOnly(Owner->GetItemDesc().URI)); + Owner->RemoveAlternativeSite(Owner->GetItemDesc().URI); if (Owner->PopAlternativeURI(NewURI)) { Owner->FailMessage(Message); -- cgit v1.2.3-70-g09d2