/*}}}*/
/* 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"
+ * - uses 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
- * 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
- * - 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
+ * and better error handling there!
+ * - 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 /*{{{*/
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;
}
}
-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
+ */
+ if(Debug)
+ std::cerr << "GetMirrorFile: " << mirror_uri_str << std::endl;
+ // read sources.list and find match
+ vector<metaIndex *>::const_iterator I;
+ pkgSourceList list;
+ list.ReadMainList();
+ for(I=list.begin(); I != list.end(); I++)
+ {
+ string uristr = (*I)->GetURI();
+ 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)
+ {
+ if(Debug)
+ std::cerr << "found BaseURI: " << uristr << std::endl;
+ BaseUri = uristr.substr(0,uristr.size()-1);
+ }
+ }
string fetch = BaseUri;
fetch.replace(0,strlen("mirror://"),"http://");
getline(in, Mirror);
if(Debug)
cerr << "Using mirror: " << Mirror << endl;
+
+ UsedMirror = Mirror;
return true;
}
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);
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()
{