From 901163e629d6d79f5369475ff5c5adca785cbc94 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Tue, 16 Jun 2020 16:48:10 +0200 Subject: [PATCH] Init SCAP directly before XML sync, in case CSV sync fails --- src/manage_pg.c | 2 +- src/manage_sql_secinfo.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/manage_pg.c b/src/manage_pg.c index a293b0063..9f52aed3b 100644 --- a/src/manage_pg.c +++ b/src/manage_pg.c @@ -3132,7 +3132,7 @@ manage_db_init (const gchar *name) " false);"); sql ("SELECT drop_scap2 ();"); - sql ("DROP FUNCTION drop_scap2 ();"); + sql ("DROP FUNCTION IF EXISTS drop_scap2 ();"); sql ("CREATE SCHEMA scap2;"); diff --git a/src/manage_sql_secinfo.c b/src/manage_sql_secinfo.c index 370127545..d857032f1 100644 --- a/src/manage_sql_secinfo.c +++ b/src/manage_sql_secinfo.c @@ -4710,6 +4710,14 @@ try_load_csv () && g_file_test (file_ovalfiles, G_FILE_TEST_EXISTS) && g_file_test (file_affected_ovaldefs, G_FILE_TEST_EXISTS)) { + /* Create a new schema, "scap2". */ + + if (manage_db_init ("scap")) + { + g_warning ("%s: could not initialize SCAP database 2", __func__); + return -1; + } + sql ("COPY scap2.cves FROM '%s' WITH (FORMAT csv);", file_cves); g_free (file_cves); @@ -4808,6 +4816,11 @@ update_scap (gboolean reset_scap_db) } } + /* If there's CSV in the feed, just load it. */ + + if (try_load_csv () == 0) + return 0; + /* Create a new schema, "scap2". */ if (manage_db_init ("scap")) @@ -4816,11 +4829,6 @@ update_scap (gboolean reset_scap_db) return -1; } - /* If there's CSV in the feed, just load it. */ - - if (try_load_csv () == 0) - return 0; - /* Add the indexes and constraints. */ g_debug ("%s: add indexes", __func__);