summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt-pkg/acquire-worker.cc19
-rwxr-xr-xtest/integration/test-handle-redirect-as-used-mirror-change3
2 files changed, 14 insertions, 8 deletions
diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc
index ca1fd4836..6cf6c856e 100644
--- a/apt-pkg/acquire-worker.cc
+++ b/apt-pkg/acquire-worker.cc
@@ -273,16 +273,19 @@ bool pkgAcquire::Worker::RunMessages()
// if we change site, treat it as a mirror change
if (URI::SiteOnly(NewURI) != URI::SiteOnly(desc.URI))
{
- std::string const OldSite = desc.Description.substr(0, desc.Description.find(" "));
- if (likely(APT::String::Startswith(desc.URI, OldSite)))
+ auto const firstSpace = desc.Description.find(" ");
+ if (firstSpace != std::string::npos)
{
- std::string const OldExtra = desc.URI.substr(OldSite.length() + 1);
- if (likely(APT::String::Endswith(NewURI, OldExtra)))
+ std::string const OldSite = desc.Description.substr(0, firstSpace);
+ if (likely(APT::String::Startswith(desc.URI, OldSite)))
{
- std::string const NewSite = NewURI.substr(0, NewURI.length() - OldExtra.length());
- Owner->UsedMirror = URI::ArchiveOnly(NewSite);
- if (desc.Description.find(" ") != string::npos)
- desc.Description.replace(0, desc.Description.find(" "), Owner->UsedMirror);
+ std::string const OldExtra = desc.URI.substr(OldSite.length() + 1);
+ if (likely(APT::String::Endswith(NewURI, OldExtra)))
+ {
+ std::string const NewSite = NewURI.substr(0, NewURI.length() - OldExtra.length());
+ Owner->UsedMirror = URI::ArchiveOnly(NewSite);
+ desc.Description.replace(0, firstSpace, Owner->UsedMirror);
+ }
}
}
}
diff --git a/test/integration/test-handle-redirect-as-used-mirror-change b/test/integration/test-handle-redirect-as-used-mirror-change
index 3a8b1fecd..7978d7524 100755
--- a/test/integration/test-handle-redirect-as-used-mirror-change
+++ b/test/integration/test-handle-redirect-as-used-mirror-change
@@ -22,3 +22,6 @@ Reading package lists..." aptget update
testsuccessequal "Hit:1 http://0.0.0.0:${APTHTTPPORT} unstable InRelease
Reading package lists..." aptget update
+
+testsuccess apthelper download-file "http://localhost:${APTHTTPPORT}/redirectme/dists/unstable/InRelease" inrelease
+testsuccess test -s inrelease