]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire-worker.cc
Czech program translation update
[apt.git] / apt-pkg / acquire-worker.cc
index 8d619e96da9a1daed290d04cbab56712f0aa38fd..176772dde47d5c93a75bc0449390cbf7f56cd201 100644 (file)
@@ -26,7 +26,6 @@
 #include <string>
 #include <vector>
 #include <iostream>
-#include <sstream>
 
 #include <sys/stat.h>
 #include <stdlib.h>
@@ -34,9 +33,7 @@
 #include <signal.h>
 #include <stdio.h>
 #include <errno.h>
-#include <sys/types.h>
-#include <pwd.h>
-#include <grp.h>
+#include <sstream>
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -204,19 +201,22 @@ bool pkgAcquire::Worker::RunMessages()
         return _error->Error("Invalid message from method %s: %s",Access.c_str(),Message.c_str());
 
       string URI = LookupTag(Message,"URI");
-      pkgAcquire::Queue::QItem *Itm = 0;
+      pkgAcquire::Queue::QItem *Itm = NULL;
       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)
+      if (Itm != NULL)
       {
-         Itm->Description.replace(0, Itm->Description.find(" "), UsedMirror);
-         // FIXME: will we need this as well?
-         //Itm->ShortDesc = UsedMirror;
+        // update used mirror
+        string UsedMirror = LookupTag(Message,"UsedMirror", "");
+        if (UsedMirror.empty() == false)
+        {
+           for (pkgAcquire::Queue::QItem::owner_iterator O = Itm->Owners.begin(); O != Itm->Owners.end(); ++O)
+              (*O)->UsedMirror = UsedMirror;
+
+           if (Itm->Description.find(" ") != string::npos)
+              Itm->Description.replace(0, Itm->Description.find(" "), UsedMirror);
+        }
       }
 
       // Determine the message number and dispatch
@@ -248,17 +248,14 @@ bool pkgAcquire::Worker::RunMessages()
                break;
             }
 
-            string NewURI = LookupTag(Message,"New-URI",URI.c_str());
+           std::string const NewURI = LookupTag(Message,"New-URI",URI.c_str());
             Itm->URI = NewURI;
 
            ItemDone();
 
            // Change the status so that it can be dequeued
            for (pkgAcquire::Queue::QItem::owner_iterator O = Itm->Owners.begin(); O != Itm->Owners.end(); ++O)
-           {
-              pkgAcquire::Item *Owner = *O;
-              Owner->Status = pkgAcquire::Item::StatIdle;
-           }
+              (*O)->Status = pkgAcquire::Item::StatIdle;
            // Mark the item as done (taking care of all queues)
            // and then put it in the main queue again
            std::vector<Item*> const ItmOwners = Itm->Owners;
@@ -267,12 +264,28 @@ bool pkgAcquire::Worker::RunMessages()
            for (pkgAcquire::Queue::QItem::owner_iterator O = ItmOwners.begin(); O != ItmOwners.end(); ++O)
            {
               pkgAcquire::Item *Owner = *O;
-              pkgAcquire::ItemDesc desc = Owner->GetItemDesc();
+              pkgAcquire::ItemDesc &desc = Owner->GetItemDesc();
+              // if we change site, treat it as a mirror change
+              if (URI::SiteOnly(NewURI) != URI::SiteOnly(desc.URI))
+              {
+                 std::string const OldSite = desc.Description.substr(0, desc.Description.find(" "));
+                 if (likely(APT::String::Startswith(desc.URI, OldSite)))
+                 {
+                    std::string const OldExtra = desc.URI.substr(OldSite.length() + 1);
+                    if (likely(APT::String::Endswith(NewURI, OldExtra)))
+                    {
+                       std::string const NewSite = NewURI.substr(0, NewURI.length() - OldExtra.length());
+                       Owner->UsedMirror = URI::ArchiveOnly(NewSite);
+                       if (desc.Description.find(" ") != string::npos)
+                          desc.Description.replace(0, desc.Description.find(" "), Owner->UsedMirror);
+                    }
+                 }
+              }
               desc.URI = NewURI;
               OwnerQ->Owner->Enqueue(desc);
 
               if (Log != 0)
-                 Log->Done(Owner->GetItemDesc());
+                 Log->Done(desc);
            }
             break;
          }
@@ -322,9 +335,10 @@ bool pkgAcquire::Worker::RunMessages()
               for (pkgAcquire::Queue::QItem::owner_iterator O = Itm->Owners.begin(); O != Itm->Owners.end(); ++O)
                  Log->Pulse((*O)->GetOwner());
 
-           std::string const filename = LookupTag(Message, "Filename", Itm->Owner->DestFile.c_str());
            HashStringList ReceivedHashes;
            {
+              std::string const givenfilename = LookupTag(Message, "Filename");
+              std::string const filename = givenfilename.empty() ? Itm->Owner->DestFile : givenfilename;
               // see if we got hashes to verify
               for (char const * const * type = HashString::SupportedHashes(); *type != NULL; ++type)
               {
@@ -345,11 +359,11 @@ bool pkgAcquire::Worker::RunMessages()
                     ReceivedHashes = calc.GetHashStringList();
                  }
               }
-           }
 
-           // only local files can refer other filenames and counting them as fetched would be unfair
-           if (Log !=  NULL && filename != Itm->Owner->DestFile)
-              Log->Fetched(ReceivedHashes.FileSize(),atoi(LookupTag(Message,"Resume-Point","0").c_str()));
+              // only local files can refer other filenames and counting them as fetched would be unfair
+              if (Log != NULL && Itm->Owner->Complete == false && Itm->Owner->Local == false && givenfilename == filename)
+                 Log->Fetched(ReceivedHashes.FileSize(),atoi(LookupTag(Message,"Resume-Point","0").c_str()));
+           }
 
            std::vector<Item*> const ItmOwners = Itm->Owners;
            OwnerQ->ItemDone(Itm);
@@ -395,11 +409,14 @@ bool pkgAcquire::Worker::RunMessages()
               else
                  consideredOkay = true;
 
+              if (consideredOkay == true)
+                 consideredOkay = Owner->VerifyDone(Message, Config);
+              else // hashsum mismatch
+                 Owner->Status = pkgAcquire::Item::StatAuthError;
+
               if (consideredOkay == true)
               {
                  Owner->Done(Message, ReceivedHashes, Config);
-
-                 // Log that we are done
                  if (Log != 0)
                  {
                     if (isIMSHit)
@@ -410,9 +427,7 @@ bool pkgAcquire::Worker::RunMessages()
               }
               else
               {
-                 Owner->Status = pkgAcquire::Item::StatAuthError;
                  Owner->Failed(Message,Config);
-
                  if (Log != 0)
                     Log->Fail(Owner->GetItemDesc());
               }
@@ -521,7 +536,7 @@ bool pkgAcquire::Worker::MediaChange(string Message)
       ostringstream msg,status;
       ioprintf(msg,_("Please insert the disc labeled: "
                     "'%s' "
-                    "in the drive '%s' and press enter."),
+                    "in the drive '%s' and press [Enter]."),
               Media.c_str(),Drive.c_str());
       status << "media-change: "  // message
             << Media  << ":"     // media
@@ -722,7 +737,7 @@ void pkgAcquire::Worker::PrepareFiles(char const * const caller, pkgAcquire::Que
         unlink(Owner->DestFile.c_str());
         if (link(filename.c_str(), Owner->DestFile.c_str()) != 0)
         {
-           // diferent mounts can't happen for us as we download to lists/ by default,
+           // different mounts can't happen for us as we download to lists/ by default,
            // but if the system is reused by others the locations can potentially be on
            // different disks, so use symlink as poor-men replacement.
            // FIXME: Real copying as last fallback, but that is costly, so offload to a method preferable