]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire-item.cc
use one 'store' method to rule all (de)compressors
[apt.git] / apt-pkg / acquire-item.cc
index ae10ed8f498b59c6c06e59b7be9ed0ad65e6bcfa..6b0debb44fd7b84011cb61b9cc25343b21c6a98f 100644 (file)
@@ -153,7 +153,7 @@ static bool MessageInsecureRepository(bool const isError, std::string const &msg
    if (isError)
    {
       _error->Error("%s", msg.c_str());
-      _error->Notice("%s", _("Updating such a repository securely is impossible and therefore disabled by default."));
+      _error->Notice("%s", _("Updating from such a repository can't be done securely, and is therefore disabled by default."));
    }
    else
    {
@@ -422,7 +422,7 @@ bool pkgAcqIndex::TransactionState(TransactionStates const state)
         {
            // keep the compressed file, but drop the decompressed
            EraseFileName.clear();
-           if (PartialFile.empty() == false && flExtension(PartialFile) == "decomp")
+           if (PartialFile.empty() == false && flExtension(PartialFile) != CurrentCompressionExtension)
               RemoveFile("TransactionAbort", PartialFile);
         }
         break;
@@ -1042,9 +1042,13 @@ void pkgAcqMetaBase::QueueIndexes(bool const verify)                     /*{{{*/
       // download time, bandwidth and diskspace for nothing, BUT Debian doesn't feature all
       // in the set of supported architectures, so we can filter based on this property rather
       // than invent an entirely new flag we would need to carry for all of eternity.
-      if (Target->Option(IndexTarget::ARCHITECTURE) == "all" &&
-           TransactionManager->MetaIndexParser->IsArchitectureSupported("all") == false)
-        continue;
+      if (Target->Option(IndexTarget::ARCHITECTURE) == "all")
+      {
+        if (TransactionManager->MetaIndexParser->IsArchitectureSupported("all") == false)
+           continue;
+        if (TransactionManager->MetaIndexParser->IsArchitectureAllSupportedFor(*Target) == false)
+           continue;
+      }
 
       bool trypdiff = Target->OptionBool(IndexTarget::PDIFFS);
       if (verify == true)
@@ -1075,6 +1079,16 @@ void pkgAcqMetaBase::QueueIndexes(bool const verify)                     /*{{{*/
            strprintf(ErrorText, _("Unable to find expected entry '%s' in Release file (Wrong sources.list entry or malformed file)"), Target->MetaKey.c_str());
            return;
         }
+        else
+        {
+           auto const hashes = GetExpectedHashesFor(Target->MetaKey);
+           if (hashes.usable() == false && hashes.empty() == false)
+           {
+              _error->Warning(_("Skipping acquire of configured file '%s' as repository '%s' provides only weak security information for it"),
+                       Target->MetaKey.c_str(), TransactionManager->Target.Description.c_str());
+              continue;
+           }
+        }
 
         // autoselect the compression method
         std::vector<std::string> types = VectorizeString(Target->Option(IndexTarget::COMPRESSIONTYPES), ' ');
@@ -1837,10 +1851,18 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string const &IndexDiffFile)       /*{{{*/
       std::clog << "Server-Current: " << ServerHashes.find(NULL)->toStr() << " and we start at "
         << CurrentPackagesFile << " " << LocalHashes.FileSize() << " " << LocalHashes.find(NULL)->toStr() << std::endl;
 
+   // historically, older hashes have more info than newer ones, so start
+   // collecting with older ones first to avoid implementing complicated
+   // information merging techniques… a failure is after all always
+   // recoverable with a complete file and hashes aren't changed that often.
+   std::vector<char const *> types;
+   for (char const * const * type = HashString::SupportedHashes(); *type != NULL; ++type)
+      types.push_back(*type);
+
    // parse all of (provided) history
    vector<DiffInfo> available_patches;
    bool firstAcceptedHashes = true;
-   for (char const * const * type = HashString::SupportedHashes(); *type != NULL; ++type)
+   for (auto type = types.crbegin(); type != types.crend(); ++type)
    {
       if (LocalHashes.find(*type) == NULL)
         continue;
@@ -1898,7 +1920,7 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string const &IndexDiffFile) /*{{{*/
       return false;
    }
 
-   for (char const * const * type = HashString::SupportedHashes(); *type != NULL; ++type)
+   for (auto type = types.crbegin(); type != types.crend(); ++type)
    {
       if (LocalHashes.find(*type) == NULL)
         continue;
@@ -1938,7 +1960,7 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string const &IndexDiffFile) /*{{{*/
       }
    }
 
-   for (char const * const * type = HashString::SupportedHashes(); *type != NULL; ++type)
+   for (auto type = types.crbegin(); type != types.crend(); ++type)
    {
       std::string tagname = *type;
       tagname.append("-Download");
@@ -2659,7 +2681,8 @@ void pkgAcqIndex::StageDownloadDone(string const &Message, HashStringList const
    {
       Stage = STAGE_DECOMPRESS_AND_VERIFY;
       Local = true;
-      DestFile += ".decomp";
+      if (CurrentCompressionExtension != "uncompressed")
+        DestFile.erase(DestFile.length() - (CurrentCompressionExtension.length() + 1));
       Desc.URI = "copy:" + FileName;
       QueueURI(Desc);
       SetActiveSubprocess("copy");
@@ -2681,6 +2704,18 @@ void pkgAcqIndex::StageDownloadDone(string const &Message, HashStringList const
         SetActiveSubprocess("copy");
         return;
       }
+      else
+      {
+        // symlinking ensures that the filename can be used for compression detection
+        // that is e.g. needed for by-hash over file
+        if (symlink(FileName.c_str(),DestFile.c_str()) != 0)
+           _error->WarningE("pkgAcqIndex::StageDownloadDone", "Symlinking file %s to %s failed", FileName.c_str(), DestFile.c_str());
+        else
+        {
+           EraseFileName = DestFile;
+           FileName = DestFile;
+        }
+      }
    }
    else
       EraseFileName = FileName;
@@ -2695,25 +2730,19 @@ void pkgAcqIndex::StageDownloadDone(string const &Message, HashStringList const
       return;
    }
 
-   // get the binary name for your used compression type
-   string decompProg;
-   if(CurrentCompressionExtension == "uncompressed")
-      decompProg = "copy";
-   else
-      decompProg = _config->Find(string("Acquire::CompressionTypes::").append(CurrentCompressionExtension),"");
-   if(decompProg.empty() == true)
-   {
-      _error->Error("Unsupported extension: %s", CurrentCompressionExtension.c_str());
-      return;
-   }
-
+   string decompProg = "store";
    if (Target.KeepCompressed == true)
    {
       DestFile = "/dev/null";
       EraseFileName.clear();
    }
    else
-      DestFile += ".decomp";
+   {
+      if (CurrentCompressionExtension == "uncompressed")
+        decompProg = "copy";
+      else
+        DestFile.erase(DestFile.length() - (CurrentCompressionExtension.length() + 1));
+   }
 
    // queue uri for the next stage
    Stage = STAGE_DECOMPRESS_AND_VERIFY;
@@ -3178,7 +3207,7 @@ std::string pkgAcqChangelog::URI(std::string const &Template,
         char const * const Component, char const * const SrcName,
         char const * const SrcVersion)
 {
-   if (Template.find("CHANGEPATH") == std::string::npos)
+   if (Template.find("@CHANGEPATH@") == std::string::npos)
       return "";
 
    // the path is: COMPONENT/SRC/SRCNAME/SRCNAME_SRCVER, e.g. main/a/apt/1.1 or contrib/liba/libapt/2.0
@@ -3190,7 +3219,7 @@ std::string pkgAcqChangelog::URI(std::string const &Template,
    if (Component != NULL && strlen(Component) != 0)
       path = std::string(Component) + "/" + path;
 
-   return SubstVar(Template, "CHANGEPATH", path);
+   return SubstVar(Template, "@CHANGEPATH@", path);
 }
                                                                        /*}}}*/
 // AcqChangelog::Failed - Failure handler                              /*{{{*/