some more coverity fixes
[ntk/apt.git] / apt-pkg / acquire-item.cc
index 9b78621..f70cabe 100644 (file)
@@ -560,7 +560,7 @@ pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire *Owner,
    Desc.Owner = this;
    Desc.ShortDesc = ShortDesc;
 
-   if(available_patches.size() == 0) 
+   if(available_patches.empty() == true)
    {
       // we are done (yeah!)
       Finish(true);
@@ -984,6 +984,8 @@ void pkgAcqIndex::Done(string Message,unsigned long long Size,string Hash,
    DestFile += ".decomp";
    Desc.URI = decompProg + ":" + FileName;
    QueueURI(Desc);
+
+   // FIXME: this points to a c++ string that goes out of scope
    Mode = decompProg.c_str();
 }
                                                                        /*}}}*/
@@ -1289,7 +1291,14 @@ void pkgAcqMetaIndex::RetrievalDone(string Message)                      /*{{{*/
       string FinalFile = _config->FindDir("Dir::State::lists");
       FinalFile += URItoFileName(RealURI);
       if (SigFile == DestFile)
+      {
         SigFile = FinalFile;
+        // constructor of pkgAcqMetaClearSig moved it out of the way,
+        // now move it back in on IMS hit for the 'old' file
+        string const OldClearSig = DestFile + ".reverify";
+        if (RealFileExists(OldClearSig) == true)
+           Rename(OldClearSig, FinalFile);
+      }
       DestFile = FinalFile;
    }
    Complete = true;
@@ -1362,9 +1371,20 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify)                          /*{{{*/
    {
       HashString ExpectedIndexHash;
       const indexRecords::checkSum *Record = MetaIndexParser->Lookup((*Target)->MetaKey);
+      bool compressedAvailable = false;
       if (Record == NULL)
       {
-        if (verify == true && (*Target)->IsOptional() == false)
+        if ((*Target)->IsOptional() == true)
+        {
+           std::vector<std::string> types = APT::Configuration::getCompressionTypes();
+           for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
+              if (MetaIndexParser->Exists(string((*Target)->MetaKey).append(".").append(*t)) == true)
+              {
+                 compressedAvailable = true;
+                 break;
+              }
+        }
+        else if (verify == true)
         {
            Status = StatAuthError;
            strprintf(ErrorText, _("Unable to find expected entry '%s' in Release file (Wrong sources.list entry or malformed file)"), (*Target)->MetaKey.c_str());
@@ -1393,7 +1413,7 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify)                           /*{{{*/
         if ((*Target)->IsSubIndex() == true)
            new pkgAcqSubIndex(Owner, (*Target)->URI, (*Target)->Description,
                                (*Target)->ShortDesc, ExpectedIndexHash);
-        else if (transInRelease == false || MetaIndexParser->Exists((*Target)->MetaKey) == true)
+        else if (transInRelease == false || Record != NULL || compressedAvailable == true)
         {
            if (_config->FindB("Acquire::PDiffs",true) == true && transInRelease == true &&
                MetaIndexParser->Exists(string((*Target)->MetaKey).append(".diff/Index")) == true)
@@ -1515,7 +1535,7 @@ void pkgAcqMetaIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
            VerifiedSigFile.append(".gpg");
         Rename(LastGoodSigFile, VerifiedSigFile);
         Status = StatTransientNetworkError;
-        _error->Warning(_("A error occurred during the signature "
+        _error->Warning(_("An error occurred during the signature "
                           "verification. The repository is not updated "
                           "and the previous index files will be used. "
                           "GPG error: %s: %s\n"),
@@ -1595,7 +1615,11 @@ string pkgAcqMetaClearSig::Custom600Headers()
 
    struct stat Buf;
    if (stat(Final.c_str(),&Buf) != 0)
-      return "\nIndex-File: true\nFail-Ignore: true\n";
+   {
+      Final = DestFile + ".reverify";
+      if (stat(Final.c_str(),&Buf) != 0)
+        return "\nIndex-File: true\nFail-Ignore: true\n";
+   }
 
    return "\nIndex-File: true\nFail-Ignore: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
 }
@@ -1649,7 +1673,7 @@ pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
       assumption here that all the available sources for this version share
       the same extension.. */
    // Skip not source sources, they do not have file fields.
-   for (; Vf.end() == false; Vf++)
+   for (; Vf.end() == false; ++Vf)
    {
       if ((Vf.File()->Flags & pkgCache::Flag::NotSource) != 0)
         continue;