From 3e557a1a8a94455c686b4c528fd952b3a3b36f32 Mon Sep 17 00:00:00 2001 From: "Felix C. Stegerman" Date: Sat, 3 Apr 2021 01:34:38 +0200 Subject: [PATCH] check for invalid appids passed to commands --- fdroidserver/common.py | 26 ++++++++++++++++++++++++-- fdroidserver/install.py | 1 + fdroidserver/metadata.py | 12 +----------- fdroidserver/publish.py | 1 + fdroidserver/verify.py | 9 +++++++++ 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 1eecbbdc..f9ec11aa 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -618,13 +618,35 @@ def read_pkg_args(appid_versionCode_pairs, allow_vercodes=False): return vercodes +def get_metadata_files(vercodes): + """ + Build a list of metadata files and raise an exception for invalid appids. + + :param vercodes: version codes as returned by read_pkg_args() + :returns: a list of corresponding metadata/*.yml files + """ + found_invalid = False + metadatafiles = [] + for appid in vercodes.keys(): + f = os.path.join('metadata', '%s.yml' % appid) + if os.path.exists(f): + metadatafiles.append(f) + else: + found_invalid = True + logging.critical(_("No such package: %s") % appid) + if found_invalid: + raise FDroidException(_("Found invalid appids in arguments")) + return metadatafiles + + def read_app_args(appid_versionCode_pairs, allapps, allow_vercodes=False): """Build a list of App instances for processing On top of what read_pkg_args does, this returns the whole app metadata, but limiting the builds list to the builds matching the - appid_versionCode_pairs and vercodes specified. If no appid_versionCode_pairs are specified, then - all App and Build instances are returned. + appid_versionCode_pairs and vercodes specified. If no + appid_versionCode_pairs are specified, then all App and Build instances are + returned. """ diff --git a/fdroidserver/install.py b/fdroidserver/install.py index 8bc5a5d8..0f933121 100644 --- a/fdroidserver/install.py +++ b/fdroidserver/install.py @@ -68,6 +68,7 @@ def main(): if options.appid: vercodes = common.read_pkg_args(options.appid, True) + common.get_metadata_files(vercodes) # only check appids apks = {appid: None for appid in vercodes} # Get the signed APK with the highest vercode diff --git a/fdroidserver/metadata.py b/fdroidserver/metadata.py index 5dde19e6..d5911a8d 100644 --- a/fdroidserver/metadata.py +++ b/fdroidserver/metadata.py @@ -566,17 +566,7 @@ def read_metadata(appids={}, sort_by_time=False): if appids: vercodes = fdroidserver.common.read_pkg_args(appids) - found_invalid = False - metadatafiles = [] - for appid in vercodes.keys(): - f = os.path.join('metadata', '%s.yml' % appid) - if os.path.exists(f): - metadatafiles.append(f) - else: - found_invalid = True - logging.critical(_("No such package: %s") % appid) - if found_invalid: - raise FDroidException(_("Found invalid appids in arguments")) + metadatafiles = fdroidserver.common.get_metadata_files(vercodes) else: metadatafiles = (glob.glob(os.path.join('metadata', '*.yml')) + glob.glob('.fdroid.yml')) diff --git a/fdroidserver/publish.py b/fdroidserver/publish.py index 5e4ccbee..71b5729d 100644 --- a/fdroidserver/publish.py +++ b/fdroidserver/publish.py @@ -268,6 +268,7 @@ def main(): allapps = metadata.read_metadata() vercodes = common.read_pkg_args(options.appid, True) + common.get_metadata_files(vercodes) # only check appids signed_apks = dict() generated_keys = dict() allaliases = check_for_key_collisions(allapps) diff --git a/fdroidserver/verify.py b/fdroidserver/verify.py index 8cb74a32..ed166d3a 100644 --- a/fdroidserver/verify.py +++ b/fdroidserver/verify.py @@ -188,6 +188,7 @@ def main(): logging.error(_("No unsigned directory - nothing to do")) sys.exit(0) + processed = set() verified = 0 notverified = 0 @@ -204,6 +205,8 @@ def main(): if vercodes[appid] and vercode not in vercodes[appid]: continue + processed.add(appid) + try: logging.info("Processing {apkfilename}".format(apkfilename=apkfilename)) @@ -236,6 +239,12 @@ def main(): logging.info("...NOT verified - {0}".format(e)) notverified += 1 + for appid in options.appid: + package = appid.split(":")[0] + if package not in processed: + logging.critical(_("No APK for package: %s") % package) + notverified += 1 + if verified > 0: logging.info("{0} successfully verified".format(verified)) if notverified > 0: