bitbake: persist_data: Handle sqlite error when cachefile path is too long

Sqlite can't open the cachefile when its path is too long (>= 505 char by
my tests).

We do have a path length check in sanity.bbclass but this code is called
before sanity checks.

Treat the error in the exception instead of checking before hand in case
sqlite eventually fixes this.

Fixes [YOCTO #12374]

(Bitbake rev: bf681d173263cd42ffc143655f61abe0573fd83c)

Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Yoann Congal 2023-01-12 20:32:55 +01:00 committed by Richard Purdie
parent 79edc06213
commit e1a661e3d2

View File

@ -249,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