]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire-worker.cc
support comments in debian/control parsing
[apt.git] / apt-pkg / acquire-worker.cc
index dc03a8870a0a4360a104f0d348831c0b6b2a7c65..c2ee8cda39fdba8962fae476ad602cdc84e14464 100644 (file)
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/hashes.h>
 
+#include <algorithm>
 #include <string>
 #include <vector>
 #include <iostream>
-#include <sstream>
 
 #include <sys/stat.h>
 #include <stdlib.h>
@@ -34,9 +34,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>
                                                                        /*}}}*/
@@ -257,8 +255,8 @@ bool pkgAcquire::Worker::RunMessages()
            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)
-              (*O)->Status = pkgAcquire::Item::StatIdle;
+           for (auto const &O: Itm->Owners)
+              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;
@@ -338,9 +336,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)
               {
@@ -361,11 +360,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);
@@ -409,13 +408,22 @@ bool pkgAcquire::Worker::RunMessages()
               else if (Owner->HashesRequired() == true)
                  consideredOkay = false;
               else
+              {
                  consideredOkay = true;
+                 // even if the hashes aren't usable to declare something secure
+                 // we can at least use them to declare it an integrity failure
+                 if (ExpectedHashes.empty() == false && ReceivedHashes != ExpectedHashes && _config->Find("Acquire::ForceHash").empty())
+                    consideredOkay = false;
+              }
+
+              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)
@@ -426,9 +434,7 @@ bool pkgAcquire::Worker::RunMessages()
               }
               else
               {
-                 Owner->Status = pkgAcquire::Item::StatAuthError;
                  Owner->Failed(Message,Config);
-
                  if (Log != 0)
                     Log->Fail(Owner->GetItemDesc());
               }
@@ -458,15 +464,18 @@ bool pkgAcquire::Worker::RunMessages()
            OwnerQ->ItemDone(Itm);
            Itm = NULL;
 
+           bool errTransient;
+           {
+              std::string const failReason = LookupTag(Message, "FailReason");
+              std::string const reasons[] = { "Timeout", "ConnectionRefused",
+                 "ConnectionTimedOut", "ResolveFailure", "TmpResolveFailure" };
+              errTransient = std::find(std::begin(reasons), std::end(reasons), failReason) != std::end(reasons);
+           }
+
            for (pkgAcquire::Queue::QItem::owner_iterator O = ItmOwners.begin(); O != ItmOwners.end(); ++O)
            {
-              // set some status
-              if(LookupTag(Message,"FailReason") == "Timeout" ||
-                    LookupTag(Message,"FailReason") == "TmpResolveFailure" ||
-                    LookupTag(Message,"FailReason") == "ResolveFailure" ||
-                    LookupTag(Message,"FailReason") == "ConnectionRefused")
+              if (errTransient)
                  (*O)->Status = pkgAcquire::Item::StatTransientNetworkError;
-
               (*O)->Failed(Message,Config);
 
               if (Log != 0)
@@ -537,7 +546,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
@@ -630,7 +639,7 @@ bool pkgAcquire::Worker::QueueItem(pkgAcquire::Queue::QItem *Item)
 
    if (RealFileExists(Item->Owner->DestFile))
    {
-      std::string SandboxUser = _config->Find("APT::Sandbox::User");
+      std::string const SandboxUser = _config->Find("APT::Sandbox::User");
       ChangeOwnerAndPermissionOfFile("Item::QueueURI", Item->Owner->DestFile.c_str(),
                                      SandboxUser.c_str(), "root", 0600);
    }
@@ -733,9 +742,9 @@ void pkgAcquire::Worker::PrepareFiles(char const * const caller, pkgAcquire::Que
       for (pkgAcquire::Queue::QItem::owner_iterator O = Itm->Owners.begin(); O != Itm->Owners.end(); ++O)
       {
         pkgAcquire::Item const * const Owner = *O;
-        if (Owner->DestFile == filename)
+        if (Owner->DestFile == filename || filename == "/dev/null")
            continue;
-        unlink(Owner->DestFile.c_str());
+        RemoveFile("PrepareFiles", Owner->DestFile);
         if (link(filename.c_str(), Owner->DestFile.c_str()) != 0)
         {
            // different mounts can't happen for us as we download to lists/ by default,
@@ -750,7 +759,7 @@ void pkgAcquire::Worker::PrepareFiles(char const * const caller, pkgAcquire::Que
    else
    {
       for (pkgAcquire::Queue::QItem::owner_iterator O = Itm->Owners.begin(); O != Itm->Owners.end(); ++O)
-        unlink((*O)->DestFile.c_str());
+        RemoveFile("PrepareFiles", (*O)->DestFile);
    }
 }
                                                                        /*}}}*/