From d25995c0849846f108bdb39f96f45b340d499532 Mon Sep 17 00:00:00 2001 From: linsui Date: Tue, 15 Nov 2022 18:50:09 +0800 Subject: [PATCH] Set ArchivePolicy based on VercodeOperation/signature --- fdroidserver/update.py | 4 ++++ tests/update.TestCase | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/fdroidserver/update.py b/fdroidserver/update.py index 12c9dfe6..06dd762f 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -1862,6 +1862,10 @@ def archive_old_apks(apps, apks, archapks, repodir, archivedir, defaultkeepversi keepversions = int(app['ArchivePolicy'][:-9]) else: keepversions = defaultkeepversions + if app.get('VercodeOperation'): + keepversions *= len(app['VercodeOperation']) + if common.metadata_find_developer_signing_files(appid, app['CurrentVersionCode']): + keepversions *= 2 logging.debug(_("Checking archiving for {appid} - apks:{integer}, keepversions:{keep}, archapks:{arch}") .format(appid=appid, integer=len(apks), keep=keepversions, arch=len(archapks))) diff --git a/tests/update.TestCase b/tests/update.TestCase index 91428b22..0cac25c7 100755 --- a/tests/update.TestCase +++ b/tests/update.TestCase @@ -1781,6 +1781,27 @@ class UpdateTest(unittest.TestCase): apks, cachechanged = fdroidserver.update.process_apks({}, 'repo', knownapks, False, apps) self.assertEqual([], apks) + def test_archive_old_apks(self): + app = fdroidserver.metadata.App() + app.id = 'test' + app.VercodeOperation = ['%c+1', '%c+2', '%c+3', '%c+4'] + apps = {app.id: app} + with self.assertLogs(level='DEBUG') as cm: + fdroidserver.update.archive_old_apks(apps, [], [], '', '', 3) + self.assertEqual(cm.output, [ + "DEBUG:root:Checking archiving for test - apks:0, keepversions:12, archapks:0" + ]) + + app = fdroidserver.metadata.App() + app.id = 'org.smssecure.smssecure' + app.CurrentVersionCode = 135 + apps = {app.id: app} + with self.assertLogs(level='DEBUG') as cm: + fdroidserver.update.archive_old_apks(apps, [], [], '', '', 3) + self.assertEqual(cm.output, [ + "DEBUG:root:Checking archiving for org.smssecure.smssecure - apks:0, keepversions:6, archapks:0" + ]) + if __name__ == "__main__": os.chdir(os.path.dirname(__file__))