From abe04272b19c302971ca7cebc338ad13f029b519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20P=C3=B6hn?= Date: Thu, 20 Apr 2017 17:48:38 +0200 Subject: [PATCH] throw proper error when download of apks fail --- fdroidserver/build.py | 6 +++++- fdroidserver/net.py | 3 ++- fdroidserver/verify.py | 6 +++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/fdroidserver/build.py b/fdroidserver/build.py index 4029b08f..c63df9d1 100644 --- a/fdroidserver/build.py +++ b/fdroidserver/build.py @@ -27,6 +27,7 @@ import tarfile import traceback import time import json +import requests from configparser import ConfigParser from argparse import ArgumentParser import logging @@ -1212,7 +1213,10 @@ def main(): logging.info("...retrieving " + url) of = "{0}_{1}.apk.binary".format(app.id, build.versionCode) of = os.path.join(output_dir, of) - net.download_file(url, local_filename=of) + try: + net.download_file(url, local_filename=of) + except requests.exceptions.HTTPError as e: + raise FDroidException('downloading Binaries from %s failed' % url) from e build_succeeded.append(app) wikilog = "Build succeeded" diff --git a/fdroidserver/net.py b/fdroidserver/net.py index c5bf283c..f7932440 100644 --- a/fdroidserver/net.py +++ b/fdroidserver/net.py @@ -26,7 +26,8 @@ def download_file(url, local_filename=None, dldir='tmp'): if local_filename is None: local_filename = os.path.join(dldir, filename) # the stream=True parameter keeps memory usage low - r = requests.get(url, stream=True) + r = requests.get(url, stream=True, allow_redirects=True) + r.raise_for_status() with open(local_filename, 'wb') as f: for chunk in r.iter_content(chunk_size=1024): if chunk: # filter out keep-alive new chunks diff --git a/fdroidserver/verify.py b/fdroidserver/verify.py index cac31a9c..8539775f 100644 --- a/fdroidserver/verify.py +++ b/fdroidserver/verify.py @@ -19,6 +19,7 @@ import sys import os import glob +import requests from argparse import ArgumentParser import logging @@ -76,7 +77,10 @@ def main(): os.remove(remoteapk) url = 'https://f-droid.org/repo/' + apkfilename logging.info("...retrieving " + url) - net.download_file(url, dldir=tmp_dir) + try: + net.download_file(url, dldir=tmp_dir) + except requests.exceptions.HTTPError as e: + raise FDroidException('downloading %s failed', url) from e compare_result = common.verify_apks( remoteapk,