summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2022-04-29 16:36:20 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2024-11-22 12:40:10 +0000
commit041317084a8f74e4a571f308e4a099f9a8090da0 (patch)
treea7c94800e923fbb7a0686c88cbe9784d4fe11c83
parent841243df877b39dfcb907a7fab9c4e8b4f65d715 (diff)
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.
-rw-r--r--apt-pkg/acquire-item.cc13
-rw-r--r--apt-pkg/acquire-item.h2
-rw-r--r--apt-pkg/acquire-worker.cc2
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 <apt-pkg/tagfile.h>
#include <algorithm>
+#include <array>
#include <cerrno>
+#include <ctime>
#include <chrono>
#include <cstddef>
#include <cstdio>
@@ -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<std::string, std::string> &&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<pkgAcquire::Item *> const &It
else
{
if (errAuthErr)
- Owner->RemoveAlternativeSite(URI::SiteOnly(Owner->GetItemDesc().URI));
+ Owner->RemoveAlternativeSite(Owner->GetItemDesc().URI);
if (Owner->PopAlternativeURI(NewURI))
{
Owner->FailMessage(Message);