diff mbox series

[v2] persist_data: Handle sqlite error when cachefile path is too long

Message ID 20230112193255.38994-1-yoann.congal@smile.fr
State Accepted, archived
Commit bf681d173263cd42ffc143655f61abe0573fd83c
Headers show
Series [v2] persist_data: Handle sqlite error when cachefile path is too long | expand

Commit Message

Yoann Congal Jan. 12, 2023, 7:32 p.m. UTC
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]

Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
---
 lib/bb/persist_data.py | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/bb/persist_data.py b/lib/bb/persist_data.py
index ce84a158..bcca791e 100644
--- a/lib/bb/persist_data.py
+++ b/lib/bb/persist_data.py
@@ -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