diff --git a/src/sbomnix/cpe.py b/src/sbomnix/cpe.py index e6b33cf..082640b 100644 --- a/src/sbomnix/cpe.py +++ b/src/sbomnix/cpe.py @@ -4,10 +4,12 @@ # pylint: disable=too-few-public-methods -""" Generate CPE (Common Platform Enumeration) identifiers""" +"""Generate CPE (Common Platform Enumeration) identifiers""" import sys import string +import time +from sqlite3 import OperationalError from dfdiskcache import DataFrameDiskCache from common.utils import ( LOG, @@ -43,7 +45,19 @@ def __init__(self): "Failed downloading cpedict: CPE information might not be accurate" ) else: - self.cache.set(_CPE_CSV_URL, self.df_cpedict, ttl=_CPE_CSV_CACHE_TTL) + waiting = True + while waiting: + try: + self.cache.set( + _CPE_CSV_URL, self.df_cpedict, ttl=_CPE_CSV_CACHE_TTL + ) + waiting = False + except OperationalError: + LOG.warning( + "CPE Sqlite database is locked! Retrying in 1 second" + ) + time.sleep(1) + if self.df_cpedict is not None: # Verify the loaded cpedict contains at least the following columns required_cols = {"vendor", "product"} diff --git a/src/sbomnix/meta.py b/src/sbomnix/meta.py index 5853adb..3e08a8b 100644 --- a/src/sbomnix/meta.py +++ b/src/sbomnix/meta.py @@ -6,10 +6,12 @@ """Cache nixpkgs meta information""" +import time import os import re import logging +from sqlite3 import OperationalError import pandas as pd from dfdiskcache import DataFrameDiskCache from nixmeta.scanner import NixMetaScanner, nixref_to_nixpkgs_path @@ -33,7 +35,15 @@ class Meta: """Cache nixpkgs meta information""" def __init__(self): - self.cache = DataFrameDiskCache(cache_dir_path=DFCACHE_PATH) + waiting = True + while waiting: + try: + self.cache = DataFrameDiskCache(cache_dir_path=DFCACHE_PATH) + waiting = False + except OperationalError: + LOG.warning("DFCACHE Sqlite database is locked! Retrying in 1 second") + time.sleep(1) + # df_nixmeta includes the meta-info from _NIXMETA_CSV_URL self.df_nixmeta = self.cache.get(_NIXMETA_CSV_URL) if self.df_nixmeta is not None and not self.df_nixmeta.empty: