From: michael.opdenacker@bootlin.com
To: bitbake-devel@lists.openembedded.org
Cc: Michael Opdenacker <michael.opdenacker@bootlin.com>,
Joshua Watt <JPEWhacker@gmail.com>,
Tim Orling <ticotimo@gmail.com>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: [PATCH v7 6/8] prserv: store_value() improvements
Date: Sat, 11 May 2024 16:31:33 +0530 [thread overview]
Message-ID: <20240511110135.1887578-7-michael.opdenacker@bootlin.com> (raw)
In-Reply-To: <20240511110135.1887578-1-michael.opdenacker@bootlin.com>
From: Michael Opdenacker <michael.opdenacker@bootlin.com>
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.
Signed-off-by: Michael Opdenacker <michael.opdenacker@bootlin.com>
Cc: Joshua Watt <JPEWhacker@gmail.com>
Cc: Tim Orling <ticotimo@gmail.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
lib/prserv/db.py | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/lib/prserv/db.py b/lib/prserv/db.py
index 79c9001bf5..88ed8e2125 100644
--- a/lib/prserv/db.py
+++ b/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):
--
2.34.1
next prev parent reply other threads:[~2024-05-11 11:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-11 11:01 [PATCH v7 0/8] prserv: add support for an "upstream" server michael.opdenacker
2024-05-11 11:01 ` [PATCH v7 1/8] prserv: declare "max_package_pr" client hook michael.opdenacker
2024-05-11 11:01 ` [PATCH v7 2/8] prserv: move code from __init__ to bitbake-prserv michael.opdenacker
2024-05-11 11:01 ` [PATCH v7 3/8] prserv: add "upstream" server support michael.opdenacker
2024-05-11 11:01 ` [PATCH v7 4/8] prserv: enable database sharing michael.opdenacker
2024-05-11 11:01 ` [PATCH v7 5/8] prserv: avoid possible race condition in database code michael.opdenacker
2024-05-11 11:01 ` michael.opdenacker [this message]
2024-05-11 11:01 ` [PATCH v7 7/8] prserv: import simplification michael.opdenacker
2024-05-11 11:01 ` [PATCH v7 8/8] prserv: add bitbake selftests michael.opdenacker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240511110135.1887578-7-michael.opdenacker@bootlin.com \
--to=michael.opdenacker@bootlin.com \
--cc=JPEWhacker@gmail.com \
--cc=bitbake-devel@lists.openembedded.org \
--cc=thomas.petazzoni@bootlin.com \
--cc=ticotimo@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).