]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire-worker.cc
the previously used VERSION didn't work everywhere so we are switching
[apt.git] / apt-pkg / acquire-worker.cc
index 8ab67778be5b8322fcbb1967bb74b253144fb494..d79b2b16dfb22c3021ebda26ecbbcf4de204420c 100644 (file)
@@ -12,9 +12,8 @@
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
-#ifdef __GNUG__
-#pragma implementation "apt-pkg/acquire-worker.h"
-#endif
+#include <config.h>
+
 #include <apt-pkg/acquire-worker.h>
 #include <apt-pkg/acquire-item.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/strutl.h>
 
-#include <apti18n.h>
-
 #include <iostream>
 #include <sstream>
 #include <fstream>
-    
+
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <stdio.h>
 #include <errno.h>
+
+#include <apti18n.h>
                                                                        /*}}}*/
 
 using namespace std;
@@ -202,6 +201,17 @@ bool pkgAcquire::Worker::RunMessages()
       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)
@@ -223,6 +233,20 @@ bool pkgAcquire::Worker::RunMessages()
         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:
         {
@@ -234,9 +258,9 @@ bool pkgAcquire::Worker::RunMessages()
            
            CurrentItem = Itm;
            CurrentSize = 0;
-           TotalSize = atoi(LookupTag(Message,"Size","0").c_str());
-           ResumePoint = atoi(LookupTag(Message,"Resume-Point","0").c_str());
-           Itm->Owner->Start(Message,atoi(LookupTag(Message,"Size","0").c_str()));
+           TotalSize = strtoull(LookupTag(Message,"Size","0").c_str(), NULL, 10);
+           ResumePoint = strtoull(LookupTag(Message,"Resume-Point","0").c_str(), NULL, 10);
+           Itm->Owner->Start(Message,strtoull(LookupTag(Message,"Size","0").c_str(), NULL, 10));
 
            // Display update before completion
            if (Log != 0 && Log->MorePulses == true)
@@ -265,13 +289,29 @@ bool pkgAcquire::Worker::RunMessages()
               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 long const ServerSize = strtoull(LookupTag(Message,"Size","0").c_str(), NULL, 10);
+           if (TotalSize != 0 && ServerSize != TotalSize)
+              _error->Warning("Size of file %s is not what the server reported %s %llu",
+                              Owner->DestFile.c_str(), LookupTag(Message,"Size","0").c_str(),TotalSize);
 
-           Owner->Done(Message,atoi(LookupTag(Message,"Size","0").c_str()),
-                       LookupTag(Message,"MD5-Hash"),Config);
+           // see if there is a hash to verify
+           string RecivedHash;
+           HashString expectedHash(Owner->HashSum());
+           if(!expectedHash.empty()) 
+           {
+              string hashTag = expectedHash.HashType()+"-Hash";
+              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
+                      << "RecivedHash: " << RecivedHash << endl
+                      << "ExpectedHash: " << expectedHash.toStr() 
+                      << endl << endl;
+              }
+           }
+           Owner->Done(Message, ServerSize, RecivedHash.c_str(), Config);
            ItemDone();
            
            // Log that we are done
@@ -311,6 +351,7 @@ bool pkgAcquire::Worker::RunMessages()
            // 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;
 
@@ -390,7 +431,23 @@ bool pkgAcquire::Worker::MediaChange(string Message)
             << Drive  << ":"     // drive
             << msg.str()         // l10n message
             << endl;
-      write(status_fd, status.str().c_str(), status.str().size());
+
+      std::string const dlstatus = status.str();
+      size_t done = 0;
+      size_t todo = dlstatus.size();
+      errno = 0;
+      int res = 0;
+      do
+      {
+        res = write(status_fd, dlstatus.c_str() + done, todo);
+        if (res < 0 && errno == EINTR)
+           continue;
+        if (res < 0)
+           break;
+        done += res;
+        todo -= res;
+      }
+      while (res > 0 && todo > 0);
    }
 
    if (Log == 0 || Log->MediaChange(LookupTag(Message,"Media"),
@@ -498,10 +555,6 @@ bool pkgAcquire::Worker::OutFdReady()
    
    if (Res <= 0)
       return MethodFailure();
-
-   // Hmm.. this should never happen.
-   if (Res < 0)
-      return true;
    
    OutQueue.erase(0,Res);
    if (OutQueue.empty() == true)
@@ -529,7 +582,8 @@ bool pkgAcquire::Worker::MethodFailure()
 {
    _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);