]> git.saurik.com Git - apt.git/commitdiff
donkults fixes
authorMichael Vogt <mvo@ubuntu.com>
Wed, 1 Oct 2014 22:38:35 +0000 (00:38 +0200)
committerMichael Vogt <mvo@ubuntu.com>
Wed, 1 Oct 2014 22:38:35 +0000 (00:38 +0200)
apt-pkg/acquire-item.cc
apt-pkg/acquire-item.h
test/integration/test-apt-by-hash-update

index b3c41a178bffd5c37be8efdaa6f67f2da5cb1b95..54e99345865587a1fe725c4fb21bf244c59b8a52 100644 (file)
@@ -269,12 +269,12 @@ pkgAcqDiffIndex::pkgAcqDiffIndex(pkgAcquire *Owner,
                                 HashStringList const &ExpectedHashes,
                                  indexRecords *MetaIndexParser)
    : pkgAcqBaseIndex(Owner, TransactionManager, Target, ExpectedHashes, 
-                     MetaIndexParser), PackagesFileReadyInPartial(false)
+                     MetaIndexParser, Target->URI), 
+     PackagesFileReadyInPartial(false)
 {
    
    Debug = _config->FindB("Debug::pkgAcquire::Diffs",false);
 
-   RealURI = Target->URI;
    Desc.Owner = this;
    Desc.Description = Target->Description + "/DiffIndex";
    Desc.ShortDesc = Target->ShortDesc;
@@ -528,7 +528,7 @@ void pkgAcqDiffIndex::Done(string Message,unsigned long long Size,HashStringList
    Item::Done(Message, Size, Hashes, Cnf);
 
    // verify the index target
-   if(Target && Target->MetaKey != "" && MetaIndexParser && Hashes.size() > 0)
+   if(Target && Target->MetaKey != "" && MetaIndexParser && Hashes.usable())
    {
       std::string IndexMetaKey  = Target->MetaKey + ".diff/Index";
       indexRecords::checkSum *Record = MetaIndexParser->Lookup(IndexMetaKey);
@@ -576,7 +576,8 @@ pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire *Owner,
                                    indexRecords *MetaIndexParser,
                                   string ServerSha1,
                                   vector<DiffInfo> diffs)
-   : pkgAcqBaseIndex(Owner, TransactionManager, Target, ExpectedHashes, MetaIndexParser),
+   : pkgAcqBaseIndex(Owner, TransactionManager, Target, ExpectedHashes, 
+                     MetaIndexParser, Target->URI),
      available_patches(diffs), ServerSha1(ServerSha1)
 {
    
@@ -585,7 +586,6 @@ pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire *Owner,
 
    Debug = _config->FindB("Debug::pkgAcquire::Diffs",false);
 
-   RealURI = Target->URI;
    Desc.Owner = this;
    Description = Target->Description;
    Desc.ShortDesc = Target->ShortDesc;
@@ -799,7 +799,8 @@ pkgAcqIndexMergeDiffs::pkgAcqIndexMergeDiffs(pkgAcquire *Owner,
                                              indexRecords *MetaIndexParser,
                                              DiffInfo const &patch,
                                              std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches)
-  : pkgAcqBaseIndex(Owner, TransactionManager, Target, ExpectedHashes, MetaIndexParser),
+  : pkgAcqBaseIndex(Owner, TransactionManager, Target, ExpectedHashes, 
+                    MetaIndexParser, Target->URI),
      patch(patch), allPatches(allPatches), State(StateFetchDiff)
 {
 
@@ -808,7 +809,6 @@ pkgAcqIndexMergeDiffs::pkgAcqIndexMergeDiffs(pkgAcquire *Owner,
 
    Debug = _config->FindB("Debug::pkgAcquire::Diffs",false);
 
-   RealURI = Target->URI;
    Desc.Owner = this;
    Description = Target->Description;
    Desc.ShortDesc = Target->ShortDesc;
@@ -937,7 +937,7 @@ void pkgAcqIndexMergeDiffs::Done(string Message,unsigned long long Size,HashStri
 // AcqBaseIndex::VerifyHashByMetaKey - verify hash for the given metakey /*{{{*/
 bool pkgAcqBaseIndex::VerifyHashByMetaKey(HashStringList const &Hashes)
 {
-   if(MetaKey != "" && Hashes.size() > 0)
+   if(MetaKey != "" && Hashes.usable())
    {
       indexRecords::checkSum *Record = MetaIndexParser->Lookup(MetaKey);
       if(Record && Record->Hashes.usable() && Hashes != Record->Hashes)
@@ -957,10 +957,8 @@ bool pkgAcqBaseIndex::VerifyHashByMetaKey(HashStringList const &Hashes)
 pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner,
                         string URI,string URIDesc,string ShortDesc,
                         HashStringList const  &ExpectedHash)
-   : pkgAcqBaseIndex(Owner, 0, NULL, ExpectedHash, NULL)
+   : pkgAcqBaseIndex(Owner, 0, NULL, ExpectedHash, NULL, RealURI)
 {
-   RealURI = URI;
-
    AutoSelectCompression();
    Init(URI, URIDesc, ShortDesc);
 
@@ -977,10 +975,8 @@ pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner,
                         HashStringList const &ExpectedHash, 
                          indexRecords *MetaIndexParser)
    : pkgAcqBaseIndex(Owner, TransactionManager, Target, ExpectedHash, 
-                     MetaIndexParser)
+                     MetaIndexParser, Target->URI)
 {
-   RealURI = Target->URI;
-
    // autoselect the compression method
    AutoSelectCompression();
    Init(Target->URI, Target->Description, Target->ShortDesc);
@@ -1025,8 +1021,8 @@ void pkgAcqIndex::Init(string const &URI, string const &URIDesc,
    DestFile = _config->FindDir("Dir::State::lists") + "partial/";
    DestFile += URItoFileName(URI);
 
-   ComprExt = CompressionExtensions.substr(0, CompressionExtensions.find(' '));
-   if (ComprExt == "uncompressed")
+   CurrentCompressionExtension = CompressionExtensions.substr(0, CompressionExtensions.find(' '));
+   if (CurrentCompressionExtension == "uncompressed")
    {
       Desc.URI = URI;
       if(Target)
@@ -1034,10 +1030,10 @@ void pkgAcqIndex::Init(string const &URI, string const &URIDesc,
    }
    else
    {
-      Desc.URI = URI + '.' + ComprExt;
-      DestFile = DestFile + '.' + ComprExt;
+      Desc.URI = URI + '.' + CurrentCompressionExtension;
+      DestFile = DestFile + '.' + CurrentCompressionExtension;
       if(Target)
-         MetaKey = string(Target->MetaKey) + '.' + ComprExt;
+         MetaKey = string(Target->MetaKey) + '.' + CurrentCompressionExtension;
    }
 
    // load the filesize
@@ -1120,9 +1116,7 @@ void pkgAcqIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf)    /*{{{*/
    // on decompression failure, remove bad versions in partial/
    if (Stage == STAGE_DECOMPRESS_AND_VERIFY)
    {
-      string s = _config->FindDir("Dir::State::lists") + "partial/";
-      s += URItoFileName(RealURI)  + '.' + ComprExt;
-      unlink(s.c_str());
+      unlink(EraseFileName.c_str());
    }
 
    Item::Failed(Message,Cnf);
@@ -1139,7 +1133,7 @@ std::string pkgAcqIndex::GetFinalFilename() const
    std::string FinalFile = _config->FindDir("Dir::State::lists");
    FinalFile += URItoFileName(RealURI);
    if (_config->FindB("Acquire::GzipIndexes",false) == true)
-      FinalFile += '.' + ComprExt;
+      FinalFile += '.' + CurrentCompressionExtension;
    return FinalFile;
 }
                                                                        /*}}}*/
@@ -1155,7 +1149,7 @@ void pkgAcqIndex::ReverifyAfterIMS()
 
    // adjust DestFile if its compressed on disk
    if (_config->FindB("Acquire::GzipIndexes",false) == true)
-      DestFile += '.' + ComprExt;
+      DestFile += '.' + CurrentCompressionExtension;
 
    // copy FinalFile into partial/ so that we check the hash again
    string FinalFile = GetFinalFilename();
@@ -1266,6 +1260,8 @@ void pkgAcqIndex::StageDownloadDone(string Message,
    // not the "DestFile" we set, in this case we uncompress from the local file
    if (FileName != DestFile)
       Local = true;
+   else
+      EraseFileName = FileName;
 
    // we need to verify the file against the current Release file again
    // on if-modfied-since hit to avoid a stale attack against us
@@ -1277,6 +1273,7 @@ void pkgAcqIndex::StageDownloadDone(string Message,
          return;
 
       // The files timestamp matches, reverify by copy into partial/
+      EraseFileName = "";
       ReverifyAfterIMS();
       return;
    }
@@ -1285,8 +1282,8 @@ void pkgAcqIndex::StageDownloadDone(string Message,
    if (_config->FindB("Acquire::GzipIndexes",false))
    {
       DestFile = _config->FindDir("Dir::State::lists") + "partial/";
-      DestFile += URItoFileName(RealURI) + '.' + ComprExt;
-
+      DestFile += URItoFileName(RealURI) + '.' + CurrentCompressionExtension;
+      EraseFileName = "";
       Stage = STAGE_DECOMPRESS_AND_VERIFY;
       Desc.URI = "copy:" + FileName;
       QueueURI(Desc);
@@ -1296,13 +1293,13 @@ void pkgAcqIndex::StageDownloadDone(string Message,
 
    // get the binary name for your used compression type
    string decompProg;
-   if(ComprExt == "uncompressed")
+   if(CurrentCompressionExtension == "uncompressed")
       decompProg = "copy";
    else
-      decompProg = _config->Find(string("Acquire::CompressionTypes::").append(ComprExt),"");
+      decompProg = _config->Find(string("Acquire::CompressionTypes::").append(CurrentCompressionExtension),"");
    if(decompProg.empty() == true)
    {
-      _error->Error("Unsupported extension: %s", ComprExt.c_str());
+      _error->Error("Unsupported extension: %s", CurrentCompressionExtension.c_str());
       return;
    }
 
@@ -1344,14 +1341,8 @@ void pkgAcqIndex::StageDecompressDone(string Message,
       return;
    }
    
-   // remove the compressed version of the file (if the file got uncompressed)
-   URI Get = LookupTag(Message, "URI");
-   if (Get.Access != "copy")
-   {
-      // To account for relative paths
-      std::string CompressedFile = Get.Host + Get.Path;
-      unlink(CompressedFile.c_str());
-   }
+   // remove the compressed version of the file
+   unlink(EraseFileName.c_str());
    
    // Done, queue for rename on transaction finished
    TransactionManager->TransactionStageCopy(this, DestFile, GetFinalFilename());
index 6518c9a9887b1ef38c055e6e245673701f3eabee..5d5d6efb9e8f01374e13bda3bbb177134c4538d6 100644 (file)
@@ -619,9 +619,10 @@ class pkgAcqBaseIndex : public pkgAcquire::Item
                    pkgAcqMetaBase *TransactionManager,
                    struct IndexTarget const * const Target,
                    HashStringList const &ExpectedHashes,
-                   indexRecords *MetaIndexParser)
+                   indexRecords *MetaIndexParser,
+                   std::string RealURI)
       : Item(Owner, ExpectedHashes, TransactionManager), Target(Target), 
-        MetaIndexParser(MetaIndexParser) {};
+        MetaIndexParser(MetaIndexParser), RealURI(RealURI) {};
 };
                                                                        /*}}}*/
 /** \brief An item that is responsible for fetching an index file of   {{{
@@ -945,13 +946,18 @@ class pkgAcqIndex : public pkgAcqBaseIndex
                             HashStringList const &Hashes,
                             pkgAcquire::MethodConfig *Cfg);
 
+   /** \brief If \b set, this partially downloaded file will be
+    *  removed when the download completes.
+    */
+   std::string EraseFileName;
+
    /** \brief The compression-related file extensions that are being
     *  added to the downloaded file one by one if first fails (e.g., "gz bz2").
     */
    std::string CompressionExtensions;
 
    /** \brief The actual compression extension currently used */
-   std::string ComprExt;
+   std::string CurrentCompressionExtension;
 
    /** \brief Do the changes needed to fetch via AptByHash (if needed) */
    void InitByHashIfNeeded(const std::string MetaKey);
index 23282bf861a54a4a8e50fda8bd022d373e1990b0..6e1ecdaff21aaae863c78e0a9926d2e86adf65f4 100755 (executable)
@@ -34,7 +34,7 @@ Building dependency tree...
 E: Unable to locate package foo" aptget install -q -s foo
 
 # ensure we can apt-get update by hash
-testsuccess aptget update -o APT::Acquire::By-Hash=1
+testsuccess aptget update -o APT::Acquire::By-Hash=1 
 
 # ensure it works
 testequal "Inst foo (1.0 unstable [all])