From 5f6b130d6342965bfa49beb9413bdf742440b8ab Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 29 Nov 2006 21:24:29 +0100 Subject: * prototype of mirror method added --- methods/http.cc | 13 ++----- methods/http.h | 7 ++-- methods/http_main.cc | 15 ++++++++ methods/makefile | 9 ++++- methods/mirror.cc | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++ methods/mirror.h | 40 ++++++++++++++++++++++ po/apt-all.pot | 42 +++++++++++------------ 7 files changed, 187 insertions(+), 36 deletions(-) create mode 100644 methods/http_main.cc create mode 100644 methods/mirror.cc create mode 100644 methods/mirror.h diff --git a/methods/http.cc b/methods/http.cc index c6623c46f..deaa8d0c8 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -38,7 +38,6 @@ #include #include #include -#include #include // Internet stuff @@ -57,7 +56,7 @@ time_t HttpMethod::FailTime = 0; unsigned long PipelineDepth = 10; unsigned long TimeOut = 120; bool Debug = false; - +URI Proxy; unsigned long CircleBuf::BwReadLimit=0; unsigned long CircleBuf::BwTickReadData=0; @@ -990,7 +989,7 @@ void HttpMethod::SigTerm(int) depth. */ bool HttpMethod::Fetch(FetchItem *) { - if (Server == 0) + if (Server == 0) return true; // Queue the requests @@ -1223,13 +1222,5 @@ int HttpMethod::Loop() } /*}}}*/ -int main() -{ - setlocale(LC_ALL, ""); - - HttpMethod Mth; - - return Mth.Loop(); -} diff --git a/methods/http.h b/methods/http.h index 541e2952c..5eac11401 100644 --- a/methods/http.h +++ b/methods/http.h @@ -13,7 +13,7 @@ #define MAXLEN 360 -#include + using std::cout; using std::endl; @@ -134,7 +134,6 @@ class HttpMethod : public pkgAcqMethod bool ServerDie(ServerState *Srv); int DealWithHeaders(FetchResult &Res,ServerState *Srv); - virtual bool Fetch(FetchItem *); virtual bool Configuration(string Message); // In the event of a fatal signal this file will be closed and timestamped. @@ -142,6 +141,9 @@ class HttpMethod : public pkgAcqMethod static int FailFd; static time_t FailTime; static void SigTerm(int); + + protected: + virtual bool Fetch(FetchItem *); public: friend class ServerState; @@ -158,6 +160,5 @@ class HttpMethod : public pkgAcqMethod }; }; -URI Proxy; #endif diff --git a/methods/http_main.cc b/methods/http_main.cc new file mode 100644 index 000000000..2c46ab19d --- /dev/null +++ b/methods/http_main.cc @@ -0,0 +1,15 @@ +#include +#include + +#include "connect.h" +#include "rfc2553emu.h" +#include "http.h" + + +int main() +{ + setlocale(LC_ALL, ""); + + HttpMethod Mth; + return Mth.Loop(); +} diff --git a/methods/makefile b/methods/makefile index 1e3b1ef85..12e446a55 100644 --- a/methods/makefile +++ b/methods/makefile @@ -49,7 +49,7 @@ include $(PROGRAM_H) PROGRAM=http SLIBS = -lapt-pkg $(SOCKETLIBS) LIB_MAKES = apt-pkg/makefile -SOURCE = http.cc rfc2553emu.cc connect.cc +SOURCE = http.cc http_main.cc rfc2553emu.cc connect.cc include $(PROGRAM_H) # The ftp method @@ -66,6 +66,13 @@ LIB_MAKES = apt-pkg/makefile SOURCE = rsh.cc include $(PROGRAM_H) +# The mirror method +PROGRAM=mirror +SLIBS = -lapt-pkg $(SOCKETLIBS) +LIB_MAKES = apt-pkg/makefile +SOURCE = mirror.cc http.cc rfc2553emu.cc connect.cc +include $(PROGRAM_H) + # SSH and vzip2 method symlink binary: $(BIN)/ssh $(BIN)/bzip2 veryclean: clean-$(BIN)/ssh clean-$(BIN)/bzip2 diff --git a/methods/mirror.cc b/methods/mirror.cc new file mode 100644 index 000000000..fad076e91 --- /dev/null +++ b/methods/mirror.cc @@ -0,0 +1,97 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +// $Id: mirror.cc,v 1.59 2004/05/08 19:42:35 mdz Exp $ +/* ###################################################################### + + Mirror Aquire Method - This is the Mirror aquire method for APT. + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include +#include +#include +#include +#include +#include + +#include +#include +using namespace std; + +#include "mirror.h" +#include "http.h" + + /*}}}*/ + +MirrorMethod::MirrorMethod() + : pkgAcqMethod("1.2",Pipeline | SendConfig), HasMirrorFile(false) +{ +#if 0 + HasMirrorFile=true; + BaseUri="http://people.ubuntu.com/~mvo/mirror/mirrors///"; + Mirror="http://de.archive.ubuntu.com/ubuntu/"; +#endif +}; + +bool MirrorMethod::GetMirrorFile(string uri) +{ + string Marker = _config->Find("Acquire::Mirror::MagicMarker","///"); + BaseUri = uri.substr(0,uri.find(Marker)); + BaseUri.replace(0,strlen("mirror://"),"http://"); + + MirrorFile = _config->FindDir("Dir::State::lists") + URItoFileName(BaseUri); + + cerr << "base-uri: " << BaseUri << endl; + cerr << "mirror-file: " << MirrorFile << endl; + + // FIXME: fetch it with curl + pkgAcquire Fetcher; + new pkgAcqFile(&Fetcher, BaseUri, "", 0, "", "", "", MirrorFile); + bool res = (Fetcher.Run() == pkgAcquire::Continue); + cerr << "fetch-result: " << res << endl; + + if(res) + HasMirrorFile = true; + Fetcher.Shutdown(); + return true; +} + +bool MirrorMethod::SelectMirror() +{ + ifstream in(MirrorFile.c_str()); + getline(in, Mirror); + cerr << "Mirror: " << Mirror << endl; +} + +// MirrorMethod::Fetch - Fetch an item /*{{{*/ +// --------------------------------------------------------------------- +/* This adds an item to the pipeline. We keep the pipeline at a fixed + depth. */ +bool MirrorMethod::Fetch(FetchItem *Itm) +{ + // get mirror information + if(!HasMirrorFile) + { + GetMirrorFile(Itm->Uri); + SelectMirror(); + } + + // change the items in the queue + Itm->Uri.replace(0,BaseUri.size()+_config->Find("Acquire::Mirror::MagicMarker","///").size()+2/*len("mirror")-len("http")*/,Mirror); + cerr << "new Fetch-uri: " << Itm->Uri << endl; + + // FIXME: fetch it with! + +}; + +int main() +{ + setlocale(LC_ALL, ""); + + MirrorMethod Mth; + + return Mth.Run(); +} + + diff --git a/methods/mirror.h b/methods/mirror.h new file mode 100644 index 000000000..ca3428830 --- /dev/null +++ b/methods/mirror.h @@ -0,0 +1,40 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/// $Id: http.h,v 1.12 2002/04/18 05:09:38 jgg Exp $ +// $Id: http.h,v 1.12 2002/04/18 05:09:38 jgg Exp $ +/* ###################################################################### + + MIRROR Aquire Method - This is the MIRROR aquire method for APT. + + ##################################################################### */ + /*}}}*/ + +#ifndef APT_MIRROR_H +#define APT_MIRROR_H + + +#include + +using std::cout; +using std::cerr; +using std::endl; + +#include "http.h" + +class MirrorMethod : public pkgAcqMethod +{ + FetchResult Res; + string Mirror; + string BaseUri; + string MirrorFile; + bool HasMirrorFile; + + protected: + bool GetMirrorFile(string uri); + bool SelectMirror(); + public: + MirrorMethod(); + virtual bool Fetch(FetchItem *Itm); +}; + + +#endif diff --git a/po/apt-all.pot b/po/apt-all.pot index 521230146..b3da2ba9a 100644 --- a/po/apt-all.pot +++ b/po/apt-all.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2006-10-11 20:34+0200\n" +"POT-Creation-Date: 2006-11-24 16:37+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1621,7 +1621,7 @@ msgstr "" msgid "Unable to accept connection" msgstr "" -#: methods/ftp.cc:864 methods/http.cc:958 methods/rsh.cc:303 +#: methods/ftp.cc:864 methods/http.cc:957 methods/rsh.cc:303 msgid "Problem hashing file" msgstr "" @@ -1752,76 +1752,76 @@ msgstr "" msgid "Read error from %s process" msgstr "" -#: methods/http.cc:376 +#: methods/http.cc:375 msgid "Waiting for headers" msgstr "" -#: methods/http.cc:522 +#: methods/http.cc:521 #, c-format msgid "Got a single header line over %u chars" msgstr "" -#: methods/http.cc:530 +#: methods/http.cc:529 msgid "Bad header line" msgstr "" -#: methods/http.cc:549 methods/http.cc:556 +#: methods/http.cc:548 methods/http.cc:555 msgid "The HTTP server sent an invalid reply header" msgstr "" -#: methods/http.cc:585 +#: methods/http.cc:584 msgid "The HTTP server sent an invalid Content-Length header" msgstr "" -#: methods/http.cc:600 +#: methods/http.cc:599 msgid "The HTTP server sent an invalid Content-Range header" msgstr "" -#: methods/http.cc:602 +#: methods/http.cc:601 msgid "This HTTP server has broken range support" msgstr "" -#: methods/http.cc:626 +#: methods/http.cc:625 msgid "Unknown date format" msgstr "" -#: methods/http.cc:773 +#: methods/http.cc:772 msgid "Select failed" msgstr "" -#: methods/http.cc:778 +#: methods/http.cc:777 msgid "Connection timed out" msgstr "" -#: methods/http.cc:801 +#: methods/http.cc:800 msgid "Error writing to output file" msgstr "" -#: methods/http.cc:832 +#: methods/http.cc:831 msgid "Error writing to file" msgstr "" -#: methods/http.cc:860 +#: methods/http.cc:859 msgid "Error writing to the file" msgstr "" -#: methods/http.cc:874 +#: methods/http.cc:873 msgid "Error reading from server. Remote end closed connection" msgstr "" -#: methods/http.cc:876 +#: methods/http.cc:875 msgid "Error reading from server" msgstr "" -#: methods/http.cc:1107 +#: methods/http.cc:1106 msgid "Bad header data" msgstr "" -#: methods/http.cc:1124 +#: methods/http.cc:1123 msgid "Connection failed" msgstr "" -#: methods/http.cc:1215 +#: methods/http.cc:1214 msgid "Internal error" msgstr "" @@ -2366,7 +2366,7 @@ msgid "MD5Sum mismatch" msgstr "" #: apt-pkg/acquire-item.cc:640 -msgid "There are no public key available for the following key IDs:\n" +msgid "There is no public key available for the following key IDs:\n" msgstr "" #: apt-pkg/acquire-item.cc:753 -- cgit v1.2.3 From 14e097c105c49a102a642c8108979356c5cc3152 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 29 Nov 2006 22:59:35 +0100 Subject: * working mirror implementation based on http method --- apt-pkg/acquire-method.h | 7 +++-- methods/mirror.cc | 72 ++++++++++++++++++++++++++++++++++++++---------- methods/mirror.h | 15 +++++++--- 3 files changed, 73 insertions(+), 21 deletions(-) diff --git a/apt-pkg/acquire-method.h b/apt-pkg/acquire-method.h index f46209d12..e0e7c1d09 100644 --- a/apt-pkg/acquire-method.h +++ b/apt-pkg/acquire-method.h @@ -63,9 +63,10 @@ class pkgAcqMethod // Outgoing messages void Fail(bool Transient = false); inline void Fail(const char *Why, bool Transient = false) {Fail(string(Why),Transient);}; - void Fail(string Why, bool Transient = false); - void URIStart(FetchResult &Res); - void URIDone(FetchResult &Res,FetchResult *Alt = 0); + virtual void Fail(string Why, bool Transient = false); + virtual void URIStart(FetchResult &Res); + virtual void URIDone(FetchResult &Res,FetchResult *Alt = 0); + bool MediaFail(string Required,string Drive); virtual void Exit() {}; diff --git a/methods/mirror.cc b/methods/mirror.cc index fad076e91..c4d911a3c 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -17,6 +17,8 @@ #include #include +#include + using namespace std; #include "mirror.h" @@ -25,31 +27,50 @@ using namespace std; /*}}}*/ MirrorMethod::MirrorMethod() - : pkgAcqMethod("1.2",Pipeline | SendConfig), HasMirrorFile(false) + : HttpMethod(), HasMirrorFile(false) { #if 0 HasMirrorFile=true; - BaseUri="http://people.ubuntu.com/~mvo/mirror/mirrors///"; + BaseUri="mirror://people.ubuntu.com/~mvo/mirror/mirrors"; + MirrorFile="/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_mirror_mirrors"; Mirror="http://de.archive.ubuntu.com/ubuntu/"; #endif }; +// HttpMethod::Configuration - Handle a configuration message /*{{{*/ +// --------------------------------------------------------------------- +/* We stash the desired pipeline depth */ +bool MirrorMethod::Configuration(string Message) +{ + if (pkgAcqMethod::Configuration(Message) == false) + return false; + Debug = _config->FindB("Debug::Acquire::mirror",false); + + return true; +} + /*}}}*/ + + bool MirrorMethod::GetMirrorFile(string uri) { string Marker = _config->Find("Acquire::Mirror::MagicMarker","///"); BaseUri = uri.substr(0,uri.find(Marker)); - BaseUri.replace(0,strlen("mirror://"),"http://"); + + string fetch = BaseUri; + fetch.replace(0,strlen("mirror://"),"http://"); MirrorFile = _config->FindDir("Dir::State::lists") + URItoFileName(BaseUri); - cerr << "base-uri: " << BaseUri << endl; - cerr << "mirror-file: " << MirrorFile << endl; + if(Debug) + { + cerr << "base-uri: " << BaseUri << endl; + cerr << "mirror-file: " << MirrorFile << endl; + } // FIXME: fetch it with curl pkgAcquire Fetcher; - new pkgAcqFile(&Fetcher, BaseUri, "", 0, "", "", "", MirrorFile); + new pkgAcqFile(&Fetcher, fetch, "", 0, "", "", "", MirrorFile); bool res = (Fetcher.Run() == pkgAcquire::Continue); - cerr << "fetch-result: " << res << endl; if(res) HasMirrorFile = true; @@ -61,7 +82,9 @@ bool MirrorMethod::SelectMirror() { ifstream in(MirrorFile.c_str()); getline(in, Mirror); - cerr << "Mirror: " << Mirror << endl; + if(Debug) + cerr << "Using mirror: " << Mirror << endl; + return true; } // MirrorMethod::Fetch - Fetch an item /*{{{*/ @@ -77,21 +100,42 @@ bool MirrorMethod::Fetch(FetchItem *Itm) SelectMirror(); } - // change the items in the queue - Itm->Uri.replace(0,BaseUri.size()+_config->Find("Acquire::Mirror::MagicMarker","///").size()+2/*len("mirror")-len("http")*/,Mirror); - cerr << "new Fetch-uri: " << Itm->Uri << endl; + if(Queue->Uri.find("mirror://") != string::npos) + Queue->Uri.replace(0,BaseUri.size(),Mirror); - // FIXME: fetch it with! - + // now run the real fetcher + return HttpMethod::Fetch(Itm); }; +void MirrorMethod::Fail(string Err,bool Transient) +{ + if(Queue->Uri.find("http://") != string::npos) + Queue->Uri.replace(0,Mirror.size(), BaseUri); + pkgAcqMethod::Fail(Err, Transient); +} + +void MirrorMethod::URIStart(FetchResult &Res) +{ + if(Queue->Uri.find("http://") != string::npos) + Queue->Uri.replace(0,Mirror.size(), BaseUri); + pkgAcqMethod::URIStart(Res); +} + +void MirrorMethod::URIDone(FetchResult &Res,FetchResult *Alt) +{ + if(Queue->Uri.find("http://") != string::npos) + Queue->Uri.replace(0,Mirror.size(), BaseUri); + pkgAcqMethod::URIDone(Res, Alt); +} + + int main() { setlocale(LC_ALL, ""); MirrorMethod Mth; - return Mth.Run(); + return Mth.Loop(); } diff --git a/methods/mirror.h b/methods/mirror.h index ca3428830..91cf8c64f 100644 --- a/methods/mirror.h +++ b/methods/mirror.h @@ -20,17 +20,24 @@ using std::endl; #include "http.h" -class MirrorMethod : public pkgAcqMethod +class MirrorMethod : public HttpMethod { FetchResult Res; - string Mirror; - string BaseUri; - string MirrorFile; + string BaseUri; // the original mirror://... url + string Mirror; // the selected mirror uri (http://...) + string MirrorFile; // bool HasMirrorFile; + bool Debug; + protected: bool GetMirrorFile(string uri); bool SelectMirror(); + virtual void Fail(string Why, bool Transient = false); + virtual void URIStart(FetchResult &Res); + virtual void URIDone(FetchResult &Res,FetchResult *Alt = 0); + virtual bool Configuration(string Message); + public: MirrorMethod(); virtual bool Fetch(FetchItem *Itm); -- cgit v1.2.3 From 86c17f0a4bd3c0e3dde5bb58b3df9c41e5a88763 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 29 Nov 2006 23:09:26 +0100 Subject: * todo added --- methods/mirror.cc | 8 ++++++++ methods/mirror.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/methods/mirror.cc b/methods/mirror.cc index c4d911a3c..c49764044 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -26,6 +26,14 @@ using namespace std; /*}}}*/ +/* + * TODO: + * - support keeping the mirror file around (evil listclearer strikes again) + * - better method to download than having a pkgAcquire interface here + * - testing :) + * + */ + MirrorMethod::MirrorMethod() : HttpMethod(), HasMirrorFile(false) { diff --git a/methods/mirror.h b/methods/mirror.h index 91cf8c64f..a47b8fbf1 100644 --- a/methods/mirror.h +++ b/methods/mirror.h @@ -23,6 +23,7 @@ using std::endl; class MirrorMethod : public HttpMethod { FetchResult Res; + // we simply transform between BaseUri and Mirror string BaseUri; // the original mirror://... url string Mirror; // the selected mirror uri (http://...) string MirrorFile; // @@ -33,6 +34,8 @@ class MirrorMethod : public HttpMethod protected: bool GetMirrorFile(string uri); bool SelectMirror(); + + // we need to overwrite those to transform the url back virtual void Fail(string Why, bool Transient = false); virtual void URIStart(FetchResult &Res); virtual void URIDone(FetchResult &Res,FetchResult *Alt = 0); -- cgit v1.2.3 From 3ed91a17d21d0d456a12accc507b82e1c0f1a697 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 29 Nov 2006 23:21:47 +0100 Subject: * more todo items --- methods/mirror.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/methods/mirror.cc b/methods/mirror.cc index c49764044..1911d6115 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -28,10 +28,11 @@ using namespace std; /* * TODO: - * - support keeping the mirror file around (evil listclearer strikes again) * - better method to download than having a pkgAcquire interface here + * - support keeping the mirror file around (evil listclearer strikes again) + * -> /var/lib/apt/mirrors dir? how to cleanup? by time? + * - provide some TTL time until the mirror file is get again (1h? 6h?) * - testing :) - * */ MirrorMethod::MirrorMethod() -- cgit v1.2.3 From ef1e6d8822bb34527bba5d2318b5768013efd010 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 30 Nov 2006 11:06:09 +0100 Subject: * methods/mirror.cc: - check the complette queue on Fetch() for urls to transform --- methods/mirror.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/methods/mirror.cc b/methods/mirror.cc index 1911d6115..4de981522 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -32,6 +32,7 @@ using namespace std; * - support keeping the mirror file around (evil listclearer strikes again) * -> /var/lib/apt/mirrors dir? how to cleanup? by time? * - provide some TTL time until the mirror file is get again (1h? 6h?) + * - deal with runing as non-root (we can't write to the lists dir then) * - testing :) */ @@ -109,8 +110,11 @@ bool MirrorMethod::Fetch(FetchItem *Itm) SelectMirror(); } - if(Queue->Uri.find("mirror://") != string::npos) - Queue->Uri.replace(0,BaseUri.size(),Mirror); + for (FetchItem *I = Queue; I != 0; I = I->Next) + { + if(I->Uri.find("mirror://") != string::npos) + I->Uri.replace(0,BaseUri.size(),Mirror); + } // now run the real fetcher return HttpMethod::Fetch(Itm); -- cgit v1.2.3 From d731f9c574138a9cb31c586a8f1e7d7181a44456 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 8 Jan 2007 11:19:32 +0100 Subject: * apt-pkg/init.cc: - added Dir::State::Mirrors * doc/examples/configure-index: - added Acquire::mirror::RefreshInterval * methods/mirror.{cc,h}: - download the mirror file into Dir::State::Mirrors - added RefreshInterval option to not ask for the mirror file too often --- apt-pkg/init.cc | 1 + debian/apt.dirs | 1 + doc/examples/configure-index | 7 +++++- methods/mirror.cc | 56 ++++++++++++++++++++++++++++++++++++-------- methods/mirror.h | 1 + po/apt-all.pot | 4 ++-- 6 files changed, 57 insertions(+), 13 deletions(-) diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc index b47378d4a..fe085a75e 100644 --- a/apt-pkg/init.cc +++ b/apt-pkg/init.cc @@ -54,6 +54,7 @@ bool pkgInitConfig(Configuration &Cnf) Cnf.Set("Dir::State::lists","lists/"); Cnf.Set("Dir::State::cdroms","cdroms.list"); + Cnf.Set("Dir::State::mirrors","mirrors/"); // Cache Cnf.Set("Dir::Cache","var/cache/apt/"); diff --git a/debian/apt.dirs b/debian/apt.dirs index e1cb738fa..b81878baa 100644 --- a/debian/apt.dirs +++ b/debian/apt.dirs @@ -5,5 +5,6 @@ etc/apt etc/apt/sources.list.d var/cache/apt/archives/partial var/lib/apt/lists/partial +var/lib/apt/mirrors/partial var/lib/apt/periodic usr/share/bug/apt diff --git a/doc/examples/configure-index b/doc/examples/configure-index index 0f0abc30c..cb20d767b 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -160,6 +160,11 @@ Acquire { Options {"--ignore-time-conflict";} // not very usefull on a normal system }; + + mirror + { + RefreshInterval "360"; // refresh interval in minutes + }; }; // Directory layout @@ -258,9 +263,9 @@ Debug Acquire::Ftp "false"; // Show ftp command traffic Acquire::Http "false"; // Show http command traffic Acquire::gpgv "false"; // Show the gpgv traffic + Acquire::Mirror "false"; // Show debugging of the mirror method aptcdrom "false"; // Show found package files IdentCdrom "false"; - } /* Whatever you do, do not use this configuration file!! Take out ONLY diff --git a/methods/mirror.cc b/methods/mirror.cc index 4de981522..e70a40f55 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -18,6 +18,7 @@ #include #include #include +#include using namespace std; @@ -28,11 +29,16 @@ using namespace std; /* * TODO: + * - send expected checksum to the mirror method so that + some checking/falling back can be done here already + * - keep the mirror file around in /var/lib/apt/mirrors + * can't be put into lists/ because of the listclearer + * cleanup by time (mtime relative to the other mtimes) + * - use a TTL time the mirror file is fetched again (6h?) + * - 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 - * - support keeping the mirror file around (evil listclearer strikes again) - * -> /var/lib/apt/mirrors dir? how to cleanup? by time? - * - provide some TTL time until the mirror file is get again (1h? 6h?) - * - deal with runing as non-root (we can't write to the lists dir then) + * - magicmarker is (a bit) evil * - testing :) */ @@ -60,6 +66,12 @@ bool MirrorMethod::Configuration(string Message) } /*}}}*/ +// clean the mirrors dir based on ttl information +bool MirrorMethod::Clean(string dir) +{ + +} + bool MirrorMethod::GetMirrorFile(string uri) { @@ -69,7 +81,7 @@ bool MirrorMethod::GetMirrorFile(string uri) string fetch = BaseUri; fetch.replace(0,strlen("mirror://"),"http://"); - MirrorFile = _config->FindDir("Dir::State::lists") + URItoFileName(BaseUri); + MirrorFile = _config->FindDir("Dir::State::mirrors") + URItoFileName(BaseUri); if(Debug) { @@ -77,19 +89,43 @@ bool MirrorMethod::GetMirrorFile(string uri) cerr << "mirror-file: " << MirrorFile << endl; } - // FIXME: fetch it with curl + // check the file, if it is not older than RefreshInterval just use it + // otherwise try to get a new one + if(FileExists(MirrorFile)) + { + struct stat buf; + time_t t,now,refresh; + if(stat(MirrorFile.c_str(), &buf) != 0) + return false; + t = std::max(buf.st_mtime, buf.st_ctime); + now = time(NULL); + refresh = 60*_config->FindI("Acquire::Mirror::RefreshInterval",360); + if(t + refresh > now) + { + if(Debug) + clog << "Mirror file is in RefreshInterval" << endl; + HasMirrorFile = true; + return true; + } + if(Debug) + clog << "Mirror file " << MirrorFile << " older than " << refresh << ", re-download it" << endl; + } + + // not that great to use pkgAcquire here, but we do not have + // any other way right now pkgAcquire Fetcher; new pkgAcqFile(&Fetcher, fetch, "", 0, "", "", "", MirrorFile); bool res = (Fetcher.Run() == pkgAcquire::Continue); - - if(res) + if(res) HasMirrorFile = true; Fetcher.Shutdown(); - return true; + return res; } bool MirrorMethod::SelectMirror() { + // FIXME: make the mirror selection more clever, do not + // just use the first one! ifstream in(MirrorFile.c_str()); getline(in, Mirror); if(Debug) @@ -103,7 +139,7 @@ bool MirrorMethod::SelectMirror() depth. */ bool MirrorMethod::Fetch(FetchItem *Itm) { - // get mirror information + // select mirror only once per session if(!HasMirrorFile) { GetMirrorFile(Itm->Uri); diff --git a/methods/mirror.h b/methods/mirror.h index a47b8fbf1..798f5a9b5 100644 --- a/methods/mirror.h +++ b/methods/mirror.h @@ -34,6 +34,7 @@ class MirrorMethod : public HttpMethod protected: bool GetMirrorFile(string uri); bool SelectMirror(); + bool Clean(string dir); // we need to overwrite those to transform the url back virtual void Fail(string Why, bool Transient = false); diff --git a/po/apt-all.pot b/po/apt-all.pot index b3da2ba9a..42c43fe8d 100644 --- a/po/apt-all.pot +++ b/po/apt-all.pot @@ -2238,12 +2238,12 @@ msgstr "" msgid "Please insert the disc labeled: '%s' in the drive '%s' and press enter." msgstr "" -#: apt-pkg/init.cc:120 +#: apt-pkg/init.cc:121 #, c-format msgid "Packaging system '%s' is not supported" msgstr "" -#: apt-pkg/init.cc:136 +#: apt-pkg/init.cc:137 msgid "Unable to determine a suitable packaging system type" msgstr "" -- cgit v1.2.3 From 70288656715d2fe4c2c33598124ae48f7bca9cdf Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 8 Jan 2007 11:38:55 +0100 Subject: * methods/mirror.cc: - implemented simple Clean() implementation based on the time of the last access for a mirror file --- doc/examples/configure-index | 2 ++ methods/mirror.cc | 55 +++++++++++++++++++++++++++++++++++++++++--- po/apt-all.pot | 3 ++- 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/doc/examples/configure-index b/doc/examples/configure-index index cb20d767b..81bb6b3b0 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -164,6 +164,8 @@ Acquire mirror { RefreshInterval "360"; // refresh interval in minutes + MaxAge "90"; // max age for a mirror file in days before + // it gets deleted }; }; diff --git a/methods/mirror.cc b/methods/mirror.cc index e70a40f55..425a2f7f5 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -19,12 +19,14 @@ #include #include #include +#include +#include using namespace std; #include "mirror.h" #include "http.h" - +#include "apti18n.h" /*}}}*/ /* @@ -67,9 +69,54 @@ bool MirrorMethod::Configuration(string Message) /*}}}*/ // clean the mirrors dir based on ttl information -bool MirrorMethod::Clean(string dir) +bool MirrorMethod::Clean(string Dir) { + // FIXME: it would better to have a global idea of the mirrors + // in the sources.list and use this instead of this time + // based approach. currently apt does not support this :/ + + DIR *D = opendir(Dir.c_str()); + if (D == 0) + return _error->Errno("opendir",_("Unable to read %s"),Dir.c_str()); + + string StartDir = SafeGetCWD(); + if (chdir(Dir.c_str()) != 0) + { + closedir(D); + return _error->Errno("chdir",_("Unable to change to %s"),Dir.c_str()); + } + + for (struct dirent *Dir = readdir(D); Dir != 0; Dir = readdir(D)) + { + // Skip some files.. + if (strcmp(Dir->d_name,"lock") == 0 || + strcmp(Dir->d_name,"partial") == 0 || + strcmp(Dir->d_name,".") == 0 || + strcmp(Dir->d_name,"..") == 0) + continue; + + // Del everything not touched for MaxAge days + time_t t,now,max; + struct stat buf; + if(stat(Dir->d_name, &buf) != 0) + { + cerr << "Can't stat '" << Dir->d_name << "'" << endl; + continue; + } + t = std::max(buf.st_mtime, buf.st_ctime); + now = time(NULL); + max = 24*60*60*_config->FindI("Acquire::Mirror::MaxAge",90); + if(t + max < now) + { + if(Debug) + clog << "Mirror file is older than MaxAge days, deleting" << endl; + unlink(Dir->d_name); + } + }; + chdir(StartDir.c_str()); + closedir(D); + return true; } @@ -81,6 +128,7 @@ bool MirrorMethod::GetMirrorFile(string uri) string fetch = BaseUri; fetch.replace(0,strlen("mirror://"),"http://"); + // get new file MirrorFile = _config->FindDir("Dir::State::mirrors") + URItoFileName(BaseUri); if(Debug) @@ -108,7 +156,7 @@ bool MirrorMethod::GetMirrorFile(string uri) return true; } if(Debug) - clog << "Mirror file " << MirrorFile << " older than " << refresh << ", re-download it" << endl; + clog << "Mirror file " << MirrorFile << " older than " << refresh << "min, re-download it" << endl; } // not that great to use pkgAcquire here, but we do not have @@ -142,6 +190,7 @@ bool MirrorMethod::Fetch(FetchItem *Itm) // select mirror only once per session if(!HasMirrorFile) { + Clean(_config->FindDir("Dir::State::mirrors")); GetMirrorFile(Itm->Uri); SelectMirror(); } diff --git a/po/apt-all.pot b/po/apt-all.pot index 42c43fe8d..d1ce72503 100644 --- a/po/apt-all.pot +++ b/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 +#: apt-pkg/acquire.cc:421 apt-pkg/clean.cc:38 methods/mirror.cc:76 #, c-format msgid "Unable to read %s" msgstr "" @@ -1956,6 +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:82 #, c-format msgid "Unable to change to %s" msgstr "" -- cgit v1.2.3 From 0c312e0ed24fed69412c181634dd4515e9b1d46f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 8 Jan 2007 12:10:05 +0100 Subject: * implemented proper mirror list cleanup --- methods/mirror.cc | 39 +++++++++++++++++++++------------------ po/apt-all.pot | 4 ++-- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/methods/mirror.cc b/methods/mirror.cc index 425a2f7f5..00f7b7807 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -71,9 +72,14 @@ bool MirrorMethod::Configuration(string Message) // clean the mirrors dir based on ttl information bool MirrorMethod::Clean(string Dir) { - // FIXME: it would better to have a global idea of the mirrors - // in the sources.list and use this instead of this time - // based approach. currently apt does not support this :/ + vector::const_iterator I; + + if(Debug) + clog << "MirrorMethod::Clean(): " << Dir << endl; + + // read sources.list + pkgSourceList list; + list.ReadMainList(); DIR *D = opendir(Dir.c_str()); if (D == 0) @@ -94,24 +100,21 @@ bool MirrorMethod::Clean(string Dir) strcmp(Dir->d_name,".") == 0 || strcmp(Dir->d_name,"..") == 0) continue; - - // Del everything not touched for MaxAge days - time_t t,now,max; - struct stat buf; - if(stat(Dir->d_name, &buf) != 0) + + // see if we have that uri + for(I=list.begin(); I != list.end(); I++) { - cerr << "Can't stat '" << Dir->d_name << "'" << endl; - continue; + string uri = (*I)->GetURI(); + if(uri.substr(0,strlen("mirror://")) != string("mirror://")) + continue; + string Marker = _config->Find("Acquire::Mirror::MagicMarker","///"); + string BaseUri = uri.substr(0,uri.find(Marker)); + if (URItoFileName(BaseUri) == Dir->d_name) + break; } - t = std::max(buf.st_mtime, buf.st_ctime); - now = time(NULL); - max = 24*60*60*_config->FindI("Acquire::Mirror::MaxAge",90); - if(t + max < now) - { - if(Debug) - clog << "Mirror file is older than MaxAge days, deleting" << endl; + // nothing found, nuke it + if (I == list.end()) unlink(Dir->d_name); - } }; chdir(StartDir.c_str()); diff --git a/po/apt-all.pot b/po/apt-all.pot index d1ce72503..52fadb81c 100644 --- a/po/apt-all.pot +++ b/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:76 +#: apt-pkg/acquire.cc:421 apt-pkg/clean.cc:38 methods/mirror.cc:86 #, 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:82 +#: methods/mirror.cc:92 #, c-format msgid "Unable to change to %s" msgstr "" -- cgit v1.2.3 From 933833c51fbfe3dca3f3a3073d441e5856462605 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 8 Jan 2007 13:07:22 +0100 Subject: * methods/mirror.cc: - updated the TODO --- methods/mirror.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/methods/mirror.cc b/methods/mirror.cc index 00f7b7807..f08b324ec 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -34,14 +34,18 @@ using namespace std; * TODO: * - send expected checksum to the mirror method so that some checking/falling back can be done here already - * - keep the mirror file around in /var/lib/apt/mirrors - * can't be put into lists/ because of the listclearer - * cleanup by time (mtime relative to the other mtimes) - * - use a TTL time the mirror file is fetched again (6h?) + use pkgAcquire::Custom600Header() for this? what about gpgv + failures? + #OR# + * - implement it at the pkgAcquire::Item::Failed() level but then + we need to send back what uri exactly was failing + * - 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 - * - magicmarker is (a bit) evil + * - magicmarker is (a bit) evil, maybe just use a similar approach as in + clean and read the sources.list and use the GetURI() method to find + the prefix? * - testing :) */ -- cgit v1.2.3 From cae9cdcefc34eba6d023cb30cbbdb9bbf909b8fe Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 17 Jan 2007 16:35:56 +0100 Subject: * basic error reporting from apt in place now (ReportMirrorFailures()) --- apt-pkg/acquire-item.cc | 10 +++++++++- apt-pkg/acquire-item.h | 1 + apt-pkg/acquire-method.cc | 1 + apt-pkg/acquire-method.h | 1 + methods/mirror.cc | 27 +++++++++++++++++++++------ methods/mirror.h | 1 + po/apt-all.pot | 16 ++++++++-------- 7 files changed, 42 insertions(+), 15 deletions(-) diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 8ec4ba2c0..7b2a89763 100644 --- a/apt-pkg/acquire-item.cc +++ b/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 /*{{{*/ // --------------------------------------------------------------------- diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h index da1bea801..c9cd75321 100644 --- a/apt-pkg/acquire-item.h +++ b/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, diff --git a/apt-pkg/acquire-method.cc b/apt-pkg/acquire-method.cc index 41b832f3b..638797657 100644 --- a/apt-pkg/acquire-method.cc +++ b/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); diff --git a/apt-pkg/acquire-method.h b/apt-pkg/acquire-method.h index e0e7c1d09..9e908d32c 100644 --- a/apt-pkg/acquire-method.h +++ b/apt-pkg/acquire-method.h @@ -33,6 +33,7 @@ class pkgAcqMethod string DestFile; time_t LastModified; bool IndexFile; + string ExpectedMD5; }; struct FetchResult diff --git a/methods/mirror.cc b/methods/mirror.cc index f08b324ec..428726a3d 100644 --- a/methods/mirror.cc +++ b/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() { diff --git a/methods/mirror.h b/methods/mirror.h index 798f5a9b5..3ff9e1a96 100644 --- a/methods/mirror.h +++ b/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); diff --git a/po/apt-all.pot b/po/apt-all.pot index 52fadb81c..aee5c09c8 100644 --- a/po/apt-all.pot +++ b/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 "" -- cgit v1.2.3 From 2769f0bcf6c1ac73e883f47857fa227de92f4525 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 17 Jan 2007 17:16:42 +0100 Subject: * mirror-failure.py: example mirror failure cgi * methods/mirror.cc: prepare for the failure submit --- methods/mirror.cc | 6 ++++++ mirror-failure.py | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 mirror-failure.py diff --git a/methods/mirror.cc b/methods/mirror.cc index 428726a3d..6621d47e2 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -247,6 +247,12 @@ void MirrorMethod::ReportMirrorFailure(string FailCode) << Queue->Uri << " FailCode: " << FailCode << std::endl; +#if 0 // FIXME: do not use system, make sure to properly encode + // URI/FailCode, do not hardcode the submit url + system("curl -d url=" + Queue->Uri + + " -d FailureCode=" + FailCode + + " http://localhost:8000/ &"); +#endif } int main() diff --git a/mirror-failure.py b/mirror-failure.py new file mode 100644 index 000000000..e7d2bbf54 --- /dev/null +++ b/mirror-failure.py @@ -0,0 +1,23 @@ +# File: cgihttpserver-example-1.py + +import CGIHTTPServer +import BaseHTTPServer + +class Handler(CGIHTTPServer.CGIHTTPRequestHandler): + #cgi_directories = ["/cgi"] + def do_POST(self): + print "do_POST" + #print self.command + #print self.path + #print self.headers + print self.client_address + data = self.rfile.read(int(self.headers["content-length"])) + print data + self.wfile.write("200 Ok\n"); + +PORT = 8000 + +httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler) +print "serving at port", PORT +httpd.serve_forever() + -- cgit v1.2.3 From b47081521b0df1f835a2111254fa1fcd77240a85 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 23 Jan 2007 18:43:42 +0100 Subject: * cmdline/report-mirror-failure - basic mirror failure script added --- cmdline/report-mirror-failure | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 cmdline/report-mirror-failure diff --git a/cmdline/report-mirror-failure b/cmdline/report-mirror-failure new file mode 100755 index 000000000..8301ed079 --- /dev/null +++ b/cmdline/report-mirror-failure @@ -0,0 +1,21 @@ +#!/usr/bin/python + +import sys +import urllib +import apt_pkg + +apt_pkg.init() +url = apt_pkg.Config.Find("Acquire::Mirror::ReportFailures", + "http://people.ubuntu.com:9000/mirror-failure") + #"http://localhost:9000/mirror-failure") +if not url: + sys.exit(0) + +data = {} +data['url'] = sys.argv[1] +data['error'] = sys.argv[2] +f = urllib.urlopen(url, urllib.urlencode(data)) +f.read() +f.close() + + -- cgit v1.2.3 From 362d29343e5d25248bcd84300aa1b18effe891e7 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 24 Jan 2007 14:42:17 +0100 Subject: make the mirror failures actually produce a error message --- cmdline/makefile | 6 ++++++ cmdline/report-mirror-failure | 21 -------------------- configure.in | 2 +- debian/changelog | 2 +- methods/mirror.cc | 46 ++++++++++++++++++++++++++++++++----------- po/apt-all.pot | 6 +++--- 6 files changed, 46 insertions(+), 37 deletions(-) delete mode 100755 cmdline/report-mirror-failure diff --git a/cmdline/makefile b/cmdline/makefile index 882a0e1b5..f07c7da3b 100644 --- a/cmdline/makefile +++ b/cmdline/makefile @@ -52,3 +52,9 @@ SOURCE=apt-key TO=$(BIN) TARGET=program include $(COPY_H) + +# The apt-key program +SOURCE=apt-report-mirror-failure +TO=$(LIB) +TARGET=program +include $(COPY_H) diff --git a/cmdline/report-mirror-failure b/cmdline/report-mirror-failure deleted file mode 100755 index 8301ed079..000000000 --- a/cmdline/report-mirror-failure +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/python - -import sys -import urllib -import apt_pkg - -apt_pkg.init() -url = apt_pkg.Config.Find("Acquire::Mirror::ReportFailures", - "http://people.ubuntu.com:9000/mirror-failure") - #"http://localhost:9000/mirror-failure") -if not url: - sys.exit(0) - -data = {} -data['url'] = sys.argv[1] -data['error'] = sys.argv[2] -f = urllib.urlopen(url, urllib.urlencode(data)) -f.read() -f.close() - - diff --git a/configure.in b/configure.in index 81f327c37..df452ba34 100644 --- a/configure.in +++ b/configure.in @@ -18,7 +18,7 @@ AC_CONFIG_AUX_DIR(buildlib) AC_CONFIG_HEADER(include/config.h:buildlib/config.h.in include/apti18n.h:buildlib/apti18n.h.in) dnl -- SET THIS TO THE RELEASE VERSION -- -AC_DEFINE_UNQUOTED(VERSION,"0.6.46.3") +AC_DEFINE_UNQUOTED(VERSION,"0.6.46.4") PACKAGE="apt" AC_DEFINE_UNQUOTED(PACKAGE,"$PACKAGE") AC_SUBST(PACKAGE) diff --git a/debian/changelog b/debian/changelog index 24e10dcd5..6c9ada3a5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,7 +2,7 @@ apt (0.6.46.4) unstable; urgency=low * add apt-secure.8 to "See also" section - -- + -- Michael Vogt Wed, 24 Jan 2007 14:34:15 +0100 apt (0.6.46.3) unstable; urgency=low diff --git a/methods/mirror.cc b/methods/mirror.cc index 6621d47e2..8f9b8ed34 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -30,13 +30,18 @@ using namespace std; #include "apti18n.h" /*}}}*/ -/* +/* Done: + * - works with http only + * - always picks the first mirror from the list + * - call out to problem reporting script + * - supports "deb mirror://host/path/to/mirror-list/// dist component" + * * TODO: - * - 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 + * what about gpgv failures? this should call-out to the problem reporting + script, but we need to know what mirror was used + * better standard format for errors to send back + * - implement failure reporting at the pkgAcquire::Item::Failed() level + but then 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] @@ -46,6 +51,7 @@ using namespace std; * - magicmarker is (a bit) evil, maybe just use a similar approach as in clean and read the sources.list and use the GetURI() method to find the prefix? + * support more than http * - testing :) */ @@ -243,16 +249,34 @@ void MirrorMethod::URIDone(FetchResult &Res,FetchResult *Alt) void MirrorMethod::ReportMirrorFailure(string FailCode) { // report that Queue->Uri failed +#if 0 std::cerr << "\nReportMirrorFailure: " << Queue->Uri << " FailCode: " << FailCode << std::endl; -#if 0 // FIXME: do not use system, make sure to properly encode - // URI/FailCode, do not hardcode the submit url - system("curl -d url=" + Queue->Uri + - " -d FailureCode=" + FailCode + - " http://localhost:8000/ &"); #endif + const char *Args[40]; + unsigned int i = 0; + string report = _config->Find("Methods::Mirror::ProblemReporting", + "/usr/lib/apt/report-mirror-failure"); + Args[i++] = report.c_str(); + Args[i++] = Queue->Uri.c_str(); + Args[i++] = FailCode.c_str(); + pid_t pid = ExecFork(); + if(pid < 0) + { + _error->Error("ReportMirrorFailure Fork failed"); + return; + } + else if(pid == 0) + { + execvp(report.c_str(), (char**)Args); + } + if(!ExecWait(pid, "report-mirror-failure")) + { + _error->Warning("Couldn't report problem to '%s'", + _config->Find("Acquire::Mirror::ReportFailures").c_str()); + } } int main() diff --git a/po/apt-all.pot b/po/apt-all.pot index aee5c09c8..dd140bd63 100644 --- a/po/apt-all.pot +++ b/po/apt-all.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2006-11-24 16:37+0100\n" +"POT-Creation-Date: 2007-01-24 12:51+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -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:92 +#: apt-pkg/acquire.cc:421 apt-pkg/clean.cc:38 methods/mirror.cc:96 #, 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:98 +#: methods/mirror.cc:102 #, c-format msgid "Unable to change to %s" msgstr "" -- cgit v1.2.3 From 36280399db0ae203d3f1ae4d44b946f31e9a38ce Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 1 Feb 2007 12:32:50 +0100 Subject: * commited the latest mirror failure detection code --- apt-pkg/acquire-item.cc | 51 +++++++++++++++++++++++++++++++-------- apt-pkg/acquire-item.h | 5 +++- apt-pkg/acquire-method.cc | 21 ++++++++++------ apt-pkg/acquire-method.h | 8 +++--- cmdline/apt-report-mirror-failure | 23 ++++++++++++++++++ methods/connect.cc | 17 ++++++------- methods/mirror.cc | 45 +++------------------------------- methods/mirror.h | 1 - po/apt-all.pot | 44 ++++++++++++++++----------------- 9 files changed, 120 insertions(+), 95 deletions(-) create mode 100755 cmdline/apt-report-mirror-failure diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 7b2a89763..61564c7aa 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -79,6 +79,10 @@ void pkgAcquire::Item::Failed(string Message,pkgAcquire::MethodConfig *Cnf) Status = StatError; Dequeue(); } + + // report mirror failure back to LP if we actually use a mirror + if(!UsedMirror.empty()) + ReportMirrorFailure(ErrorText); } /*}}}*/ // Acquire::Item::Start - Item has begun to download /*{{{*/ @@ -100,6 +104,7 @@ void pkgAcquire::Item::Done(string Message,unsigned long Size,string, { // We just downloaded something.. string FileName = LookupTag(Message,"Filename"); + UsedMirror = LookupTag(Message,"UsedMirror"); if (Complete == false && FileName == DestFile) { if (Owner->Log != 0) @@ -108,7 +113,6 @@ void pkgAcquire::Item::Done(string Message,unsigned long Size,string, if (FileSize == 0) FileSize= Size; - Status = StatDone; ErrorText = string(); Owner->Dequeue(this); @@ -131,6 +135,42 @@ void pkgAcquire::Item::Rename(string From,string To) } /*}}}*/ +void pkgAcquire::Item::ReportMirrorFailure(string FailCode) +{ + // report that Queue->Uri failed +#if 0 + std::cerr << "\nReportMirrorFailure: " + << UsedMirror + << " FailCode: " + << FailCode << std::endl; +#endif + const char *Args[40]; + unsigned int i = 0; + string report = _config->Find("Methods::Mirror::ProblemReporting", + "/usr/bin/apt-report-mirror-failure"); + if(!FileExists(report)) + return; + Args[i++] = report.c_str(); + Args[i++] = UsedMirror.c_str(); + Args[i++] = FailCode.c_str(); + pid_t pid = ExecFork(); + if(pid < 0) + { + _error->Error("ReportMirrorFailure Fork failed"); + return; + } + else if(pid == 0) + { + execvp(report.c_str(), (char**)Args); + } + if(!ExecWait(pid, "report-mirror-failure")) + { + _error->Warning("Couldn't report problem to '%s'", + _config->Find("Acquire::Mirror::ReportFailures").c_str()); + } +} + + // AcqIndex::AcqIndex - Constructor /*{{{*/ // --------------------------------------------------------------------- /* The package file is added to the queue and a second class is @@ -176,8 +216,6 @@ 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); } /*}}}*/ @@ -1016,13 +1054,6 @@ 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 /*{{{*/ // --------------------------------------------------------------------- diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h index c9cd75321..9949d0044 100644 --- a/apt-pkg/acquire-item.h +++ b/apt-pkg/acquire-item.h @@ -56,6 +56,7 @@ class pkgAcquire::Item unsigned long ID; bool Complete; bool Local; + string UsedMirror; // Number of queues we are inserted into unsigned int QueueCounter; @@ -78,6 +79,9 @@ class pkgAcquire::Item pkgAcquire *GetOwner() {return Owner;}; virtual bool IsTrusted() {return false;}; + // report mirror problems + void ReportMirrorFailure(string FailCode); + Item(pkgAcquire *Owner); virtual ~Item(); }; @@ -205,7 +209,6 @@ 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, diff --git a/apt-pkg/acquire-method.cc b/apt-pkg/acquire-method.cc index 638797657..13201d310 100644 --- a/apt-pkg/acquire-method.cc +++ b/apt-pkg/acquire-method.cc @@ -99,12 +99,11 @@ void pkgAcqMethod::Fail(string Err,bool Transient) } char S[1024]; + char *End = S; if (Queue != 0) { - snprintf(S,sizeof(S)-50,"400 URI Failure\nURI: %s\n" - "Message: %s %s\n",Queue->Uri.c_str(),Err.c_str(), - FailExtra.c_str()); - + End += snprintf(S,sizeof(S)-50,"400 URI Failure\nURI: %s\n" + "Message: %s %s\n",Queue->Uri.c_str(), Err.c_str(), IP.c_str()); // Dequeue FetchItem *Tmp = Queue; Queue = Queue->Next; @@ -113,10 +112,14 @@ void pkgAcqMethod::Fail(string Err,bool Transient) QueueBack = Queue; } else - snprintf(S,sizeof(S)-50,"400 URI Failure\nURI: \n" - "Message: %s %s\n",Err.c_str(), - FailExtra.c_str()); - + { + End += snprintf(S,sizeof(S)-50,"400 URI Failure\nURI: \n" + "Message: %s\n",Err.c_str()); + } + if(FailReason.empty() == false) + End += snprintf(End,sizeof(S)-50 - (End - S),"FailReason: %s\n",FailReason.c_str()); + if (UsedMirror.empty() == false) + End += snprintf(End,sizeof(S)-50 - (End - S),"UsedMirror: %s\n",UsedMirror.c_str()); // Set the transient flag if (Transient == true) strcat(S,"Transient-Failure: true\n\n"); @@ -182,6 +185,8 @@ void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt) End += snprintf(End,sizeof(S)-50 - (End - S),"MD5-Hash: %s\n",Res.MD5Sum.c_str()); if (Res.SHA1Sum.empty() == false) End += snprintf(End,sizeof(S)-50 - (End - S),"SHA1-Hash: %s\n",Res.SHA1Sum.c_str()); + if (UsedMirror.empty() == false) + End += snprintf(End,sizeof(S)-50 - (End - S),"UsedMirror: %s\n",UsedMirror.c_str()); if (Res.GPGVOutput.size() > 0) End += snprintf(End,sizeof(S)-50 - (End - S),"GPGVOutput:\n"); for (vector::iterator I = Res.GPGVOutput.begin(); diff --git a/apt-pkg/acquire-method.h b/apt-pkg/acquire-method.h index 9e908d32c..ee68c75f7 100644 --- a/apt-pkg/acquire-method.h +++ b/apt-pkg/acquire-method.h @@ -55,7 +55,9 @@ class pkgAcqMethod vector Messages; FetchItem *Queue; FetchItem *QueueBack; - string FailExtra; + string FailReason; + string UsedMirror; + string IP; // Handlers for messages virtual bool Configuration(string Message); @@ -72,7 +74,6 @@ class pkgAcqMethod virtual void Exit() {}; public: - enum CnfFlags {SingleInstance = (1<<0), Pipeline = (1<<1), SendConfig = (1<<2), LocalOnly = (1<<3), NeedsCleanup = (1<<4), @@ -82,7 +83,8 @@ class pkgAcqMethod void Status(const char *Format,...); int Run(bool Single = false); - inline void SetFailExtraMsg(string Msg) {FailExtra = Msg;}; + inline void SetFailReason(string Msg) {FailReason = Msg;}; + inline void SetIP(string aIP) {IP = aIP;}; pkgAcqMethod(const char *Ver,unsigned long Flags = 0); virtual ~pkgAcqMethod() {}; diff --git a/cmdline/apt-report-mirror-failure b/cmdline/apt-report-mirror-failure new file mode 100755 index 000000000..70b16cf4f --- /dev/null +++ b/cmdline/apt-report-mirror-failure @@ -0,0 +1,23 @@ +#!/usr/bin/python + +import sys +import urllib +import apt_pkg + +print "apt-report-mirror-failure" + +apt_pkg.init() +url = apt_pkg.Config.Find("Acquire::Mirror::ReportFailures", + "http://people.ubuntu.com:9000/mirror-failure") + #"http://localhost:9000/mirror-failure") +if not url: + sys.exit(0) + +data = {} +data['url'] = sys.argv[1] +data['error'] = sys.argv[2] +f = urllib.urlopen(url, urllib.urlencode(data)) +f.read() +f.close() + + diff --git a/methods/connect.cc b/methods/connect.cc index 8c2ac6d56..4e227c3fd 100644 --- a/methods/connect.cc +++ b/methods/connect.cc @@ -18,6 +18,7 @@ #include #include #include +#include // Internet stuff #include @@ -67,12 +68,10 @@ static bool DoConnect(struct addrinfo *Addr,string Host, wrong this will get tacked onto the end of the error message */ if (LastHostAddr->ai_next != 0) { - char Name2[NI_MAXHOST + NI_MAXSERV + 10]; - snprintf(Name2,sizeof(Name2),_("[IP: %s %s]"),Name,Service); - Owner->SetFailExtraMsg(string(Name2)); - } - else - Owner->SetFailExtraMsg(""); + std::stringstream ss; + ioprintf(ss, _("[IP: %s %s]"),Name,Service); + Owner->SetIP(ss.str()); + } // Get a socket if ((Fd = socket(Addr->ai_family,Addr->ai_socktype, @@ -89,7 +88,7 @@ static bool DoConnect(struct addrinfo *Addr,string Host, /* This implements a timeout for connect by opening the connection nonblocking */ if (WaitFd(Fd,true,TimeOut) == false) { - Owner->SetFailExtraMsg("\nFailReason: Timeout"); + Owner->SetFailReason("Timeout"); return _error->Error(_("Could not connect to %s:%s (%s), " "connection timed out"),Host.c_str(),Service,Name); } @@ -104,7 +103,7 @@ static bool DoConnect(struct addrinfo *Addr,string Host, { errno = Err; if(errno == ECONNREFUSED) - Owner->SetFailExtraMsg("\nFailReason: ConnectionRefused"); + Owner->SetFailReason("ConnectionRefused"); return _error->Errno("connect",_("Could not connect to %s:%s (%s)."),Host.c_str(), Service,Name); } @@ -169,7 +168,7 @@ bool Connect(string Host,int Port,const char *Service,int DefPort,int &Fd, if (Res == EAI_AGAIN) { - Owner->SetFailExtraMsg("\nFailReason: TmpResolveFailure"); + Owner->SetFailReason("TmpResolveFailure"); return _error->Error(_("Temporary failure resolving '%s'"), Host.c_str()); } diff --git a/methods/mirror.cc b/methods/mirror.cc index 8f9b8ed34..8ccfb8559 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -38,7 +38,7 @@ using namespace std; * * TODO: * what about gpgv failures? this should call-out to the problem reporting - script, but we need to know what mirror was used + script, but we need to know what mirror was used -> just run pkgAcquire::Item::ReportMirrorFailure() * better standard format for errors to send back * - implement failure reporting at the pkgAcquire::Item::Failed() level but then we need to send back what uri exactly was failing @@ -48,7 +48,7 @@ using namespace std; * - 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 - * - magicmarker is (a bit) evil, maybe just use a similar approach as in + * - magicmarker is evil, maybe just use a similar approach as in clean and read the sources.list and use the GetURI() method to find the prefix? * support more than http @@ -191,6 +191,8 @@ bool MirrorMethod::SelectMirror() getline(in, Mirror); if(Debug) cerr << "Using mirror: " << Mirror << endl; + + UsedMirror = Mirror; return true; } @@ -220,9 +222,6 @@ 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); @@ -237,47 +236,11 @@ 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 -#if 0 - std::cerr << "\nReportMirrorFailure: " - << Queue->Uri - << " FailCode: " - << FailCode << std::endl; -#endif - const char *Args[40]; - unsigned int i = 0; - string report = _config->Find("Methods::Mirror::ProblemReporting", - "/usr/lib/apt/report-mirror-failure"); - Args[i++] = report.c_str(); - Args[i++] = Queue->Uri.c_str(); - Args[i++] = FailCode.c_str(); - pid_t pid = ExecFork(); - if(pid < 0) - { - _error->Error("ReportMirrorFailure Fork failed"); - return; - } - else if(pid == 0) - { - execvp(report.c_str(), (char**)Args); - } - if(!ExecWait(pid, "report-mirror-failure")) - { - _error->Warning("Couldn't report problem to '%s'", - _config->Find("Acquire::Mirror::ReportFailures").c_str()); - } -} int main() { diff --git a/methods/mirror.h b/methods/mirror.h index 3ff9e1a96..798f5a9b5 100644 --- a/methods/mirror.h +++ b/methods/mirror.h @@ -35,7 +35,6 @@ 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); diff --git a/po/apt-all.pot b/po/apt-all.pot index dd140bd63..15b650fda 100644 --- a/po/apt-all.pot +++ b/po/apt-all.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2007-01-24 12:51+0100\n" +"POT-Creation-Date: 2007-01-24 17:20+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -950,7 +950,7 @@ msgstr "" msgid "Calculating upgrade... " msgstr "" -#: cmdline/apt-get.cc:1716 methods/ftp.cc:702 methods/connect.cc:101 +#: cmdline/apt-get.cc:1716 methods/ftp.cc:702 methods/connect.cc:100 msgid "Failed" msgstr "" @@ -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:96 +#: apt-pkg/acquire.cc:421 apt-pkg/clean.cc:38 methods/mirror.cc:99 #, c-format msgid "Unable to read %s" msgstr "" @@ -1648,59 +1648,59 @@ msgstr "" msgid "Unable to invoke " msgstr "" -#: methods/connect.cc:64 +#: methods/connect.cc:65 #, c-format msgid "Connecting to %s (%s)" msgstr "" -#: methods/connect.cc:71 +#: methods/connect.cc:72 #, c-format msgid "[IP: %s %s]" msgstr "" -#: methods/connect.cc:80 +#: methods/connect.cc:79 #, c-format msgid "Could not create a socket for %s (f=%u t=%u p=%u)" msgstr "" -#: methods/connect.cc:86 +#: methods/connect.cc:85 #, c-format msgid "Cannot initiate the connection to %s:%s (%s)." msgstr "" -#: methods/connect.cc:93 +#: methods/connect.cc:92 #, c-format msgid "Could not connect to %s:%s (%s), connection timed out" msgstr "" -#: methods/connect.cc:108 +#: methods/connect.cc:107 #, c-format msgid "Could not connect to %s:%s (%s)." msgstr "" #. We say this mainly because the pause here is for the #. ssh connection that is still going -#: methods/connect.cc:136 methods/rsh.cc:425 +#: methods/connect.cc:135 methods/rsh.cc:425 #, c-format msgid "Connecting to %s" msgstr "" -#: methods/connect.cc:167 +#: methods/connect.cc:166 #, c-format msgid "Could not resolve '%s'" msgstr "" -#: methods/connect.cc:173 +#: methods/connect.cc:172 #, c-format msgid "Temporary failure resolving '%s'" msgstr "" -#: methods/connect.cc:176 +#: methods/connect.cc:175 #, c-format msgid "Something wicked happened resolving '%s:%s' (%i)" msgstr "" -#: methods/connect.cc:223 +#: methods/connect.cc:222 #, c-format msgid "Unable to connect to %s %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:102 +#: methods/mirror.cc:105 #, c-format msgid "Unable to change to %s" msgstr "" @@ -2357,40 +2357,40 @@ msgstr "" msgid "IO Error saving source cache" msgstr "" -#: apt-pkg/acquire-item.cc:126 +#: apt-pkg/acquire-item.cc:128 #, c-format msgid "rename failed, %s (%s -> %s)." msgstr "" -#: apt-pkg/acquire-item.cc:237 apt-pkg/acquire-item.cc:946 +#: apt-pkg/acquire-item.cc:275 apt-pkg/acquire-item.cc:984 msgid "MD5Sum mismatch" msgstr "" -#: apt-pkg/acquire-item.cc:641 +#: apt-pkg/acquire-item.cc:679 msgid "There is no public key available for the following key IDs:\n" msgstr "" -#: apt-pkg/acquire-item.cc:754 +#: apt-pkg/acquire-item.cc:792 #, 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:813 +#: apt-pkg/acquire-item.cc:851 #, 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:849 +#: apt-pkg/acquire-item.cc:887 #, c-format msgid "" "The package index files are corrupted. No Filename: field for package %s." msgstr "" -#: apt-pkg/acquire-item.cc:936 +#: apt-pkg/acquire-item.cc:974 msgid "Size mismatch" msgstr "" -- cgit v1.2.3 From 361593e92a44255cc0ef98417e7457911716cab5 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 1 Feb 2007 13:02:47 +0100 Subject: * get the mirror failure stuff really working --- apt-pkg/acquire-item.cc | 8 ++++++-- cmdline/apt-report-mirror-failure | 4 ++-- po/apt-all.pot | 20 ++++++++++---------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 61564c7aa..0d3d6a083 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -63,6 +63,7 @@ void pkgAcquire::Item::Failed(string Message,pkgAcquire::MethodConfig *Cnf) { Status = StatIdle; ErrorText = LookupTag(Message,"Message"); + UsedMirror = LookupTag(Message,"UsedMirror"); if (QueueCounter <= 1) { /* This indicates that the file is not available right now but might @@ -153,6 +154,7 @@ void pkgAcquire::Item::ReportMirrorFailure(string FailCode) Args[i++] = report.c_str(); Args[i++] = UsedMirror.c_str(); Args[i++] = FailCode.c_str(); + Args[i++] = NULL; pid_t pid = ExecFork(); if(pid < 0) { @@ -161,12 +163,14 @@ void pkgAcquire::Item::ReportMirrorFailure(string FailCode) } else if(pid == 0) { - execvp(report.c_str(), (char**)Args); + execvp(Args[0], (char**)Args); + std::cerr << "Could not exec " << Args[0] << std::endl; + _exit(100); } if(!ExecWait(pid, "report-mirror-failure")) { _error->Warning("Couldn't report problem to '%s'", - _config->Find("Acquire::Mirror::ReportFailures").c_str()); + _config->Find("Methods::Mirror::ProblemReporting").c_str()); } } diff --git a/cmdline/apt-report-mirror-failure b/cmdline/apt-report-mirror-failure index 70b16cf4f..277b23e9a 100755 --- a/cmdline/apt-report-mirror-failure +++ b/cmdline/apt-report-mirror-failure @@ -4,8 +4,6 @@ import sys import urllib import apt_pkg -print "apt-report-mirror-failure" - apt_pkg.init() url = apt_pkg.Config.Find("Acquire::Mirror::ReportFailures", "http://people.ubuntu.com:9000/mirror-failure") @@ -13,6 +11,8 @@ url = apt_pkg.Config.Find("Acquire::Mirror::ReportFailures", if not url: sys.exit(0) +print "Reporting mirror failure to '%s'" % url + data = {} data['url'] = sys.argv[1] data['error'] = sys.argv[2] diff --git a/po/apt-all.pot b/po/apt-all.pot index 15b650fda..39759f265 100644 --- a/po/apt-all.pot +++ b/po/apt-all.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2007-01-24 17:20+0100\n" +"POT-Creation-Date: 2007-02-01 12:41+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -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:99 +#: apt-pkg/acquire.cc:421 apt-pkg/clean.cc:38 methods/mirror.cc:96 #, 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:105 +#: methods/mirror.cc:102 #, c-format msgid "Unable to change to %s" msgstr "" @@ -2357,40 +2357,40 @@ msgstr "" msgid "IO Error saving source cache" msgstr "" -#: apt-pkg/acquire-item.cc:128 +#: apt-pkg/acquire-item.cc:131 #, c-format msgid "rename failed, %s (%s -> %s)." msgstr "" -#: apt-pkg/acquire-item.cc:275 apt-pkg/acquire-item.cc:984 +#: apt-pkg/acquire-item.cc:279 apt-pkg/acquire-item.cc:988 msgid "MD5Sum mismatch" msgstr "" -#: apt-pkg/acquire-item.cc:679 +#: apt-pkg/acquire-item.cc:683 msgid "There is no public key available for the following key IDs:\n" msgstr "" -#: apt-pkg/acquire-item.cc:792 +#: apt-pkg/acquire-item.cc:796 #, 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:851 +#: apt-pkg/acquire-item.cc:855 #, 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:887 +#: apt-pkg/acquire-item.cc:891 #, c-format msgid "" "The package index files are corrupted. No Filename: field for package %s." msgstr "" -#: apt-pkg/acquire-item.cc:974 +#: apt-pkg/acquire-item.cc:978 msgid "Size mismatch" msgstr "" -- cgit v1.2.3 From 59271f62e4a291c8d96e1f6073203c395734b6ca Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 5 Feb 2007 17:52:28 +0100 Subject: * use pkgAcqMethod::FailReason() for consistent error reporting --- apt-pkg/acquire-item.cc | 10 +++++++--- methods/connect.cc | 1 + methods/http.cc | 3 +++ methods/mirror.cc | 12 +++--------- po/apt-all.pot | 34 +++++++++++++++++----------------- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 0d3d6a083..08a029ff4 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -82,8 +82,7 @@ void pkgAcquire::Item::Failed(string Message,pkgAcquire::MethodConfig *Cnf) } // report mirror failure back to LP if we actually use a mirror - if(!UsedMirror.empty()) - ReportMirrorFailure(ErrorText); + ReportMirrorFailure(ErrorText); } /*}}}*/ // Acquire::Item::Start - Item has begun to download /*{{{*/ @@ -138,10 +137,13 @@ void pkgAcquire::Item::Rename(string From,string To) void pkgAcquire::Item::ReportMirrorFailure(string FailCode) { - // report that Queue->Uri failed + // we only act if a mirror was used at all + if(UsedMirror.empty()) + return; #if 0 std::cerr << "\nReportMirrorFailure: " << UsedMirror + << " Uri: " << DescURI() << " FailCode: " << FailCode << std::endl; #endif @@ -278,6 +280,7 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string MD5, Status = StatAuthError; ErrorText = _("MD5Sum mismatch"); Rename(DestFile,DestFile + ".FAILED"); + ReportMirrorFailure("HashChecksumFailure"); return; } // Done, move it into position @@ -765,6 +768,7 @@ void pkgAcqMetaIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf) } // gpgv method failed + ReportMirrorFailure("GPGFailure"); _error->Warning("GPG error: %s: %s", Desc.Description.c_str(), LookupTag(Message,"Message").c_str()); diff --git a/methods/connect.cc b/methods/connect.cc index 4e227c3fd..145001fb3 100644 --- a/methods/connect.cc +++ b/methods/connect.cc @@ -163,6 +163,7 @@ bool Connect(string Host,int Port,const char *Service,int DefPort,int &Fd, DefPort = 0; continue; } + Owner->SetFailReason("ResolveFailure"); return _error->Error(_("Could not resolve '%s'"),Host.c_str()); } diff --git a/methods/http.cc b/methods/http.cc index deaa8d0c8..01ad14655 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -914,6 +914,9 @@ int HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv) failure */ if (Srv->Result < 200 || Srv->Result >= 300) { + char err[255]; + snprintf(err,sizeof(err)-1,"HttpError%i",Srv->Result); + SetFailReason(err); _error->Error("%u %s",Srv->Result,Srv->Code); if (Srv->HaveContent == true) return 4; diff --git a/methods/mirror.cc b/methods/mirror.cc index 8ccfb8559..b64879bec 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -31,20 +31,14 @@ using namespace std; /*}}}*/ /* Done: - * - works with http only + * - works with http (only!) * - always picks the first mirror from the list * - call out to problem reporting script * - supports "deb mirror://host/path/to/mirror-list/// dist component" + * - use pkgAcqMethod::FailReason() to have a string representation + * of the failure that is also send to LP * * TODO: - * what about gpgv failures? this should call-out to the problem reporting - script, but we need to know what mirror was used -> just run pkgAcquire::Item::ReportMirrorFailure() - * better standard format for errors to send back - * - implement failure reporting at the pkgAcquire::Item::Failed() level - but then 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 diff --git a/po/apt-all.pot b/po/apt-all.pot index 39759f265..f24f19ba7 100644 --- a/po/apt-all.pot +++ b/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:96 +#: apt-pkg/acquire.cc:421 apt-pkg/clean.cc:38 methods/mirror.cc:98 #, c-format msgid "Unable to read %s" msgstr "" @@ -1621,7 +1621,7 @@ msgstr "" msgid "Unable to accept connection" msgstr "" -#: methods/ftp.cc:864 methods/http.cc:957 methods/rsh.cc:303 +#: methods/ftp.cc:864 methods/http.cc:960 methods/rsh.cc:303 msgid "Problem hashing file" msgstr "" @@ -1685,22 +1685,22 @@ msgstr "" msgid "Connecting to %s" msgstr "" -#: methods/connect.cc:166 +#: methods/connect.cc:167 #, c-format msgid "Could not resolve '%s'" msgstr "" -#: methods/connect.cc:172 +#: methods/connect.cc:173 #, c-format msgid "Temporary failure resolving '%s'" msgstr "" -#: methods/connect.cc:175 +#: methods/connect.cc:176 #, c-format msgid "Something wicked happened resolving '%s:%s' (%i)" msgstr "" -#: methods/connect.cc:222 +#: methods/connect.cc:223 #, c-format msgid "Unable to connect to %s %s:" msgstr "" @@ -1813,15 +1813,15 @@ msgstr "" msgid "Error reading from server" msgstr "" -#: methods/http.cc:1106 +#: methods/http.cc:1109 msgid "Bad header data" msgstr "" -#: methods/http.cc:1123 +#: methods/http.cc:1126 msgid "Connection failed" msgstr "" -#: methods/http.cc:1214 +#: methods/http.cc:1217 msgid "Internal error" 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:102 +#: methods/mirror.cc:104 #, c-format msgid "Unable to change to %s" msgstr "" @@ -2357,40 +2357,40 @@ msgstr "" msgid "IO Error saving source cache" msgstr "" -#: apt-pkg/acquire-item.cc:131 +#: apt-pkg/acquire-item.cc:130 #, c-format msgid "rename failed, %s (%s -> %s)." msgstr "" -#: apt-pkg/acquire-item.cc:279 apt-pkg/acquire-item.cc:988 +#: apt-pkg/acquire-item.cc:281 apt-pkg/acquire-item.cc:992 msgid "MD5Sum mismatch" msgstr "" -#: apt-pkg/acquire-item.cc:683 +#: apt-pkg/acquire-item.cc:686 msgid "There is no public key available for the following key IDs:\n" msgstr "" -#: apt-pkg/acquire-item.cc:796 +#: apt-pkg/acquire-item.cc:800 #, 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:855 +#: apt-pkg/acquire-item.cc:859 #, 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:891 +#: apt-pkg/acquire-item.cc:895 #, c-format msgid "" "The package index files are corrupted. No Filename: field for package %s." msgstr "" -#: apt-pkg/acquire-item.cc:978 +#: apt-pkg/acquire-item.cc:982 msgid "Size mismatch" msgstr "" -- cgit v1.2.3 From 066b53e95ba224f81d078e7d8df3002275f8a092 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 5 Feb 2007 18:46:45 +0100 Subject: * get rid of magic mirror --- methods/mirror.cc | 62 +++++++++++++++++++++++++++++++++++++++++-------------- po/apt-all.pot | 4 ++-- 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/methods/mirror.cc b/methods/mirror.cc index b64879bec..ff91130b8 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -42,22 +42,13 @@ using namespace std; * - 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 - * - magicmarker is evil, maybe just use a similar approach as in - clean and read the sources.list and use the GetURI() method to find - the prefix? - * support more than http + * - support more than http * - testing :) */ MirrorMethod::MirrorMethod() : HttpMethod(), HasMirrorFile(false) { -#if 0 - HasMirrorFile=true; - BaseUri="mirror://people.ubuntu.com/~mvo/mirror/mirrors"; - MirrorFile="/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_mirror_mirrors"; - Mirror="http://de.archive.ubuntu.com/ubuntu/"; -#endif }; // HttpMethod::Configuration - Handle a configuration message /*{{{*/ @@ -111,8 +102,7 @@ bool MirrorMethod::Clean(string Dir) string uri = (*I)->GetURI(); if(uri.substr(0,strlen("mirror://")) != string("mirror://")) continue; - string Marker = _config->Find("Acquire::Mirror::MagicMarker","///"); - string BaseUri = uri.substr(0,uri.find(Marker)); + string BaseUri = uri.substr(0,uri.size()-1); if (URItoFileName(BaseUri) == Dir->d_name) break; } @@ -127,11 +117,51 @@ bool MirrorMethod::Clean(string Dir) } -bool MirrorMethod::GetMirrorFile(string uri) +bool MirrorMethod::GetMirrorFile(string mirror_uri_str) { - string Marker = _config->Find("Acquire::Mirror::MagicMarker","///"); - BaseUri = uri.substr(0,uri.find(Marker)); - + /* + - a mirror_uri_str looks like this: + mirror://people.ubuntu.com/~mvo/apt/mirror/mirrors/dists/feisty/Release.gpg + + - the matching source.list entry + deb mirror://people.ubuntu.com/~mvo/apt/mirror/mirrors feisty main + + - we actually want to go after: + http://people.ubuntu.com/~mvo/apt/mirror/mirrors + + And we need to save the BaseUri for later: + - mirror://people.ubuntu.com/~mvo/apt/mirror/mirrors + + FIXME: what if we have two similar prefixes? + mirror://people.ubuntu.com/~mvo/mirror + mirror://people.ubuntu.com/~mvo/mirror2 + then mirror_uri_str looks like: + mirror://people.ubuntu.com/~mvo/apt/mirror/dists/feisty/Release.gpg + mirror://people.ubuntu.com/~mvo/apt/mirror2/dists/feisty/Release.gpg + we search sources.list and find: + mirror://people.ubuntu.com/~mvo/apt/mirror + in both cases! So we need to apply some domain knowledge here :( and + check for /dists/ or /Release.gpg as suffixes + */ + std::cerr << "GetMirrorFile: " << mirror_uri_str << std::endl; + + // read sources.list and find match + vector::const_iterator I; + pkgSourceList list; + list.ReadMainList(); + for(I=list.begin(); I != list.end(); I++) + { + string uristr = (*I)->GetURI(); + std::cerr << "Checking: " << uristr << std::endl; + if(uristr.substr(0,strlen("mirror://")) != string("mirror://")) + continue; + // find matching uri in sources.list + if(mirror_uri_str.substr(0,uristr.size()) == uristr) + { + std::cerr << "found BaseURI: " << uristr << std::endl; + BaseUri = uristr.substr(0,uristr.size()-1); + } + } string fetch = BaseUri; fetch.replace(0,strlen("mirror://"),"http://"); diff --git a/po/apt-all.pot b/po/apt-all.pot index f24f19ba7..8fa68d296 100644 --- a/po/apt-all.pot +++ b/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:98 +#: apt-pkg/acquire.cc:421 apt-pkg/clean.cc:38 methods/mirror.cc:90 #, 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:104 +#: methods/mirror.cc:96 #, c-format msgid "Unable to change to %s" msgstr "" -- cgit v1.2.3 From f0b509cdb44cb5e79e9c5ddd7ebec46965138534 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 5 Feb 2007 19:06:42 +0100 Subject: * apt-pkg/acquire-item.cc: - use FailReason in pkgAcquire::Item::Failed when available * methods/mirror.cc: - move some debug output into if(Debug) --- apt-pkg/acquire-item.cc | 7 ++++++- cmdline/apt-report-mirror-failure | 5 +++-- methods/mirror.cc | 9 ++++++--- po/apt-all.pot | 18 +++++++++--------- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 08a029ff4..14610d6e9 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -82,7 +82,11 @@ void pkgAcquire::Item::Failed(string Message,pkgAcquire::MethodConfig *Cnf) } // report mirror failure back to LP if we actually use a mirror - ReportMirrorFailure(ErrorText); + string FailReason = LookupTag(Message, "FailReason"); + if(FailReason.size() != 0) + ReportMirrorFailure(FailReason); + else + ReportMirrorFailure(ErrorText); } /*}}}*/ // Acquire::Item::Start - Item has begun to download /*{{{*/ @@ -155,6 +159,7 @@ void pkgAcquire::Item::ReportMirrorFailure(string FailCode) return; Args[i++] = report.c_str(); Args[i++] = UsedMirror.c_str(); + Args[i++] = DescURI().c_str(); Args[i++] = FailCode.c_str(); Args[i++] = NULL; pid_t pid = ExecFork(); diff --git a/cmdline/apt-report-mirror-failure b/cmdline/apt-report-mirror-failure index 277b23e9a..fb43f0e74 100755 --- a/cmdline/apt-report-mirror-failure +++ b/cmdline/apt-report-mirror-failure @@ -14,8 +14,9 @@ if not url: print "Reporting mirror failure to '%s'" % url data = {} -data['url'] = sys.argv[1] -data['error'] = sys.argv[2] +data['mirror'] = sys.argv[1] +data['failurl'] = sys.argv[2] +data['error'] = sys.argv[3] f = urllib.urlopen(url, urllib.urlencode(data)) f.read() f.close() diff --git a/methods/mirror.cc b/methods/mirror.cc index ff91130b8..c5c0c7461 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -143,7 +143,8 @@ bool MirrorMethod::GetMirrorFile(string mirror_uri_str) in both cases! So we need to apply some domain knowledge here :( and check for /dists/ or /Release.gpg as suffixes */ - std::cerr << "GetMirrorFile: " << mirror_uri_str << std::endl; + if(Debug) + std::cerr << "GetMirrorFile: " << mirror_uri_str << std::endl; // read sources.list and find match vector::const_iterator I; @@ -152,13 +153,15 @@ bool MirrorMethod::GetMirrorFile(string mirror_uri_str) for(I=list.begin(); I != list.end(); I++) { string uristr = (*I)->GetURI(); - std::cerr << "Checking: " << uristr << std::endl; + if(Debug) + std::cerr << "Checking: " << uristr << std::endl; if(uristr.substr(0,strlen("mirror://")) != string("mirror://")) continue; // find matching uri in sources.list if(mirror_uri_str.substr(0,uristr.size()) == uristr) { - std::cerr << "found BaseURI: " << uristr << std::endl; + if(Debug) + std::cerr << "found BaseURI: " << uristr << std::endl; BaseUri = uristr.substr(0,uristr.size()-1); } } diff --git a/po/apt-all.pot b/po/apt-all.pot index 8fa68d296..2355eee20 100644 --- a/po/apt-all.pot +++ b/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:90 +#: apt-pkg/acquire.cc:421 apt-pkg/clean.cc:38 methods/mirror.cc:81 #, 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:96 +#: methods/mirror.cc:87 #, c-format msgid "Unable to change to %s" msgstr "" @@ -2357,40 +2357,40 @@ msgstr "" msgid "IO Error saving source cache" msgstr "" -#: apt-pkg/acquire-item.cc:130 +#: apt-pkg/acquire-item.cc:134 #, c-format msgid "rename failed, %s (%s -> %s)." msgstr "" -#: apt-pkg/acquire-item.cc:281 apt-pkg/acquire-item.cc:992 +#: apt-pkg/acquire-item.cc:286 apt-pkg/acquire-item.cc:997 msgid "MD5Sum mismatch" msgstr "" -#: apt-pkg/acquire-item.cc:686 +#: apt-pkg/acquire-item.cc:691 msgid "There is no public key available for the following key IDs:\n" msgstr "" -#: apt-pkg/acquire-item.cc:800 +#: apt-pkg/acquire-item.cc:805 #, 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:859 +#: apt-pkg/acquire-item.cc:864 #, 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:895 +#: apt-pkg/acquire-item.cc:900 #, c-format msgid "" "The package index files are corrupted. No Filename: field for package %s." msgstr "" -#: apt-pkg/acquire-item.cc:982 +#: apt-pkg/acquire-item.cc:987 msgid "Size mismatch" msgstr "" -- cgit v1.2.3 From 3f599bb721c4ac58d8ff18991c9704b5f30eaa2b Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 6 Feb 2007 10:49:25 +0100 Subject: * apt-pkg/acquire-item.cc: - default to "/usr/lib/apt/apt-report-mirror-failure" * cmdline/apt-report-mirror-failure: - no default comit url for now * debian/rules: - move apt-report-mirror-failure into /usr/lib/apt * doc/examples/configure-index: - more documentation * methods/mirror.cc: - updated TODO --- apt-pkg/acquire-item.cc | 2 +- cmdline/apt-report-mirror-failure | 4 ++-- cmdline/makefile | 2 +- debian/rules | 4 ++++ doc/examples/configure-index | 4 ++++ methods/mirror.cc | 1 + 6 files changed, 13 insertions(+), 4 deletions(-) diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 14610d6e9..38530152f 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -154,7 +154,7 @@ void pkgAcquire::Item::ReportMirrorFailure(string FailCode) const char *Args[40]; unsigned int i = 0; string report = _config->Find("Methods::Mirror::ProblemReporting", - "/usr/bin/apt-report-mirror-failure"); + "/usr/lib/apt/apt-report-mirror-failure"); if(!FileExists(report)) return; Args[i++] = report.c_str(); diff --git a/cmdline/apt-report-mirror-failure b/cmdline/apt-report-mirror-failure index fb43f0e74..1567e78e3 100755 --- a/cmdline/apt-report-mirror-failure +++ b/cmdline/apt-report-mirror-failure @@ -5,8 +5,8 @@ import urllib import apt_pkg apt_pkg.init() -url = apt_pkg.Config.Find("Acquire::Mirror::ReportFailures", - "http://people.ubuntu.com:9000/mirror-failure") +url = apt_pkg.Config.Find("Acquire::Mirror::ReportFailures", None) + #"http://people.ubuntu.com:9000/mirror-failure") #"http://localhost:9000/mirror-failure") if not url: sys.exit(0) diff --git a/cmdline/makefile b/cmdline/makefile index f07c7da3b..8d284c2f3 100644 --- a/cmdline/makefile +++ b/cmdline/makefile @@ -55,6 +55,6 @@ include $(COPY_H) # The apt-key program SOURCE=apt-report-mirror-failure -TO=$(LIB) +TO=$(BIN) TARGET=program include $(COPY_H) diff --git a/debian/rules b/debian/rules index 02ee734bb..9e87b1723 100755 --- a/debian/rules +++ b/debian/rules @@ -214,6 +214,10 @@ apt: build debian/shlibs.local # head -n 500 ChangeLog > debian/ChangeLog + # move the mirror failure script in place + mv debian/$@/usr/bin/apt-report-mirror-failure \ + debian/$@/usr/lib/apt/apt-report-mirror-failure \ + dh_installexamples -p$@ $(BLD)/docs/examples/* dh_installman -p$@ dh_installcron -p$@ diff --git a/doc/examples/configure-index b/doc/examples/configure-index index 81bb6b3b0..81fa4c52f 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -166,6 +166,10 @@ Acquire RefreshInterval "360"; // refresh interval in minutes MaxAge "90"; // max age for a mirror file in days before // it gets deleted + // mirror failure reporting script + ProblemReporting "/usr/lib/apt/apt-report-mirror-failure"; + // mirror failure reporting url + ReportFailures "http://example.com/mirror-failure"; }; }; diff --git a/methods/mirror.cc b/methods/mirror.cc index c5c0c7461..9a86a10c2 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -42,6 +42,7 @@ using namespace std; * - 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 + * and better error handling there! * - support more than http * - testing :) */ -- cgit v1.2.3 From 39e1be0ff93e3084b7cb98b6a7d0c272a8b296b0 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 6 Feb 2007 11:06:15 +0100 Subject: * removed dead code --- apt-pkg/acquire-method.cc | 1 - apt-pkg/acquire-method.h | 1 - doc/examples/configure-index | 1 + po/apt-all.pot | 6 +++--- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apt-pkg/acquire-method.cc b/apt-pkg/acquire-method.cc index 13201d310..180b52ad7 100644 --- a/apt-pkg/acquire-method.cc +++ b/apt-pkg/acquire-method.cc @@ -373,7 +373,6 @@ 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); diff --git a/apt-pkg/acquire-method.h b/apt-pkg/acquire-method.h index ee68c75f7..20691cc2c 100644 --- a/apt-pkg/acquire-method.h +++ b/apt-pkg/acquire-method.h @@ -33,7 +33,6 @@ class pkgAcqMethod string DestFile; time_t LastModified; bool IndexFile; - string ExpectedMD5; }; struct FetchResult diff --git a/doc/examples/configure-index b/doc/examples/configure-index index 81fa4c52f..c02fe849f 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -184,6 +184,7 @@ Dir "/" userstatus "status.user"; status "/var/lib/dpkg/status"; cdroms "cdroms.list"; + mirrors "mirrors/"; }; // Location of the cache dir diff --git a/po/apt-all.pot b/po/apt-all.pot index 2355eee20..c37d84be2 100644 --- a/po/apt-all.pot +++ b/po/apt-all.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2007-02-01 12:41+0100\n" +"POT-Creation-Date: 2007-02-06 10:56+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -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:81 +#: apt-pkg/acquire.cc:421 apt-pkg/clean.cc:38 methods/mirror.cc:82 #, 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:87 +#: methods/mirror.cc:88 #, c-format msgid "Unable to change to %s" msgstr "" -- cgit v1.2.3