Skip to content

Commit bc7b8d9

Browse files
author
John Andersen
authored
Switch back to .cache/cve-bin-tool
* Changes back to old default directory of .cache/cve-bin-tool (from .cache/cvedb) * Adds warning if old directory exists * Removes old directory when `-u now` is used Fixes: #320
2 parents 5e52e0a + b84bafd commit bc7b8d9

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

cve_bin_tool/VersionSignature.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import sqlite3
33
import time
44
from datetime import datetime
5-
6-
DISK_LOCATION_DEFAULT = os.path.join(os.path.expanduser("~"), ".cache", "cvedb")
5+
from .cvedb import DISK_LOCATION_DEFAULT
76

87

98
class VersionSignatureDb:

cve_bin_tool/cli.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from .file import is_binary
3333
from .OutputEngine import OutputEngine
3434

35-
from .cvedb import CVEDB
35+
from .cvedb import CVEDB, OLD_CACHE_DIR
3636
from .log import LOGGER
3737

3838
try:
@@ -421,6 +421,12 @@ def main(argv=None):
421421
# Connect to the database
422422
cvedb_orig = CVEDB()
423423

424+
# if OLD_CACHE_DIR (from cvedb.py) exists, print warning
425+
if os.path.exists(OLD_CACHE_DIR):
426+
LOGGER.warning(
427+
f"Obsolete cache dir {OLD_CACHE_DIR} is no longer needed and can be removed."
428+
)
429+
424430
# Clear data if -u now is set
425431
if args.update == "now":
426432
cvedb_orig.clear_cached_data()

cve_bin_tool/cvedb.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
logging.basicConfig(level=logging.DEBUG)
3131

3232
# database defaults
33-
DISK_LOCATION_DEFAULT = os.path.join(os.path.expanduser("~"), ".cache", "cvedb")
33+
DISK_LOCATION_DEFAULT = os.path.join(os.path.expanduser("~"), ".cache", "cve-bin-tool")
3434
DBNAME = "cve.db"
35+
OLD_CACHE_DIR = os.path.join(os.path.expanduser("~"), ".cache", "cvedb")
3536

3637

3738
class EmptyCache(Exception):
@@ -145,7 +146,7 @@ class CVEDB(object):
145146
Downloads NVD data in json form and stores it on disk in a cache.
146147
"""
147148

148-
CACHEDIR = os.path.join(os.path.expanduser("~"), ".cache", "cvedb")
149+
CACHEDIR = DISK_LOCATION_DEFAULT
149150
FEED = "https://nvd.nist.gov/vuln/data-feeds"
150151
LOGGER = LOGGER.getChild("CVEDB")
151152
NVDCVE_FILENAME_TEMPLATE = "nvdcve-1.1-{}.json"
@@ -592,6 +593,10 @@ def clear_cached_data(self):
592593
if os.path.exists(self.cachedir):
593594
self.LOGGER.warning(f"Deleting cachedir {self.cachedir}")
594595
shutil.rmtree(self.cachedir)
596+
# Remove files associated with pre-1.0 development tree
597+
if os.path.exists(OLD_CACHE_DIR):
598+
self.LOGGER.warning(f"Deleting old cachedir {OLD_CACHE_DIR}")
599+
shutil.rmtree(OLD_CACHE_DIR)
595600

596601

597602
def refresh():
@@ -601,7 +606,7 @@ def refresh():
601606

602607
if __name__ == "__main__":
603608
LOGGER.debug("Experimenting...")
604-
cvedb = CVEDB(os.path.join(os.path.expanduser("~"), ".cache", "cvedb"))
609+
cvedb = CVEDB(DISK_LOCATION_DEFAULT)
605610
# cvedb.refresh()
606611
# print(cvedb.years())
607612
# connection = cvedb.init_database()

test/test_cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import logging
77
import subprocess
88
from cve_bin_tool.cli import main
9+
from cve_bin_tool.cvedb import DISK_LOCATION_DEFAULT
910
from cve_bin_tool.extractor import Extractor
1011

1112
from .utils import (
@@ -184,7 +185,7 @@ def test_update(self):
184185

185186
with self.assertLogs(logger, logging.INFO) as cm:
186187
main(["cve-bin-tool", "-u", "now", test_path])
187-
db_path = os.path.join(os.path.expanduser("~"), ".cache", "cvedb")
188+
db_path = DISK_LOCATION_DEFAULT
188189
self.assertTrue(
189190
("WARNING:cve_bin_tool.CVEDB:Deleting cachedir " + db_path in cm.output)
190191
and (

test/test_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from jsonschema import validate
1414
from jsonschema.exceptions import ValidationError
1515
from test.utils import LONG_TESTS
16+
from cve_bin_tool.cvedb import DISK_LOCATION_DEFAULT
1617

1718
# Try python3 dependency, fall back if not available
1819
try:
@@ -23,7 +24,6 @@
2324
NVD_SCHEMA = "https://scap.nist.gov/schema/nvd/feed/1.1/nvd_cve_feed_json_1.1.schema"
2425

2526
# NVD feeds from "https://nvd.nist.gov/vuln/data-feeds#JSON_FEED" but stored locally
26-
DISK_LOCATION_DEFAULT = os.path.join(os.path.expanduser("~"), ".cache", "cvedb")
2727
NVD_FILE_TEMPLATE = "nvdcve-1.1-{}.json"
2828

2929

0 commit comments

Comments
 (0)