From a3a0b8dcf0a22bbe05733a9b2d71aec0a1a4c7cd Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Fri, 25 May 2018 11:29:44 +0200 Subject: [PATCH] verify: --reuse-remote-apk to reuse local APKs For something like a verification server, this avoids having `fdroid verify` redownload the remote APK from f-droid.org every time its run. For normal users, it should download a fresh copy each time to avoid false errors based on confusion over anything that might have changed the local copy of the remote APK. This patch has been used on verification.f-droid.org for a while now. It is the last thing keeping verification.f-droid.org from using fdroidserver straight from stretch-backports. --- fdroidserver/verify.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/fdroidserver/verify.py b/fdroidserver/verify.py index 73b94725..aac0a515 100644 --- a/fdroidserver/verify.py +++ b/fdroidserver/verify.py @@ -40,6 +40,8 @@ def main(): parser = ArgumentParser(usage="%(prog)s [options] [APPID[:VERCODE] [APPID[:VERCODE] ...]]") common.setup_global_opts(parser) parser.add_argument("appid", nargs='*', help=_("applicationId with optional versionCode in the form APPID[:VERCODE]")) + parser.add_argument("--reuse-remote-apk", action="store_true", default=False, + help=_("Verify against locally cached copy rather than redownloading.")) options = parser.parse_args() config = common.read_config(options) @@ -74,18 +76,19 @@ def main(): logging.info("Processing {apkfilename}".format(apkfilename=apkfilename)) remoteapk = os.path.join(tmp_dir, apkfilename) - if os.path.exists(remoteapk): - os.remove(remoteapk) - url = 'https://f-droid.org/repo/' + apkfilename - logging.info("...retrieving " + url) - try: - net.download_file(url, dldir=tmp_dir) - except requests.exceptions.HTTPError as e: + if not options.reuse_remote_apk or not os.path.exists(remoteapk): + if os.path.exists(remoteapk): + os.remove(remoteapk) + url = 'https://f-droid.org/repo/' + apkfilename + logging.info("...retrieving " + url) try: - net.download_file(url.replace('/repo', '/archive'), dldir=tmp_dir) + net.download_file(url, dldir=tmp_dir) except requests.exceptions.HTTPError as e: - raise FDroidException(_('Downloading {url} failed. {error}') - .format(url=url, error=e)) + try: + net.download_file(url.replace('/repo', '/archive'), dldir=tmp_dir) + except requests.exceptions.HTTPError as e: + raise FDroidException(_('Downloading {url} failed. {error}') + .format(url=url, error=e)) compare_result = common.verify_apks( remoteapk,