Openembedded Core Discussions
 help / color / mirror / Atom feed
From: Ross Burton <ross.burton@intel.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH 3/3] cve-update-db: refresh once every 24 hours
Date: Thu, 18 Jul 2019 21:04:00 +0100	[thread overview]
Message-ID: <20190718200400.19750-3-ross.burton@intel.com> (raw)
In-Reply-To: <20190718200400.19750-1-ross.burton@intel.com>

Check the mtime of the database before updating, and if it's less than 24 hours
ago don't refresh.  This saves the HTTP fetches to determine if the data has
been updated.

Signed-off-by: Ross Burton <ross.burton@intel.com>
---
 meta/recipes-core/meta/cve-update-db-native.bb | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/meta/recipes-core/meta/cve-update-db-native.bb b/meta/recipes-core/meta/cve-update-db-native.bb
index cabbde5066c..2afca94fc6b 100644
--- a/meta/recipes-core/meta/cve-update-db-native.bb
+++ b/meta/recipes-core/meta/cve-update-db-native.bb
@@ -22,7 +22,7 @@ python do_populate_cve_db() {
     Update NVD database with json data feed
     """
 
-    import sqlite3, urllib, shutil, gzip, re
+    import sqlite3, urllib, shutil, gzip, re, time
     from datetime import date
 
     BASE_URL = "https://nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-"
@@ -37,6 +37,11 @@ python do_populate_cve_db() {
     if not os.path.isdir(db_dir):
         os.mkdir(db_dir)
 
+    expiry = time.time() - (60*60*24) # This time yesterday
+    if os.path.exists(db_file) and expiry < os.path.getmtime(db_file):
+        bb.note("CVE data updated less than 24 hours ago, not refreshing. Delete %s to force update." % db_file)
+        return
+
     # Connect to database
     conn = sqlite3.connect(db_file)
     c = conn.cursor()
-- 
2.20.1



  parent reply	other threads:[~2019-07-18 20:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-18 20:03 [PATCH 1/3] cve-update-db-native: use os.path.join instead of + Ross Burton
2019-07-18 20:03 ` [PATCH 2/3] cve-update-db: actually inherit native Ross Burton
2019-07-18 20:04 ` Ross Burton [this message]
2019-07-18 22:31   ` [PATCH 3/3] cve-update-db: refresh once every 24 hours akuster808
2019-07-18 22:37     ` Burton, Ross
2019-07-18 20:31 ` ✗ patchtest: failure for "cve-update-db-native: use os.p..." and 2 more Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190718200400.19750-3-ross.burton@intel.com \
    --to=ross.burton@intel.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox