From 83e6798e72fabee7ec333a7e897b095cda688c45 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 24 Mar 2011 17:37:18 +0100 Subject: merge fix from Matt Zimmerman, many thanks (LP: #741098) --- methods/mirror.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'methods') diff --git a/methods/mirror.cc b/methods/mirror.cc index e499b054b..9d8202dad 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) -- cgit v1.2.3 From 0004842de7eeac345b614fa0b6bd241af0c4cc34 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 24 Mar 2011 17:45:20 +0100 Subject: do not crash if the mirror file fails to download --- methods/mirror.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'methods') diff --git a/methods/mirror.cc b/methods/mirror.cc index 9d8202dad..00757e61f 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -160,6 +160,9 @@ bool MirrorMethod::RandomizeMirrorFile(string mirror_file) vector content; string line; + if (!FileExists(mirror_file)) + return false; + // read ifstream in(mirror_file.c_str()); while ( !in.eof() ) { @@ -356,8 +359,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()) { -- cgit v1.2.3 From b46fb8ff65bf345e51b11946783b450f6fa8f0a8 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 24 Mar 2011 18:01:25 +0100 Subject: methods/mirror.cc: raise error if the mirror file can not be read --- methods/mirror.cc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'methods') diff --git a/methods/mirror.cc b/methods/mirror.cc index 00757e61f..2cf5c9ce1 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -256,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 -- cgit v1.2.3