Просмотр исходного кода

retry without same redirection mirror on 404 errors

If 9b8034a9fd40b4d05075fda719e61f6eb4c45678 serves the Release files
from a partial mirror we will end up getting 404 for some of the
indexes. Instead of giving up, we will instead ignore our same
redirection mirror constrain and ask the redirection service as a
potential hashsum mismatch is better than keeping the certain 404 error.
David Kalnischkies лет назад: 10
Родитель
Сommit
ad9416611a
2 измененных файлов с 41 добавлено и 5 удалено
  1. 21 1
      apt-pkg/acquire-item.cc
  2. 20 4
      test/integration/test-handle-redirect-as-used-mirror-change

+ 21 - 1
apt-pkg/acquire-item.cc

@@ -410,7 +410,7 @@ bool pkgAcqTransactionItem::QueueURI(pkgAcquire::ItemDesc &Item)
       return false;
       return false;
    }
    }
    // If we got the InRelease file via a mirror, pick all indexes directly from this mirror, too
    // If we got the InRelease file via a mirror, pick all indexes directly from this mirror, too
-   if (TransactionManager->BaseURI.empty() == false &&
+   if (TransactionManager->BaseURI.empty() == false && UsedMirror.empty() &&
 	 URI::SiteOnly(Item.URI) != URI::SiteOnly(TransactionManager->BaseURI))
 	 URI::SiteOnly(Item.URI) != URI::SiteOnly(TransactionManager->BaseURI))
    {
    {
       // this ensures we rewrite only once and only the first step
       // this ensures we rewrite only once and only the first step
@@ -1226,9 +1226,15 @@ bool pkgAcqMetaBase::CheckDownloadDone(pkgAcqTransactionItem * const I, const st
    if (I->UsedMirror.empty() == false && _config->FindB("Acquire::SameMirrorForAllIndexes", true))
    if (I->UsedMirror.empty() == false && _config->FindB("Acquire::SameMirrorForAllIndexes", true))
    {
    {
       if (APT::String::Endswith(I->Desc.URI, "InRelease"))
       if (APT::String::Endswith(I->Desc.URI, "InRelease"))
+      {
 	 TransactionManager->BaseURI = I->Desc.URI.substr(0, I->Desc.URI.length() - strlen("InRelease"));
 	 TransactionManager->BaseURI = I->Desc.URI.substr(0, I->Desc.URI.length() - strlen("InRelease"));
+	 TransactionManager->UsedMirror = I->UsedMirror;
+      }
       else if (APT::String::Endswith(I->Desc.URI, "Release"))
       else if (APT::String::Endswith(I->Desc.URI, "Release"))
+      {
 	 TransactionManager->BaseURI = I->Desc.URI.substr(0, I->Desc.URI.length() - strlen("Release"));
 	 TransactionManager->BaseURI = I->Desc.URI.substr(0, I->Desc.URI.length() - strlen("Release"));
+	 TransactionManager->UsedMirror = I->UsedMirror;
+      }
    }
    }
 
 
    std::string const FileName = LookupTag(Message,"Filename");
    std::string const FileName = LookupTag(Message,"Filename");
@@ -2935,6 +2941,20 @@ void pkgAcqIndex::Failed(string const &Message,pkgAcquire::MethodConfig const *
 {
 {
    pkgAcqBaseIndex::Failed(Message,Cnf);
    pkgAcqBaseIndex::Failed(Message,Cnf);
 
 
+   if (UsedMirror.empty() == false && UsedMirror != "DIRECT" &&
+	 LookupTag(Message, "FailReason") == "HttpError404")
+   {
+      UsedMirror = "DIRECT";
+      if (Desc.URI.find("/by-hash/") != std::string::npos)
+	 CompressionExtensions = "by-hash " + CompressionExtensions;
+      else
+	 CompressionExtensions = CurrentCompressionExtension + ' ' + CompressionExtensions;
+      Desc.Description = Target.Description;
+      Init(Target.URI, Desc.Description, Desc.ShortDesc);
+      Status = StatIdle;
+      return;
+   }
+
    // authorisation matches will not be fixed by other compression types
    // authorisation matches will not be fixed by other compression types
    if (Status != StatAuthError)
    if (Status != StatAuthError)
    {
    {

+ 20 - 4
test/integration/test-handle-redirect-as-used-mirror-change

@@ -44,10 +44,28 @@ testsuccess apthelper download-file "http://localhost:${APTHTTPPORT}/redirectme/
 testsuccess test -s inrelease
 testsuccess test -s inrelease
 cd - >/dev/null
 cd - >/dev/null
 
 
+webserverconfig "aptwebserver::redirect::replace::http://0.0.0.0:${APTHTTPPORT}/dists/unstable/InRelease" "http://0.0.0.0:${APTHTTPPORT}/storage/dists/unstable/InRelease"
+mkdir -p aptarchive/storage/dists/unstable
+mv aptarchive/dists/unstable/InRelease aptarchive/storage/dists/unstable
+rm -rf rootdir/var/lib/apt/lists
+testsuccessequal "Get:1 http://0.0.0.0:${APTHTTPPORT}/storage unstable InRelease [$(stat -c %s aptarchive/storage/dists/unstable/InRelease) B]
+Ign:2 http://0.0.0.0:${APTHTTPPORT}/storage unstable/main Sources
+  404  Not Found
+Ign:3 http://0.0.0.0:${APTHTTPPORT}/storage unstable/main all Packages
+  404  Not Found
+Ign:4 http://0.0.0.0:${APTHTTPPORT}/storage unstable/main Translation-en
+  404  Not Found
+Get:2 http://0.0.0.0:${APTHTTPPORT} unstable/main Sources [$(stat -c %s aptarchive/dists/unstable/main/source/Sources.gz) B]
+Get:3 http://0.0.0.0:${APTHTTPPORT} unstable/main all Packages [$(stat -c %s aptarchive/dists/unstable/main/binary-all/Packages.gz) B]
+Get:4 http://0.0.0.0:${APTHTTPPORT} unstable/main Translation-en [$(stat -c %s aptarchive/dists/unstable/main/i18n/Translation-en.gz) B]
+Reading package lists...
+Building dependency tree...
+All packages are up to date." apt update
+
 find aptarchive -name 'InRelease' -delete
 find aptarchive -name 'InRelease' -delete
 rm -rf rootdir/var/lib/apt/lists
 rm -rf rootdir/var/lib/apt/lists
 
 
-testsuccessequal "Ign:1 http://0.0.0.0:${APTHTTPPORT} unstable InRelease
+testsuccessequal "Ign:1 http://0.0.0.0:${APTHTTPPORT}/storage unstable InRelease
   404  Not Found
   404  Not Found
 Get:2 http://0.0.0.0:${APTHTTPPORT} unstable Release [$(stat -c %s aptarchive/dists/unstable/Release) B]
 Get:2 http://0.0.0.0:${APTHTTPPORT} unstable Release [$(stat -c %s aptarchive/dists/unstable/Release) B]
 Get:3 http://0.0.0.0:${APTHTTPPORT} unstable Release.gpg [$(stat -c %s aptarchive/dists/unstable/Release.gpg) B]
 Get:3 http://0.0.0.0:${APTHTTPPORT} unstable Release.gpg [$(stat -c %s aptarchive/dists/unstable/Release.gpg) B]
@@ -56,9 +74,7 @@ Get:5 http://0.0.0.0:${APTHTTPPORT} unstable/main all Packages [$(stat -c %s apt
 Get:6 http://0.0.0.0:${APTHTTPPORT} unstable/main Translation-en [$(stat -c %s aptarchive/dists/unstable/main/i18n/Translation-en.gz) B]
 Get:6 http://0.0.0.0:${APTHTTPPORT} unstable/main Translation-en [$(stat -c %s aptarchive/dists/unstable/main/i18n/Translation-en.gz) B]
 Reading package lists..." aptget update
 Reading package lists..." aptget update
 
 
-testsuccessequal "Ign:1 http://0.0.0.0:${APTHTTPPORT} unstable InRelease
+testsuccessequal "Ign:1 http://0.0.0.0:${APTHTTPPORT}/storage unstable InRelease
   404  Not Found
   404  Not Found
 Hit:2 http://0.0.0.0:${APTHTTPPORT} unstable Release
 Hit:2 http://0.0.0.0:${APTHTTPPORT} unstable Release
 Reading package lists..." aptget update
 Reading package lists..." aptget update
-
-