]> git.saurik.com Git - apt.git/blobdiff - methods/mirror.cc
merge lp:~mvo/apt/sha512-template to add support for sha512
[apt.git] / methods / mirror.cc
index 9d8202dad58340dfa1734bbe2850e53dbfc44ac4..2cf5c9ce1110a9d7f9b259cf9913451b89126d94 100644 (file)
@@ -160,6 +160,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 +256,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
@@ -356,8 +366,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()) {