diff mbox series

[1/2] cve-update-db-native: move download cleanup to a function

Message ID 20230102070327.55373-1-rybczynska@gmail.com
State New
Headers show
Series [1/2] cve-update-db-native: move download cleanup to a function | expand

Commit Message

Marta Rybczynska Jan. 2, 2023, 7:03 a.m. UTC
Move cleanup of the database after a failed download to a separate
function. This will be useful when we have more actions to do in
that situation.

Signed-off-by: Marta Rybczynska <marta.rybczynska@linaro.org>
---
 meta/recipes-core/meta/cve-update-db-native.bb | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

Comments

Marta Rybczynska Jan. 4, 2023, 3:27 p.m. UTC | #1
This patch is replaced by
https://lists.openembedded.org/g/openembedded-core/message/175355 (with a
minor patch title change)

On Mon, Jan 2, 2023 at 8:03 AM Marta Rybczynska <rybczynska@gmail.com>
wrote:

> Move cleanup of the database after a failed download to a separate
> function. This will be useful when we have more actions to do in
> that situation.
>
> Signed-off-by: Marta Rybczynska <marta.rybczynska@linaro.org>
> ---
>  meta/recipes-core/meta/cve-update-db-native.bb | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/meta/recipes-core/meta/cve-update-db-native.bb
> b/meta/recipes-core/meta/cve-update-db-native.bb
> index 9b9dbbd75f..642fda5395 100644
> --- a/meta/recipes-core/meta/cve-update-db-native.bb
> +++ b/meta/recipes-core/meta/cve-update-db-native.bb
> @@ -44,13 +44,7 @@ python do_fetch() {
>
>      cve_socket_timeout = int(d.getVar("CVE_SOCKET_TIMEOUT"))
>
> -    if os.path.exists("{0}-journal".format(db_file)):
> -        # If a journal is present the last update might have been
> interrupted. In that case,
> -        # just wipe any leftovers and force the DB to be recreated.
> -        os.remove("{0}-journal".format(db_file))
> -
> -        if os.path.exists(db_file):
> -            os.remove(db_file)
> +    cleanup_db_download(db_file)
>
>      # The NVD database changes once a day, so no need to update more
> frequently
>      # Allow the user to force-update
> @@ -134,6 +128,15 @@ do_fetch[lockfiles] += "${CVE_CHECK_DB_FILE_LOCK}"
>  do_fetch[file-checksums] = ""
>  do_fetch[vardeps] = ""
>
> +def cleanup_db_download(db_file):
> +    if os.path.exists("{0}-journal".format(db_file)):
> +        # If a journal is present the last update might have been
> interrupted. In that case,
> +        # just wipe any leftovers and force the DB to be recreated.
> +        os.remove("{0}-journal".format(db_file))
> +
> +        if os.path.exists(db_file):
> +            os.remove(db_file)
> +
>  def initialize_db(conn):
>      with conn:
>          c = conn.cursor()
> --
> 2.35.1
>
>
diff mbox series

Patch

diff --git a/meta/recipes-core/meta/cve-update-db-native.bb b/meta/recipes-core/meta/cve-update-db-native.bb
index 9b9dbbd75f..642fda5395 100644
--- a/meta/recipes-core/meta/cve-update-db-native.bb
+++ b/meta/recipes-core/meta/cve-update-db-native.bb
@@ -44,13 +44,7 @@  python do_fetch() {
 
     cve_socket_timeout = int(d.getVar("CVE_SOCKET_TIMEOUT"))
 
-    if os.path.exists("{0}-journal".format(db_file)):
-        # If a journal is present the last update might have been interrupted. In that case,
-        # just wipe any leftovers and force the DB to be recreated.
-        os.remove("{0}-journal".format(db_file))
-
-        if os.path.exists(db_file):
-            os.remove(db_file)
+    cleanup_db_download(db_file)
 
     # The NVD database changes once a day, so no need to update more frequently
     # Allow the user to force-update
@@ -134,6 +128,15 @@  do_fetch[lockfiles] += "${CVE_CHECK_DB_FILE_LOCK}"
 do_fetch[file-checksums] = ""
 do_fetch[vardeps] = ""
 
+def cleanup_db_download(db_file):
+    if os.path.exists("{0}-journal".format(db_file)):
+        # If a journal is present the last update might have been interrupted. In that case,
+        # just wipe any leftovers and force the DB to be recreated.
+        os.remove("{0}-journal".format(db_file))
+
+        if os.path.exists(db_file):
+            os.remove(db_file)
+
 def initialize_db(conn):
     with conn:
         c = conn.cursor()