[v2] aurblup: make provider updates more robust

Message ID 20190121205850.17828-1-lfleischer@archlinux.org
State Under Review
Headers show
Series
  • [v2] aurblup: make provider updates more robust
Related show

Commit Message

Lukas Fleischer Jan. 21, 2019, 8:58 p.m. UTC
Reverse the order of deletion and addition so that deletion comes first.
This prevents corner cases such as failing unique key constraints when a
provided package changes from lower case to upper case and the old name
is not yet gone.

Helped-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
---
 aurweb/scripts/aurblup.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Patch

diff --git a/aurweb/scripts/aurblup.py b/aurweb/scripts/aurblup.py
index 1433173..a7d43f1 100755
--- a/aurweb/scripts/aurblup.py
+++ b/aurweb/scripts/aurblup.py
@@ -39,13 +39,13 @@  def main():
     cur = conn.execute("SELECT Name, Provides FROM OfficialProviders")
     oldproviders = set(cur.fetchall())
 
+    for pkg, provides in oldproviders.difference(providers):
+        conn.execute("DELETE FROM OfficialProviders "
+                     "WHERE Name = ? AND Provides = ?", [pkg, provides])
     for pkg, provides in providers.difference(oldproviders):
         repo = repomap[(pkg, provides)]
         conn.execute("INSERT INTO OfficialProviders (Name, Repo, Provides) "
                      "VALUES (?, ?, ?)", [pkg, repo, provides])
-    for pkg, provides in oldproviders.difference(providers):
-        conn.execute("DELETE FROM OfficialProviders "
-                     "WHERE Name = ? AND Provides = ?", [pkg, provides])
 
     conn.commit()
     conn.close()