Browse Source

* basic error reporting from apt in place now (ReportMirrorFailures())

Michael Vogt 17 years ago
parent
commit
cae9cdcefc
7 changed files with 42 additions and 15 deletions
  1. 9 1
      apt-pkg/acquire-item.cc
  2. 1 0
      apt-pkg/acquire-item.h
  3. 1 0
      apt-pkg/acquire-method.cc
  4. 1 0
      apt-pkg/acquire-method.h
  5. 21 6
      methods/mirror.cc
  6. 1 0
      methods/mirror.h
  7. 8 8
      po/apt-all.pot

+ 9 - 1
apt-pkg/acquire-item.cc

@@ -176,7 +176,8 @@ string pkgAcqIndex::Custom600Headers()
    struct stat Buf;
    if (stat(Final.c_str(),&Buf) != 0)
       return "\nIndex-File: true";
-   
+   if(ExpectedMD5 != "")
+      return "\nExpectedMD5: " + ExpectedMD5;
    return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
 }
 									/*}}}*/
@@ -1015,6 +1016,13 @@ void pkgAcqArchive::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
    }
 }
 									/*}}}*/
+// ---------------------------------------------------------------------
+string pkgAcqArchive::Custom600Headers()
+{
+   if(MD5 != "")
+      return "\nExpectedMD5: " + MD5;
+   return "";
+}
 // AcqArchive::IsTrusted - Determine whether this archive comes from a
 // trusted source							/*{{{*/
 // ---------------------------------------------------------------------

+ 1 - 0
apt-pkg/acquire-item.h

@@ -205,6 +205,7 @@ class pkgAcqArchive : public pkgAcquire::Item
    virtual string ShortDesc() {return Desc.ShortDesc;};
    virtual void Finished();
    virtual bool IsTrusted();
+   virtual string Custom600Headers();
    
    pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
 		 pkgRecords *Recs,pkgCache::VerIterator const &Version,

+ 1 - 0
apt-pkg/acquire-method.cc

@@ -368,6 +368,7 @@ int pkgAcqMethod::Run(bool Single)
 	    
 	    Tmp->Uri = LookupTag(Message,"URI");
 	    Tmp->DestFile = LookupTag(Message,"FileName");
+	    Tmp->ExpectedMD5 = LookupTag(Message,"ExpectedMD5");
 	    if (StrToTime(LookupTag(Message,"Last-Modified"),Tmp->LastModified) == false)
 	       Tmp->LastModified = 0;
 	    Tmp->IndexFile = StringToBool(LookupTag(Message,"Index-File"),false);

+ 1 - 0
apt-pkg/acquire-method.h

@@ -33,6 +33,7 @@ class pkgAcqMethod
       string DestFile;
       time_t LastModified;
       bool IndexFile;
+      string ExpectedMD5;
    };
    
    struct FetchResult

+ 21 - 6
methods/mirror.cc

@@ -32,14 +32,14 @@ using namespace std;
 
 /* 
  * TODO: 
- * - send expected checksum to the mirror method so that 
-     some checking/falling back can be done here already
-     use pkgAcquire::Custom600Header() for this? what about gpgv 
-     failures?
+ * - what about gpgv  failures? better standard format for errors
+     to send back to LP
    #OR#
  * - implement it at the pkgAcquire::Item::Failed() level but then
-     we need to send back what uri exactly was failing
-
+     we need to send back what uri exactly was failing 
+     [mvo: the problem with this approach is ::Failed() is not really
+           called for all failures :/ e.g. md5sum mismatch in a archive
+           is not]
  * - deal with runing as non-root because we can't write to the lists 
      dir then -> use the cached mirror file
  * - better method to download than having a pkgAcquire interface here
@@ -214,6 +214,9 @@ bool MirrorMethod::Fetch(FetchItem *Itm)
 
 void MirrorMethod::Fail(string Err,bool Transient)
 {
+   // FIXME: queue next mirror?
+   ReportMirrorFailure(Err);
+
    if(Queue->Uri.find("http://") != string::npos)
       Queue->Uri.replace(0,Mirror.size(), BaseUri);
    pkgAcqMethod::Fail(Err, Transient);
@@ -228,11 +231,23 @@ void MirrorMethod::URIStart(FetchResult &Res)
 
 void MirrorMethod::URIDone(FetchResult &Res,FetchResult *Alt)
 {
+   // FIXME: queue next mirror?
+   if(Queue->ExpectedMD5 != "" && Res.MD5Sum != Queue->ExpectedMD5)
+      ReportMirrorFailure("499 Hash mismatch");
+
    if(Queue->Uri.find("http://") != string::npos)
       Queue->Uri.replace(0,Mirror.size(), BaseUri);
    pkgAcqMethod::URIDone(Res, Alt);
 }
 
+void MirrorMethod::ReportMirrorFailure(string FailCode)
+{
+   // report that Queue->Uri failed
+   std::cerr << "\nReportMirrorFailure: " 
+	     << Queue->Uri
+	     << " FailCode: " 
+	     << FailCode << std::endl;
+}
 
 int main()
 {

+ 1 - 0
methods/mirror.h

@@ -35,6 +35,7 @@ class MirrorMethod : public HttpMethod
    bool GetMirrorFile(string uri);
    bool SelectMirror();
    bool Clean(string dir);
+   void ReportMirrorFailure(string FailCode);
    
    // we need to overwrite those to transform the url back
    virtual void Fail(string Why, bool Transient = false);

+ 8 - 8
po/apt-all.pot

@@ -1330,7 +1330,7 @@ msgstr ""
 
 #: apt-inst/extract.cc:467 apt-pkg/contrib/configuration.cc:750
 #: apt-pkg/contrib/cdromutl.cc:153 apt-pkg/sourcelist.cc:324
-#: apt-pkg/acquire.cc:421 apt-pkg/clean.cc:38 methods/mirror.cc:86
+#: apt-pkg/acquire.cc:421 apt-pkg/clean.cc:38 methods/mirror.cc:92
 #, c-format
 msgid "Unable to read %s"
 msgstr ""
@@ -1956,7 +1956,7 @@ msgid "Unable to stat the mount point %s"
 msgstr ""
 
 #: apt-pkg/contrib/cdromutl.cc:149 apt-pkg/acquire.cc:427 apt-pkg/clean.cc:44
-#: methods/mirror.cc:92
+#: methods/mirror.cc:98
 #, c-format
 msgid "Unable to change to %s"
 msgstr ""
@@ -2362,35 +2362,35 @@ msgstr ""
 msgid "rename failed, %s (%s -> %s)."
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:236 apt-pkg/acquire-item.cc:945
+#: apt-pkg/acquire-item.cc:237 apt-pkg/acquire-item.cc:946
 msgid "MD5Sum mismatch"
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:640
+#: apt-pkg/acquire-item.cc:641
 msgid "There is no public key available for the following key IDs:\n"
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:753
+#: apt-pkg/acquire-item.cc:754
 #, c-format
 msgid ""
 "I wasn't able to locate a file for the %s package. This might mean you need "
 "to manually fix this package. (due to missing arch)"
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:812
+#: apt-pkg/acquire-item.cc:813
 #, c-format
 msgid ""
 "I wasn't able to locate file for the %s package. This might mean you need to "
 "manually fix this package."
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:848
+#: apt-pkg/acquire-item.cc:849
 #, c-format
 msgid ""
 "The package index files are corrupted. No Filename: field for package %s."
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:935
+#: apt-pkg/acquire-item.cc:936
 msgid "Size mismatch"
 msgstr ""