diff options
Diffstat (limited to 'bitbake/lib/bb/persist_data.py')
-rw-r--r-- | bitbake/lib/bb/persist_data.py | 91 |
1 files changed, 32 insertions, 59 deletions
diff --git a/bitbake/lib/bb/persist_data.py b/bitbake/lib/bb/persist_data.py index de8f87a8bf..bcca791edf 100644 --- a/bitbake/lib/bb/persist_data.py +++ b/bitbake/lib/bb/persist_data.py @@ -12,14 +12,14 @@ currently, providing a key/value store accessed by 'domain'. # import collections +import collections.abc +import contextlib +import functools import logging import os.path -import sys -import warnings -from bb.compat import total_ordering -from collections import Mapping import sqlite3 -import contextlib +import sys +from collections.abc import Mapping sqlversion = sqlite3.sqlite_version_info if sqlversion[0] < 3 or (sqlversion[0] == 3 and sqlversion[1] < 3): @@ -28,8 +28,8 @@ if sqlversion[0] < 3 or (sqlversion[0] == 3 and sqlversion[1] < 3): logger = logging.getLogger("BitBake.PersistData") -@total_ordering -class SQLTable(collections.MutableMapping): +@functools.total_ordering +class SQLTable(collections.abc.MutableMapping): class _Decorators(object): @staticmethod def retry(*, reconnect=True): @@ -63,7 +63,7 @@ class SQLTable(collections.MutableMapping): """ Decorator that starts a database transaction and creates a database cursor for performing queries. If no exception is thrown, the - database results are commited. If an exception occurs, the database + database results are committed. If an exception occurs, the database is rolled back. In all cases, the cursor is closed after the function ends. @@ -179,6 +179,9 @@ class SQLTable(collections.MutableMapping): elif not isinstance(value, str): raise TypeError('Only string values are supported') + # Ensure the entire transaction (including SELECT) executes under write lock + cursor.execute("BEGIN EXCLUSIVE") + cursor.execute("SELECT * from %s where key=?;" % self.table, [key]) row = cursor.fetchone() if row is not None: @@ -205,7 +208,7 @@ class SQLTable(collections.MutableMapping): def __lt__(self, other): if not isinstance(other, Mapping): - raise NotImplemented + raise NotImplementedError() return len(self) < len(other) @@ -235,55 +238,6 @@ class SQLTable(collections.MutableMapping): def has_key(self, key): return key in self - -class PersistData(object): - """Deprecated representation of the bitbake persistent data store""" - def __init__(self, d): - warnings.warn("Use of PersistData is deprecated. Please use " - "persist(domain, d) instead.", - category=DeprecationWarning, - stacklevel=2) - - self.data = persist(d) - logger.debug(1, "Using '%s' as the persistent data cache", - self.data.filename) - - def addDomain(self, domain): - """ - Add a domain (pending deprecation) - """ - return self.data[domain] - - def delDomain(self, domain): - """ - Removes a domain and all the data it contains - """ - del self.data[domain] - - def getKeyValues(self, domain): - """ - Return a list of key + value pairs for a domain - """ - return list(self.data[domain].items()) - - def getValue(self, domain, key): - """ - Return the value of a key for a domain - """ - return self.data[domain][key] - - def setValue(self, domain, key, value): - """ - Sets the value of a key for a domain - """ - self.data[domain][key] = value - - def delValue(self, domain, key): - """ - Deletes a key/value pair - """ - del self.data[domain][key] - def persist(domain, d): """Convenience factory for SQLTable objects based upon metadata""" import bb.utils @@ -295,4 +249,23 @@ def persist(domain, d): bb.utils.mkdirhier(cachedir) cachefile = os.path.join(cachedir, "bb_persist_data.sqlite3") - return SQLTable(cachefile, domain) + + try: + return SQLTable(cachefile, domain) + except sqlite3.OperationalError: + # Sqlite fails to open database when its path is too long. + # After testing, 504 is the biggest path length that can be opened by + # sqlite. + # Note: This code is called before sanity.bbclass and its path length + # check + max_len = 504 + if len(cachefile) > max_len: + logger.critical("The path of the cache file is too long " + "({0} chars > {1}) to be opened by sqlite! " + "Your cache file is \"{2}\"".format( + len(cachefile), + max_len, + cachefile)) + sys.exit(1) + else: + raise |