From 3be2201de538a484e94ba91356a2fbe121a53308 Mon Sep 17 00:00:00 2001 From: Michael Opdenacker Date: Sat, 11 May 2024 16:31:33 +0530 Subject: [PATCH] bitbake: prserv: store_value() improvements Add a test_checksum_value() to test whether a (version, pkgarch, checksum, value) entry already exists in the database. This is used to protect the store_value() function from an error when trying to store a duplicate entry in the database. Also check whether the current database is open in read-only mode. (Bitbake rev: b7f6c085a7cf8ac83695242a0299e2d5f7abc69a) Signed-off-by: Michael Opdenacker Cc: Joshua Watt Cc: Tim Orling Cc: Thomas Petazzoni Signed-off-by: Richard Purdie --- bitbake/lib/prserv/db.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/bitbake/lib/prserv/db.py b/bitbake/lib/prserv/db.py index 79c9001bf5..88ed8e2125 100644 --- a/bitbake/lib/prserv/db.py +++ b/bitbake/lib/prserv/db.py @@ -78,6 +78,18 @@ class PRTable(object): else: return False + def test_checksum_value(self, version, pkgarch, checksum, value): + """Returns whether the specified value is found in the database for the specified package, architecture and checksum""" + + with closing(self.conn.cursor()) as cursor: + data=cursor.execute("SELECT value FROM %s WHERE version=? AND pkgarch=? and checksum=? and value=?;" % self.table, + (version, pkgarch, checksum, value)) + row=data.fetchone() + if row is not None: + return True + else: + return False + def test_value(self, version, pkgarch, value): """Returns whether the specified value is found in the database for the specified package and architecture""" @@ -143,15 +155,13 @@ class PRTable(object): return base + ".0" def store_value(self, version, pkgarch, checksum, value): - """Store new value in the database""" + """Store value in the database""" - with closing(self.conn.cursor()) as cursor: - try: + if not self.read_only and not self.test_checksum_value(version, pkgarch, checksum, value): + with closing(self.conn.cursor()) as cursor: cursor.execute("INSERT INTO %s VALUES (?, ?, ?, ?);" % (self.table), (version, pkgarch, checksum, value)) - except sqlite3.IntegrityError as exc: - logger.error(str(exc)) - self.conn.commit() + self.conn.commit() def _get_value(self, version, pkgarch, checksum, history):