1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-10-02 17:20:25 +02:00

Merge branch 'skip_apk' into 'master'

Don't include disabled apks in the index

Closes #1002

See merge request fdroid/fdroidserver!1126
This commit is contained in:
Hans-Christoph Steiner 2022-05-23 12:05:40 +00:00
commit 9eeabddcf0
2 changed files with 45 additions and 5 deletions

View File

@ -1415,7 +1415,7 @@ def scan_apk_androguard(apk, apkfile):
def process_apk(apkcache, apkfilename, repodir, knownapks, use_date_from_apk=False, def process_apk(apkcache, apkfilename, repodir, knownapks, use_date_from_apk=False,
allow_disabled_algorithms=False, archive_bad_sig=False): allow_disabled_algorithms=False, archive_bad_sig=False, apps=None):
"""Process the apk with the given filename in the given repo directory. """Process the apk with the given filename in the given repo directory.
This also extracts the icons. This also extracts the icons.
@ -1468,6 +1468,12 @@ def process_apk(apkcache, apkfilename, repodir, knownapks, use_date_from_apk=Fal
.format(apkfilename=apkfilename)) .format(apkfilename=apkfilename))
return True, None, False return True, None, False
if apps:
if apk['packageName'] in apps:
for build in apps[apk['packageName']].get('Builds', []):
if int(build['versionCode']) == apk['versionCode'] and build['disable']:
return True, None, False
# Check for debuggable apks... # Check for debuggable apks...
if common.is_apk_and_debuggable(apkfile): if common.is_apk_and_debuggable(apkfile):
logging.warning('{0} is set to android:debuggable="true"'.format(apkfile)) logging.warning('{0} is set to android:debuggable="true"'.format(apkfile))
@ -1560,7 +1566,7 @@ def process_apk(apkcache, apkfilename, repodir, knownapks, use_date_from_apk=Fal
return False, apk, cachechanged return False, apk, cachechanged
def process_apks(apkcache, repodir, knownapks, use_date_from_apk=False): def process_apks(apkcache, repodir, knownapks, use_date_from_apk=False, apps=None):
"""Process the apks in the given repo directory. """Process the apks in the given repo directory.
This also extracts the icons. This also extracts the icons.
@ -1596,7 +1602,7 @@ def process_apks(apkcache, repodir, knownapks, use_date_from_apk=False):
apkfilename = apkfile[len(repodir) + 1:] apkfilename = apkfile[len(repodir) + 1:]
ada = disabled_algorithms_allowed() ada = disabled_algorithms_allowed()
(skip, apk, cachethis) = process_apk(apkcache, apkfilename, repodir, knownapks, (skip, apk, cachethis) = process_apk(apkcache, apkfilename, repodir, knownapks,
use_date_from_apk, ada, True) use_date_from_apk, ada, True, apps)
if skip: if skip:
continue continue
apks.append(apk) apks.append(apk)
@ -2209,7 +2215,8 @@ def main():
delete_disabled_builds(apps, apkcache, repodirs) delete_disabled_builds(apps, apkcache, repodirs)
# Scan all apks in the main repo # Scan all apks in the main repo
apks, cachechanged = process_apks(apkcache, repodirs[0], knownapks, options.use_date_from_apk) apks, cachechanged = process_apks(apkcache, repodirs[0], knownapks,
options.use_date_from_apk, apps)
files, fcachechanged = scan_repo_files(apkcache, repodirs[0], knownapks, files, fcachechanged = scan_repo_files(apkcache, repodirs[0], knownapks,
options.use_date_from_apk) options.use_date_from_apk)
@ -2272,7 +2279,8 @@ def main():
# Scan the archive repo for apks as well # Scan the archive repo for apks as well
if len(repodirs) > 1: if len(repodirs) > 1:
archapks, cc = process_apks(apkcache, repodirs[1], knownapks, options.use_date_from_apk) archapks, cc = process_apks(apkcache, repodirs[1], knownapks,
options.use_date_from_apk, apps)
if cc: if cc:
cachechanged = True cachechanged = True
else: else:

View File

@ -1716,6 +1716,38 @@ class UpdateTest(unittest.TestCase):
self.maxDiff = None self.maxDiff = None
self.assertEqual(apkaapt, apkandroguard) self.assertEqual(apkaapt, apkandroguard)
def test_exclude_disabled_apks(self):
testdir = tempfile.mkdtemp(
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
)
os.chdir(testdir)
os.mkdir('repo')
testapk = os.path.join('repo', 'com.politedroid_6.apk')
testapk_new = os.path.join('repo', 'Politedroid-1.5.apk')
shutil.copy(os.path.join(self.basedir, testapk), testapk_new)
config = dict()
fdroidserver.common.fill_config_defaults(config)
config['ndk_paths'] = dict()
fdroidserver.common.config = config
fdroidserver.update.config = config
fdroidserver.common.options = Options
fdroidserver.update.options = fdroidserver.common.options
fdroidserver.update.options.clean = True
app = fdroidserver.metadata.App()
app.id = 'com.politedroid'
apps = {app.id: app}
build = fdroidserver.metadata.Build()
build.versionCode = 6
build.disable = "disabled"
app['Builds'] = [build]
knownapks = fdroidserver.common.KnownApks()
apks, cachechanged = fdroidserver.update.process_apks({}, 'repo', knownapks, False, apps)
self.assertEqual([], apks)
if __name__ == "__main__": if __name__ == "__main__":
os.chdir(os.path.dirname(__file__)) os.chdir(os.path.dirname(__file__))