]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire-worker.cc
merged from lp:~donkult/apt/sid
[apt.git] / apt-pkg / acquire-worker.cc
index 460f599611dba48868c515b7535ad6584fe95365..75e03232a1de76a28ed2e57de03159542d6a28d0 100644 (file)
@@ -199,6 +199,17 @@ bool pkgAcquire::Worker::RunMessages()
       pkgAcquire::Queue::QItem *Itm = 0;
       if (URI.empty() == false)
         Itm = OwnerQ->FindItem(URI,this);
       pkgAcquire::Queue::QItem *Itm = 0;
       if (URI.empty() == false)
         Itm = OwnerQ->FindItem(URI,this);
+
+      // update used mirror
+      string UsedMirror = LookupTag(Message,"UsedMirror", "");
+      if (!UsedMirror.empty() && 
+          Itm && 
+          Itm->Description.find(" ") != string::npos) 
+      {
+         Itm->Description.replace(0, Itm->Description.find(" "), UsedMirror);
+         // FIXME: will we need this as well?
+         //Itm->ShortDesc = UsedMirror;
+      }
       
       // Determine the message number and dispatch
       switch (Number)
       
       // Determine the message number and dispatch
       switch (Number)
@@ -220,6 +231,20 @@ bool pkgAcquire::Worker::RunMessages()
         Status = LookupTag(Message,"Message");
         break;
            
         Status = LookupTag(Message,"Message");
         break;
            
+         // 103 Redirect
+         case 103:
+         {
+            if (Itm == 0)
+            {
+               _error->Error("Method gave invalid 103 Redirect message");
+               break;
+            }
+            string NewURI = LookupTag(Message,"New-URI",URI.c_str());
+            Itm->URI = NewURI;
+            break;
+         }
+   
         // 200 URI Start
         case 200:
         {
         // 200 URI Start
         case 200:
         {
@@ -262,10 +287,10 @@ bool pkgAcquire::Worker::RunMessages()
               Log->Pulse(Owner->GetOwner());
            
            OwnerQ->ItemDone(Itm);
               Log->Pulse(Owner->GetOwner());
            
            OwnerQ->ItemDone(Itm);
-           if (TotalSize != 0 &&
-               (unsigned)atoi(LookupTag(Message,"Size","0").c_str()) != TotalSize)
-              _error->Warning("Bizarre Error - File size is not what the server reported %s %lu",
-                              LookupTag(Message,"Size","0").c_str(),TotalSize);
+           unsigned long const ServerSize = atol(LookupTag(Message,"Size","0").c_str());
+           if (TotalSize != 0 && ServerSize != TotalSize)
+              _error->Warning("Size of file %s is not what the server reported %s %lu",
+                              Owner->DestFile.c_str(), LookupTag(Message,"Size","0").c_str(),TotalSize);
 
            // see if there is a hash to verify
            string RecivedHash;
 
            // see if there is a hash to verify
            string RecivedHash;
@@ -273,7 +298,9 @@ bool pkgAcquire::Worker::RunMessages()
            if(!expectedHash.empty()) 
            {
               string hashTag = expectedHash.HashType()+"-Hash";
            if(!expectedHash.empty()) 
            {
               string hashTag = expectedHash.HashType()+"-Hash";
-              RecivedHash = expectedHash.HashType() + ":" + LookupTag(Message, hashTag.c_str());
+              string hashSum = LookupTag(Message, hashTag.c_str());
+              if(!hashSum.empty())
+                 RecivedHash = expectedHash.HashType() + ":" + hashSum;
               if(_config->FindB("Debug::pkgAcquire::Auth", false) == true)
               {
                  clog << "201 URI Done: " << Owner->DescURI() << endl
               if(_config->FindB("Debug::pkgAcquire::Auth", false) == true)
               {
                  clog << "201 URI Done: " << Owner->DescURI() << endl
@@ -282,8 +309,7 @@ bool pkgAcquire::Worker::RunMessages()
                       << endl << endl;
               }
            }
                       << endl << endl;
               }
            }
-           Owner->Done(Message,atoi(LookupTag(Message,"Size","0").c_str()),
-                       RecivedHash.c_str(), Config);
+           Owner->Done(Message, ServerSize, RecivedHash.c_str(), Config);
            ItemDone();
            
            // Log that we are done
            ItemDone();
            
            // Log that we are done
@@ -323,6 +349,7 @@ bool pkgAcquire::Worker::RunMessages()
            // set some status
            if(LookupTag(Message,"FailReason") == "Timeout" || 
               LookupTag(Message,"FailReason") == "TmpResolveFailure" ||
            // set some status
            if(LookupTag(Message,"FailReason") == "Timeout" || 
               LookupTag(Message,"FailReason") == "TmpResolveFailure" ||
+              LookupTag(Message,"FailReason") == "ResolveFailure" ||
               LookupTag(Message,"FailReason") == "ConnectionRefused") 
               Owner->Status = pkgAcquire::Item::StatTransientNetworkError;
 
               LookupTag(Message,"FailReason") == "ConnectionRefused") 
               Owner->Status = pkgAcquire::Item::StatTransientNetworkError;
 
@@ -510,10 +537,6 @@ bool pkgAcquire::Worker::OutFdReady()
    
    if (Res <= 0)
       return MethodFailure();
    
    if (Res <= 0)
       return MethodFailure();
-
-   // Hmm.. this should never happen.
-   if (Res < 0)
-      return true;
    
    OutQueue.erase(0,Res);
    if (OutQueue.empty() == true)
    
    OutQueue.erase(0,Res);
    if (OutQueue.empty() == true)
@@ -541,7 +564,8 @@ bool pkgAcquire::Worker::MethodFailure()
 {
    _error->Error("Method %s has died unexpectedly!",Access.c_str());
    
 {
    _error->Error("Method %s has died unexpectedly!",Access.c_str());
    
-   ExecWait(Process,Access.c_str(),true);
+   // do not reap the child here to show meaningfull error to the user
+   ExecWait(Process,Access.c_str(),false);
    Process = -1;
    close(InFd);
    close(OutFd);
    Process = -1;
    close(InFd);
    close(OutFd);