#include <fstream>
#include <iostream>
+#include <stdarg.h>
+
using namespace std;
#include "mirror.h"
/*}}}*/
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;
{
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 /*{{{*/
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();
}