|
2 | 2 | # which is available at https://www.volatilityfoundation.org/license/vsl-v1.0 |
3 | 3 | # |
4 | 4 | import base64 |
| 5 | +import datetime |
5 | 6 | import json |
6 | 7 | import logging |
7 | 8 | import os |
@@ -170,6 +171,7 @@ def __init__(self, filename: str): |
170 | 171 | def _connect_storage(self, path: str) -> sqlite3.Connection: |
171 | 172 | database = sqlite3.connect(path) |
172 | 173 | database.row_factory = sqlite3.Row |
| 174 | + |
173 | 175 | database.cursor().execute( |
174 | 176 | f'CREATE TABLE IF NOT EXISTS database_info (schema_version INT DEFAULT {constants.CACHE_SQLITE_SCHEMA_VERSION})') |
175 | 177 | schema_version = database.cursor().execute('SELECT schema_version FROM database_info').fetchone() |
@@ -259,10 +261,31 @@ def update(self, progress_callback = None): |
259 | 261 | cache_update = set() |
260 | 262 | files_to_timestamp = on_disk_locations.intersection(cached_locations) |
261 | 263 | if files_to_timestamp: |
262 | | - result = self._database.cursor().execute("SELECT location FROM cache WHERE local = 1 " |
| 264 | + result = self._database.cursor().execute("SELECT location, cached FROM cache WHERE local = 1 " |
263 | 265 | f"AND cached < date('now', '{self.cache_period}');") |
264 | 266 | for row in result: |
265 | | - if row['location'] in files_to_timestamp: |
| 267 | + location = row['location'] |
| 268 | + stored_timestamp = datetime.datetime.fromisoformat(row['cached']) |
| 269 | + timestamp = stored_timestamp # Default to requiring update |
| 270 | + |
| 271 | + # See if the file is a local URL type we can handle: |
| 272 | + parsed = urllib.parse.urlparse(location) |
| 273 | + pathname = None |
| 274 | + if parsed.scheme == 'file': |
| 275 | + pathname = urllib.request.url2pathname(parsed.path) |
| 276 | + if parsed.scheme == 'jar': |
| 277 | + inner_url = urllib.parse.urlparse(parsed.path) |
| 278 | + if inner_url.scheme == 'file': |
| 279 | + pathname = inner_url.path.split('!')[0] |
| 280 | + |
| 281 | + if pathname: |
| 282 | + timestamp = datetime.datetime.fromtimestamp(os.stat(pathname).st_mtime) |
| 283 | + else: |
| 284 | + vollog.log(constants.LOGLEVEL_VVVV, |
| 285 | + "File location in database classed as local but not file/jar URL") |
| 286 | + |
| 287 | + # If we're supposed to include it, and our last check is older than (or equal to) the file timestamp |
| 288 | + if row['location'] in files_to_timestamp and stored_timestamp < timestamp: |
266 | 289 | cache_update.add(row['location']) |
267 | 290 |
|
268 | 291 | idextractors = list(framework.class_subclasses(IdentifierProcessor)) |
|
0 commit comments