summaryrefslogtreecommitdiff
path: root/methods/mirror.cc
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2011-04-08 14:36:08 +0200
committerMichael Vogt <mvo@debian.org>2011-04-08 14:36:08 +0200
commita6dba137a3d8e011215ba86f55963f33fb8c45ff (patch)
treec769a443be0438678d629d00e5391309ed66e674 /methods/mirror.cc
parent7ea7ac9efa88b73fc6ff30483a928ef49b95c015 (diff)
parentc996a75cabffa5d3e5bc610d9f1097c2edae606f (diff)
merged from the mvo branch
Diffstat (limited to 'methods/mirror.cc')
-rw-r--r--methods/mirror.cc18
1 files changed, 15 insertions, 3 deletions
diff --git a/methods/mirror.cc b/methods/mirror.cc
index e499b054b..2cf5c9ce1 100644
--- a/methods/mirror.cc
+++ b/methods/mirror.cc
@@ -141,8 +141,10 @@ bool MirrorMethod::DownloadMirrorFile(string mirror_uri_str)
pkgAcquire Fetcher;
new pkgAcqFile(&Fetcher, fetch, "", 0, "", "", "", MirrorFile);
bool res = (Fetcher.Run() == pkgAcquire::Continue);
- if(res)
+ if(res) {
DownloadedMirrorFile = true;
+ chmod(MirrorFile.c_str(), 0644);
+ }
Fetcher.Shutdown();
if(Debug)
@@ -158,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() ) {
@@ -251,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
@@ -354,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()) {