Explorar o código

add shared code into pkgAcqMetaSigBase::GenerateAuthWarning()

Michael Vogt %!s(int64=12) %!d(string=hai) anos
pai
achega
e6e8939038
Modificáronse 2 ficheiros con 65 adicións e 54 borrados
  1. 51 52
      apt-pkg/acquire-item.cc
  2. 14 2
      apt-pkg/acquire-item.h

+ 51 - 52
apt-pkg/acquire-item.cc

@@ -1367,13 +1367,56 @@ void pkgAcqIndexTrans::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
    Item::Failed(Message,Cnf);
 }
 									/*}}}*/
+
+pkgAcqMetaSigBase::pkgAcqMetaSigBase(pkgAcquire *Owner,
+                                     HashStringList const &ExpectedHashes,
+                                     unsigned long TransactionID)
+   : Item(Owner, ExpectedHashes, TransactionID)
+{
+}
+                                                                       /*{{{*/
+bool pkgAcqMetaSigBase::GenerateAuthWarning(const std::string &RealURI,
+                                            const std::string &Message)
+{
+   string Final = _config->FindDir("Dir::State::lists") + URItoFileName(RealURI);
+   
+   if(FileExists(Final))
+   {
+      Status = StatTransientNetworkError;
+      _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"),
+                      Desc.Description.c_str(),
+                      LookupTag(Message,"Message").c_str());
+      RunScripts("APT::Update::Auth-Failure");
+      return true;
+   } else if (LookupTag(Message,"Message").find("NODATA") != string::npos) {
+      /* Invalid signature file, reject (LP: #346386) (Closes: #627642) */
+      _error->Error(_("GPG error: %s: %s"),
+                    Desc.Description.c_str(),
+                    LookupTag(Message,"Message").c_str());
+      Status = StatError;
+      return true;
+   } else {
+      _error->Warning(_("GPG error: %s: %s"),
+                      Desc.Description.c_str(),
+                      LookupTag(Message,"Message").c_str());
+   }
+   // gpgv method failed 
+   ReportMirrorFailure("GPGFailure");
+   return false;
+}
+									/*}}}*/
+
+
 pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire *Owner,          		/*{{{*/
                              unsigned long TransactionID,
 			     string URI,string URIDesc,string ShortDesc,
                              string MetaIndexFile,
 			     const vector<IndexTarget*>* IndexTargets,
 			     indexRecords* MetaIndexParser) :
-   Item(Owner, HashStringList(), TransactionID), RealURI(URI), 
+   pkgAcqMetaSigBase(Owner, HashStringList(), TransactionID), RealURI(URI), 
    MetaIndexParser(MetaIndexParser), MetaIndexFile(MetaIndexFile),
    IndexTargets(IndexTargets), AuthPass(false), IMSHit(false)
 {
@@ -1490,31 +1533,9 @@ void pkgAcqMetaSig::Failed(string Message,pkgAcquire::MethodConfig *Cnf)/*{{{*/
    // FIXME: duplicated code from pkgAcqMetaIndex
    if (AuthPass == true)
    {
-      if(FileExists(Final))
-      {
-	 Status = StatTransientNetworkError;
-	 _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"),
-			 Desc.Description.c_str(),
-			 LookupTag(Message,"Message").c_str());
-	 RunScripts("APT::Update::Auth-Failure");
-	 return;
-      } else if (LookupTag(Message,"Message").find("NODATA") != string::npos) {
-	 /* Invalid signature file, reject (LP: #346386) (Closes: #627642) */
-	 _error->Error(_("GPG error: %s: %s"),
-			 Desc.Description.c_str(),
-			 LookupTag(Message,"Message").c_str());
-         Status = StatError;
-	 return;
-      } else {
-	 _error->Warning(_("GPG error: %s: %s"),
-			 Desc.Description.c_str(),
-			 LookupTag(Message,"Message").c_str());
-      }
-      // gpgv method failed 
-      ReportMirrorFailure("GPGFailure");
+      bool Stop = GenerateAuthWarning(RealURI, Message);
+      if(Stop)
+         return;
    }
 
    // FIXME: this is used often (e.g. in pkgAcqIndexTrans) so refactor
@@ -1536,7 +1557,7 @@ pkgAcqMetaIndex::pkgAcqMetaIndex(pkgAcquire *Owner,			/*{{{*/
                                  string MetaIndexSigURI,string MetaIndexSigURIDesc, string MetaIndexSigShortDesc,
 				 const vector<IndexTarget*>* IndexTargets,
 				 indexRecords* MetaIndexParser) :
-   Item(Owner, HashStringList(), TransactionID), RealURI(URI), IndexTargets(IndexTargets),
+   pkgAcqMetaSigBase(Owner, HashStringList(), TransactionID), RealURI(URI), IndexTargets(IndexTargets),
    MetaIndexParser(MetaIndexParser), AuthPass(false), IMSHit(false),
    MetaIndexSigURI(MetaIndexSigURI), MetaIndexSigURIDesc(MetaIndexSigURIDesc),
    MetaIndexSigShortDesc(MetaIndexSigShortDesc)
@@ -1905,31 +1926,9 @@ void pkgAcqMetaIndex::Failed(string Message,
 
    if (AuthPass == true)
    {
-      if(FileExists(Final))
-      {
-	 Status = StatTransientNetworkError;
-	 _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"),
-			 Desc.Description.c_str(),
-			 LookupTag(Message,"Message").c_str());
-	 RunScripts("APT::Update::Auth-Failure");
-	 return;
-      } else if (LookupTag(Message,"Message").find("NODATA") != string::npos) {
-	 /* Invalid signature file, reject (LP: #346386) (Closes: #627642) */
-	 _error->Error(_("GPG error: %s: %s"),
-			 Desc.Description.c_str(),
-			 LookupTag(Message,"Message").c_str());
-         Status = StatError;
-	 return;
-      } else {
-	 _error->Warning(_("GPG error: %s: %s"),
-			 Desc.Description.c_str(),
-			 LookupTag(Message,"Message").c_str());
-      }
-      // gpgv method failed 
-      ReportMirrorFailure("GPGFailure");
+      bool Stop = GenerateAuthWarning(RealURI, Message);
+      if(Stop)
+         return;
    }
 
    /* Always move the meta index, even if gpgv failed. This ensures

+ 14 - 2
apt-pkg/acquire-item.h

@@ -378,6 +378,18 @@ class pkgAcqSubIndex : public pkgAcquire::Item
 };
 									/*}}}*/
 
+class pkgAcqMetaSigBase : public pkgAcquire::Item
+{
+ protected:
+   bool GenerateAuthWarning(const std::string &RealURI,
+                            const std::string &Message);
+
+ public:
+   pkgAcqMetaSigBase(pkgAcquire *Owner,
+                     HashStringList const &ExpectedHashes=HashStringList(),
+                     unsigned long TransactionID=0);
+};
+
 /** \brief An item that is responsible for downloading the meta-index	{{{
  *  file (i.e., Release) itself and verifying its signature.
  *
@@ -388,7 +400,7 @@ class pkgAcqSubIndex : public pkgAcquire::Item
  *  otherwise, the expected hashsums will be "" (causing the
  *  authentication of the index files to be bypassed).
  */
-class pkgAcqMetaIndex : public pkgAcquire::Item
+class pkgAcqMetaIndex : public pkgAcqMetaSigBase
 {
    protected:
    /** \brief The URI that is actually being downloaded; never
@@ -1017,7 +1029,7 @@ class OptionalSubIndexTarget : public OptionalIndexTarget
  *
  *  \sa pkgAcqMetaIndex
  */
-class pkgAcqMetaSig : public pkgAcquire::Item
+class pkgAcqMetaSig : public pkgAcqMetaSigBase
 {
    protected:
    /** \brief The last good signature file */