From b893682f356ca2861d676a51c4ae1c937d4c7c44 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 14 Sep 2011 14:37:13 -0400 Subject: Ensure we have a mirror URL to return If our query returned zero results, then try a slightly less exclusive query followed by returning a 404 result. Signed-off-by: Dan McGee --- packages/views.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'packages') diff --git a/packages/views.py b/packages/views.py index 8c9c1b1..7979335 100644 --- a/packages/views.py +++ b/packages/views.py @@ -548,15 +548,21 @@ def flag_confirmed(request, name, repo, arch): def download(request, name, repo, arch): pkg = get_object_or_404(Package, pkgname=name, repo__name__iexact=repo, arch__name=arch) - mirrorurl = MirrorUrl.objects.filter(mirror__country='Any', + mirror_urls = MirrorUrl.objects.filter( mirror__public=True, mirror__active=True, - protocol__protocol__iexact='HTTP')[0] + protocol__protocol__iexact='HTTP') + # look first for an 'Any' URL, then fall back to any HTTP URL + filtered_urls = mirror_urls.filter(mirror__country='Any')[:1] + if not filtered_urls: + filtered_urls = mirror_urls[:1] + if not filtered_urls: + raise Http404 arch = pkg.arch.name if pkg.arch.agnostic: # grab the first non-any arch to fake the download path arch = Arch.objects.exclude(agnostic=True)[0].name values = { - 'host': mirrorurl.url, + 'host': filtered_urls[0].url, 'arch': arch, 'repo': pkg.repo.name.lower(), 'file': pkg.filename, -- cgit v1.2.3-24-g4f1b