* apt-pkg/acquire*.cc:
authorRaphael Geissert <geissert@debian.org>
Mon, 14 May 2012 16:07:01 +0000 (18:07 +0200)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Mon, 14 May 2012 16:07:01 +0000 (18:07 +0200)
  - handle redirections in the worker with the right method instead of
    in the method the redirection occured in (Closes: #668111)
* methods/http.cc:
  - forbid redirects to change protocol

apt-pkg/acquire-method.cc
apt-pkg/acquire-worker.cc
apt-pkg/acquire.cc
debian/changelog
methods/http.cc

index e6e02bb..5bc1c15 100644 (file)
@@ -412,26 +412,14 @@ void pkgAcqMethod::Status(const char *Format,...)
                                                                        /*}}}*/
 // AcqMethod::Redirect - Send a redirect message                       /*{{{*/
 // ---------------------------------------------------------------------
-/* This method sends the redirect message and also manipulates the queue
  to keep the pipeline synchronized. */
+/* This method sends the redirect message and dequeues the item as
* the worker will enqueue again later on to the right queue */
 void pkgAcqMethod::Redirect(const string &NewURI)
 {
    std::cout << "103 Redirect\nURI: " << Queue->Uri << "\n"
             << "New-URI: " << NewURI << "\n"
             << "\n" << std::flush;
-
-   // Change the URI for the request.
-   Queue->Uri = NewURI;
-
-   /* To keep the pipeline synchronized, move the current request to
-      the end of the queue, past the end of the current pipeline. */
-   FetchItem *I;
-   for (I = Queue; I->Next != 0; I = I->Next) ;
-   I->Next = Queue;
-   Queue = Queue->Next;
-   I->Next->Next = 0;
-   if (QueueBack == 0)
-      QueueBack = I->Next;
+   Dequeue();
 }
                                                                         /*}}}*/
 // AcqMethod::FetchResult::FetchResult - Constructor                   /*{{{*/
index d6db8bc..9d90b08 100644 (file)
@@ -244,6 +244,21 @@ bool pkgAcquire::Worker::RunMessages()
  
             string NewURI = LookupTag(Message,"New-URI",URI.c_str());
             Itm->URI = NewURI;
+
+           ItemDone();
+
+           pkgAcquire::Item *Owner = Itm->Owner;
+           pkgAcquire::ItemDesc Desc = *Itm;
+
+           // Change the status so that it can be dequeued
+           Owner->Status = pkgAcquire::Item::StatIdle;
+           // Mark the item as done (taking care of all queues)
+           // and then put it in the main queue again
+           OwnerQ->ItemDone(Itm);
+           OwnerQ->Owner->Enqueue(Desc);
+
+           if (Log != 0)
+              Log->Done(Desc);
             break;
          }
    
index 5e14190..a8a5abd 100644 (file)
@@ -244,11 +244,19 @@ void pkgAcquire::Dequeue(Item *Itm)
 {
    Queue *I = Queues;
    bool Res = false;
-   for (; I != 0; I = I->Next)
-      Res |= I->Dequeue(Itm);
-   
    if (Debug == true)
       clog << "Dequeuing " << Itm->DestFile << endl;
+
+   for (; I != 0; I = I->Next)
+   {
+      if (I->Dequeue(Itm))
+      {
+         Res = true;
+        if (Debug == true)
+           clog << "Dequeued from " << I->Name << endl;
+      }
+   }
+
    if (Res == true)
       ToFetch--;
 }
@@ -269,9 +277,30 @@ string pkgAcquire::QueueName(string Uri,MethodConfig const *&Config)
    /* Single-Instance methods get exactly one queue per URI. This is
       also used for the Access queue method  */
    if (Config->SingleInstance == true || QueueMode == QueueAccess)
-       return U.Access;
+      return U.Access;
+
+   string AccessSchema = U.Access + ':',
+       FullQueueName = AccessSchema + U.Host;
+   unsigned int Instances = 0, SchemaLength = AccessSchema.length();
+
+   Queue *I = Queues;
+   for (; I != 0; I = I->Next) {
+      // if the queue already exists, re-use it
+      if (I->Name == FullQueueName)
+        return FullQueueName;
+
+      if (I->Name.compare(0, SchemaLength, AccessSchema) == 0)
+        Instances++;
+   }
+
+   if (Debug) {
+      clog << "Found " << Instances << " instances of " << U.Access << endl;
+   }
+
+   if (Instances >= (unsigned int)_config->FindI("Acquire::QueueHost::Limit",10))
+      return U.Access;
 
-   return U.Access + ':' + U.Host;
+   return FullQueueName;
 }
                                                                        /*}}}*/
 // Acquire::GetConfig - Fetch the configuration information            /*{{{*/
index 7097a6e..937bde9 100644 (file)
@@ -18,6 +18,13 @@ apt (0.9.4) UNRELEASED; urgency=low
   * apt-pkg/acquire-methods.cc:
     - factor out into private Dequeue() to fix access to deleted pointer
 
+  [ Raphael Geissert ]
+  * apt-pkg/acquire*.cc:
+    - handle redirections in the worker with the right method instead of
+      in the method the redirection occured in (Closes: #668111)
+  * methods/http.cc:
+    - forbid redirects to change protocol
+
  -- David Kalnischkies <kalnischkies@gmail.com>  Fri, 11 May 2012 23:26:59 +0200
 
 apt (0.9.3) unstable; urgency=low
index b450b6f..bb02176 100644 (file)
@@ -985,7 +985,10 @@ HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv)
       else
       {
          NextURI = DeQuoteString(Srv->Location);
-         return TRY_AGAIN_OR_REDIRECT;
+         URI tmpURI = NextURI;
+         // Do not allow a redirection to switch protocol
+         if (tmpURI.Access == "http")
+            return TRY_AGAIN_OR_REDIRECT;
       }
       /* else pass through for error message */
    }