diff options
author | Michael Opdenacker <michael.opdenacker@bootlin.com> | 2024-05-11 16:31:33 +0530 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-05-21 14:23:43 +0100 |
commit | 3be2201de538a484e94ba91356a2fbe121a53308 (patch) | |
tree | 0844335c4dcc3d1bef903e559ef3cdafb961d0b3 /bitbake/lib/prserv | |
parent | 0d6dd343dee916c9d446e7c3e43aeca3c466f22c (diff) | |
download | poky-3be2201de538a484e94ba91356a2fbe121a53308.tar.gz |
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 <michael.opdenacker@bootlin.com>
Cc: Joshua Watt <JPEWhacker@gmail.com>
Cc: Tim Orling <ticotimo@gmail.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/prserv')
-rw-r--r-- | bitbake/lib/prserv/db.py | 22 |
1 files 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): | |||
78 | else: | 78 | else: |
79 | return False | 79 | return False |
80 | 80 | ||
81 | def test_checksum_value(self, version, pkgarch, checksum, value): | ||
82 | """Returns whether the specified value is found in the database for the specified package, architecture and checksum""" | ||
83 | |||
84 | with closing(self.conn.cursor()) as cursor: | ||
85 | data=cursor.execute("SELECT value FROM %s WHERE version=? AND pkgarch=? and checksum=? and value=?;" % self.table, | ||
86 | (version, pkgarch, checksum, value)) | ||
87 | row=data.fetchone() | ||
88 | if row is not None: | ||
89 | return True | ||
90 | else: | ||
91 | return False | ||
92 | |||
81 | def test_value(self, version, pkgarch, value): | 93 | def test_value(self, version, pkgarch, value): |
82 | """Returns whether the specified value is found in the database for the specified package and architecture""" | 94 | """Returns whether the specified value is found in the database for the specified package and architecture""" |
83 | 95 | ||
@@ -143,15 +155,13 @@ class PRTable(object): | |||
143 | return base + ".0" | 155 | return base + ".0" |
144 | 156 | ||
145 | def store_value(self, version, pkgarch, checksum, value): | 157 | def store_value(self, version, pkgarch, checksum, value): |
146 | """Store new value in the database""" | 158 | """Store value in the database""" |
147 | 159 | ||
148 | with closing(self.conn.cursor()) as cursor: | 160 | if not self.read_only and not self.test_checksum_value(version, pkgarch, checksum, value): |
149 | try: | 161 | with closing(self.conn.cursor()) as cursor: |
150 | cursor.execute("INSERT INTO %s VALUES (?, ?, ?, ?);" % (self.table), | 162 | cursor.execute("INSERT INTO %s VALUES (?, ?, ?, ?);" % (self.table), |
151 | (version, pkgarch, checksum, value)) | 163 | (version, pkgarch, checksum, value)) |
152 | except sqlite3.IntegrityError as exc: | 164 | self.conn.commit() |
153 | logger.error(str(exc)) | ||
154 | self.conn.commit() | ||
155 | 165 | ||
156 | def _get_value(self, version, pkgarch, checksum, history): | 166 | def _get_value(self, version, pkgarch, checksum, history): |
157 | 167 | ||