From d0b0e4d88b465796bf3ff5bfbd6f709e4e367560 Mon Sep 17 00:00:00 2001 From: moson-mo Date: Wed, 17 May 2023 18:22:53 +0200 Subject: [PATCH] fix: update repo information with aurblup script Currently, the "Repo" column in "OfficialProviders" is not updated when a package is moved from one repository to another. Note that we only save a package/provides combination once, hence if a package is available in core and testing at the same time, it would only put just one record into the OfficialProviders table. We iterate through the repos one by one and the last value is kept for mapping a (package/provides) combination to a repo. Due to that, the repos listed in the "sync-db" config setting should be ordered such that the "testing" repos are listed first. Signed-off-by: moson-mo --- aurweb/scripts/aurblup.py | 11 +++++++++++ test/test_aurblup.py | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/aurweb/scripts/aurblup.py b/aurweb/scripts/aurblup.py index 340d1ccd..10da1d98 100755 --- a/aurweb/scripts/aurblup.py +++ b/aurweb/scripts/aurblup.py @@ -49,6 +49,7 @@ def _main(force: bool = False): .all() ) + # delete providers not existing in any of our alpm repos for name, provides in old_providers.difference(providers): db.delete_all( db.query(OfficialProvider).filter( @@ -59,10 +60,20 @@ def _main(force: bool = False): ) ) + # add new providers that do not yet exist in our DB for name, provides in providers.difference(old_providers): repo = repomap.get((name, provides)) db.create(OfficialProvider, Name=name, Repo=repo, Provides=provides) + # update providers where a pkg was moved from one repo to another + all_providers = db.query(OfficialProvider) + + for op in all_providers: + new_repo = repomap.get((op.Name, op.Provides)) + + if op.Repo != new_repo: + op.Repo = new_repo + def main(force: bool = False): db.get_engine() diff --git a/test/test_aurblup.py b/test/test_aurblup.py index 93a832f9..1489677d 100644 --- a/test/test_aurblup.py +++ b/test/test_aurblup.py @@ -87,3 +87,23 @@ def test_aurblup_cleanup(alpm_db: AlpmDatabase): db.query(OfficialProvider).filter(OfficialProvider.Name == "fake package").all() ) assert len(providers) == 0 + + +def test_aurblup_repo_change(alpm_db: AlpmDatabase): + # Add a package and sync up the database. + alpm_db.add("pkg", "1.0", "x86_64", provides=["pkg2", "pkg3"]) + aurblup.main() + + # We should find an entry with repo "test" + op = db.query(OfficialProvider).filter(OfficialProvider.Name == "pkg").first() + assert op.Repo == "test" + + # Modify the repo to something that does not exist. + op.Repo = "nonsense" + + # Run our script. + aurblup.main() + + # Repo should be set back to "test" + db.refresh(op) + assert op.Repo == "test"