]> git.saurik.com Git - apt.git/commitdiff
Merge remote-tracking branch 'mvo/feature/update-by-hash' into debian/experimental
authorMichael Vogt <mvo@debian.org>
Wed, 18 Jun 2014 08:46:08 +0000 (10:46 +0200)
committerMichael Vogt <mvo@debian.org>
Wed, 18 Jun 2014 08:46:08 +0000 (10:46 +0200)
1  2 
apt-pkg/acquire-item.cc
apt-pkg/acquire-item.h

diff --combined apt-pkg/acquire-item.cc
index 70d03b84576d8ae63ca2a4b3fb048e6756115d97,e111ed4ca28cd464d14a05b59292e019e71b2f6f..e453085574e0e505611f4d6f342e626d41b6def0
@@@ -1018,6 -1018,8 +1018,8 @@@ void pkgAcqIndex::Init(string const &UR
        indexRecords::checkSum *Record = MetaIndexParser->Lookup(MetaKey);
        if(Record)
           FileSize = Record->Size;
+       
+       InitByHashIfNeeded(MetaKey);
     }
  
     Desc.Description = URIDesc;
     QueueURI(Desc);
  }
                                                                        /*}}}*/
+ // AcqIndex::AdjustForByHash - modify URI for by-hash support         /*{{{*/
+ // ---------------------------------------------------------------------
+ /* */
+ void pkgAcqIndex::InitByHashIfNeeded(const std::string MetaKey)
+ {
+    // TODO:
+    //  - (maybe?) add support for by-hash into the sources.list as flag
+    //  - make apt-ftparchive generate the hashes (and expire?)
+    std::string HostKnob = "APT::Acquire::" + ::URI(Desc.URI).Host + "::By-Hash";
+    if(_config->FindB("APT::Acquire::By-Hash", false) == true ||
+       _config->FindB(HostKnob, false) == true ||
+       MetaIndexParser->GetSupportsAcquireByHash())
+    {
+       indexRecords::checkSum *Record = MetaIndexParser->Lookup(MetaKey);
+       if(Record)
+       {
+          // FIXME: should we really use the best hash here? or a fixed one?
+          const HashString *TargetHash = Record->Hashes.find("");
+          std::string ByHash = "/by-hash/" + TargetHash->HashType() + "/" + TargetHash->HashValue();
+          size_t trailing_slash = Desc.URI.find_last_of("/");
+          Desc.URI = Desc.URI.replace(
+             trailing_slash,
+             Desc.URI.substr(trailing_slash+1).size()+1,
+             ByHash);
+       } else {
+          _error->Warning(
+             "Fetching ByHash requested but can not find record for %s",
+             MetaKey.c_str());
+       }
+    }
+ }
+                                                                       /*}}}*/
  // AcqIndex::Custom600Headers - Insert custom request headers         /*{{{*/
  // ---------------------------------------------------------------------
  /* The only header we use is the last-modified header. */
@@@ -1620,6 -1654,7 +1654,6 @@@ void pkgAcqMetaIndex::QueueIndexes(boo
  
     // at this point the real Items are loaded in the fetcher
     ExpectedAdditionalItems = 0;
 -
     for (vector <IndexTarget*>::const_iterator Target = IndexTargets->begin();
          Target != IndexTargets->end();
          ++Target)
diff --combined apt-pkg/acquire-item.h
index 6e204813a7b927772912d8d2be103f6f59270d9d,cda92e84f5d77354c1f7c8973e7c599a322d5ff3..b4cac2f04448b1b2a589d86ea6001b65ed36cf93
@@@ -713,6 -713,9 +713,9 @@@ class pkgAcqIndex : public pkgAcqBaseIn
      */
     std::string CompressionExtension;
  
+    /** \brief Do the changes needed to fetch via AptByHash (if needed) */
+    void InitByHashIfNeeded(const std::string MetaKey);
     public:
     
     // Specialized action members
               std::string ShortDesc, HashStringList const &ExpectedHashes,
               std::string compressExt="");
     pkgAcqIndex(pkgAcquire *Owner,
 -               struct IndexTarget const * const Target,
 +               IndexTarget const * const Target,
                 HashStringList const &ExpectedHash,
                 indexRecords *MetaIndexParser);
     void Init(std::string const &URI, std::string const &URIDesc,