[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#668111: apt: better handling of external redirections



Apparently, it is really necessary to fully simulate as if the item had 
indeed been downloaded. Attached patch does that, also fixing the log 
output.

The side effect is that the status line looks kinda funny, at least when 
using http.d.n. Not sure if I should be calling Log->Done(Desc) before 
calling Enqueue.

By the way, I don't know if any other method uses the redirection feature, 
but I'm a bit concerned of changing the meaning of code 103. Perhaps the 
code number should be bumped.

Cheers,
-- 
Raphael Geissert - Debian Developer
www.debian.org - get.debian.net
diff --git a/apt-0.8.15.10/methods/http.cc b/apt-0.8.15.10.wip/methods/http.cc
index 65a0cbb..cbc6c69 100644
--- a/apt-0.8.15.10/methods/http.cc
+++ b/apt-0.8.15.10.wip/methods/http.cc
@@ -967,7 +967,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 */
    }
diff --git a/apt-0.8.15.10/apt-pkg/acquire-method.cc b/apt-0.8.15.10.wip/apt-pkg/acquire-method.cc
index 294d78f..eddf443 100644
--- a/apt-0.8.15.10/apt-pkg/acquire-method.cc
+++ b/apt-0.8.15.10.wip/apt-pkg/acquire-method.cc
@@ -417,26 +417,19 @@ 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. */
 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;
+   // Dequeue
+   FetchItem *Tmp = Queue;
    Queue = Queue->Next;
-   I->Next->Next = 0;
-   if (QueueBack == 0)
-      QueueBack = I->Next;
+   delete Tmp;
+   if (Tmp == QueueBack)
+      QueueBack = Queue;
 }
                                                                         /*}}}*/
 // AcqMethod::FetchResult::FetchResult - Constructor			/*{{{*/
diff --git a/apt-0.8.15.10/apt-pkg/acquire-worker.cc b/apt-0.8.15.10.new/apt-pkg/acquire-worker.cc
index 75e0323..3c65b51 100644
--- a/apt-0.8.15.10/apt-pkg/acquire-worker.cc
+++ b/apt-0.8.15.10.new/apt-pkg/acquire-worker.cc
@@ -242,6 +242,22 @@ 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
+            // dequeued with Dequeue, to keep the counter in sync
+	    OwnerQ->ItemDone(Itm);
+            OwnerQ->Owner->Enqueue(Desc);
+
+            if (Log != 0)
+               Log->Done(Desc);
             break;
          }
    

Reply to: