Skip to content

fix: Handle failed purl2cpe download at first run #4895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cve_bin_tool/cvedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,21 @@ def init_database(self) -> None:
def populate_purl2cpe(self):
"""Transfers data from PURL2CPE database to CVE database."""

purl2cpe_conn = sqlite3.connect(self.cachedir / "purl2cpe/purl2cpe.db")
purl2cpe_dbpath = self.cachedir / "purl2cpe/purl2cpe.db"

# check if downloaded DB exists; if not, we should avoid operating on an empty DB
if not purl2cpe_dbpath.is_file():
self.LOGGER.error("PURL2CPE downloaded data not found, skipping!")
return

purl2cpe_conn = sqlite3.connect(purl2cpe_dbpath)
purl2cpe_cursor = purl2cpe_conn.cursor()

cve_conn = sqlite3.connect(self.dbpath)
cve_cursor = cve_conn.cursor()

# we are occasionally seeing an error where the cache doesn't have
# purl2cpe and thus we get an error, so attempt to initalize here
# purl2cpe and thus we get an error, so attempt to initialize here
cve_cursor.execute(self.TABLE_SCHEMAS["purl2cpe"])
cve_cursor.execute(self.INDEXES["purl"])

Expand Down
Loading