]> git.saurik.com Git - apt.git/blobdiff - methods/mirror.cc
remove fake-status leftover from the python-test
[apt.git] / methods / mirror.cc
index 9d8202dad58340dfa1734bbe2850e53dbfc44ac4..cb24a06cf1743a80eaf5f072bb4cad08d56c563b 100644 (file)
@@ -54,7 +54,7 @@ using namespace std;
  */
 
 MirrorMethod::MirrorMethod()
-   : HttpMethod(), DownloadedMirrorFile(false)
+   : HttpMethod(), DownloadedMirrorFile(false), Debug(false)
 {
 };
 
@@ -107,7 +107,7 @@ bool MirrorMethod::Clean(string Dir)
         continue;
 
       // see if we have that uri
-      for(I=list.begin(); I != list.end(); I++)
+      for(I=list.begin(); I != list.end(); ++I)
       {
         string uri = (*I)->GetURI();
         if(uri.find("mirror://") != 0)
@@ -134,6 +134,10 @@ bool MirrorMethod::DownloadMirrorFile(string mirror_uri_str)
    string fetch = BaseUri;
    fetch.replace(0,strlen("mirror://"),"http://");
 
+   // append the dist as a query string
+   if (Dist != "")
+      fetch += "?dist=" + Dist;
+
    if(Debug)
       clog << "MirrorMethod::DownloadMirrorFile(): '" << fetch << "'"
            << " to " << MirrorFile << endl;
@@ -160,6 +164,9 @@ bool MirrorMethod::RandomizeMirrorFile(string mirror_file)
    vector<string> content;
    string line;
 
+   if (!FileExists(mirror_file))
+      return false;
+
    // read 
    ifstream in(mirror_file.c_str());
    while ( !in.eof() ) {
@@ -253,6 +260,13 @@ bool MirrorMethod::InitMirrors()
       return _error->Error(_("No mirror file '%s' found "), MirrorFile.c_str());
    }
 
+   if (access(MirrorFile.c_str(), R_OK) != 0)
+   {
+      // FIXME: fallback to a default mirror here instead 
+      //        and provide a config option to define that default
+      return _error->Error(_("Can not read mirror file '%s'"), MirrorFile.c_str());
+   }  
+
    // FIXME: make the mirror selection more clever, do not 
    //        just use the first one!
    // BUT: we can not make this random, the mirror has to be
@@ -264,8 +278,18 @@ bool MirrorMethod::InitMirrors()
    while (!in.eof()) 
    {
       getline(in, s);
-      if (s.size() > 0)
-        AllMirrors.push_back(s);
+
+      // ignore lines that start with #
+      if (s.find("#") == 0)
+         continue;
+      // ignore empty lines
+      if (s.size() == 0)
+         continue;
+      // ignore non http lines
+      if (s.find("http://") != 0)
+         continue;
+
+      AllMirrors.push_back(s);
    }
    Mirror = AllMirrors[0];
    UsedMirror = Mirror;
@@ -306,7 +330,7 @@ string MirrorMethod::GetMirrorFileName(string mirror_uri_str)
    vector<metaIndex *>::const_iterator I;
    pkgSourceList list;
    list.ReadMainList();
-   for(I=list.begin(); I != list.end(); I++)
+   for(I=list.begin(); I != list.end(); ++I)
    {
       string uristr = (*I)->GetURI();
       if(Debug)
@@ -319,6 +343,7 @@ string MirrorMethod::GetMirrorFileName(string mirror_uri_str)
         if(Debug)
            std::cerr << "found BaseURI: " << uristr << std::endl;
         BaseUri = uristr.substr(0,uristr.size()-1);
+         Dist = (*I)->GetDist();
       }
    }
    // get new file
@@ -356,8 +381,8 @@ bool MirrorMethod::Fetch(FetchItem *Itm)
    if(Itm->IndexFile && !DownloadedMirrorFile)
    {
       Clean(_config->FindDir("Dir::State::mirrors"));
-      DownloadMirrorFile(Itm->Uri);
-      RandomizeMirrorFile(MirrorFile);
+      if (DownloadMirrorFile(Itm->Uri))
+         RandomizeMirrorFile(MirrorFile);
    }
 
    if(AllMirrors.empty()) {