summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorRoberto C. Sánchez <roberto@debian.org>2020-11-21 09:10:24 -0500
committerRoberto C. Sánchez <roberto@debian.org>2020-11-21 09:10:24 -0500
commit6db8637e14df554d15f5852b9a93c1a29523f2b9 (patch)
tree8b5af0829a1dba063ff9ff7ba0eba0b8a4263040 /bin
parent6cd2d5c0482b8984b55620a9bd6a759b16dbb0b5 (diff)
LTS: Ensure ~/.cache exists before writing out tracker data cache
If ~/.cache does not already exist, then this happens: $ ./bin/lts-cve-triage.py Updating ~/.cache/debian_security_tracker.json from https://security-tracker.debian.org/tracker/data/json ... Traceback (most recent call last): File "./bin/lts-cve-triage.py", line 94, in <module> tracker = TrackerData(update_cache=not args.skip_cache_update) File "/home/roberto/src/freexian/security-tracker.git/bin/tracker_data.py", line 40, in __init__ self.update_cache() File "/home/roberto/src/freexian/security-tracker.git/bin/tracker_data.py", line 77, in update_cache with open(self.cached_data_path, 'w') as cache_file: FileNotFoundError: [Errno 2] No such file or directory: '/home/roberto/.cache/debian_security_tracker.json'
Diffstat (limited to 'bin')
-rw-r--r--bin/tracker_data.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/bin/tracker_data.py b/bin/tracker_data.py
index b5f15c3976..a3eb2b3d23 100644
--- a/bin/tracker_data.py
+++ b/bin/tracker_data.py
@@ -25,6 +25,7 @@ import six
class TrackerData(object):
DATA_URL = "https://security-tracker.debian.org/tracker/data/json"
GIT_URL = "https://salsa.debian.org/security-tracker-team/security-tracker.git"
+ CACHED_DATA_DIR = "~/.cache"
CACHED_DATA_PATH = "~/.cache/debian_security_tracker.json"
CACHED_REVISION_PATH = "~/.cache/debian_security_tracker.rev"
GET_REVISION_COMMAND = \
@@ -33,6 +34,7 @@ class TrackerData(object):
def __init__(self, update_cache=True):
self._latest_revision = None
+ self.cached_data_dir = os.path.expanduser(self.CACHED_DATA_DIR)
self.cached_data_path = os.path.expanduser(self.CACHED_DATA_PATH)
self.cached_revision_path = os.path.expanduser(
self.CACHED_REVISION_PATH)
@@ -74,6 +76,9 @@ class TrackerData(object):
self.DATA_URL))
response = requests.get(self.DATA_URL, allow_redirects=True)
response.raise_for_status()
+ # if ~/.cache does not exist, then open() will fail; dec 448 -> octal 0700
+ if not os.path.exists(self.cached_data_dir):
+ os.mkdir(self.cached_data_dir, mode=448)
with open(self.cached_data_path, 'w') as cache_file:
cache_file.write(response.text)
with open(self.cached_revision_path, 'w') as rev_file:

© 2014-2024 Faster IT GmbH | imprint | privacy policy