From abe1712491d4afd3e2958094620411951e5aceb8 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Fri, 7 Jun 2024 16:22:20 +0200 Subject: [PATCH] Prefer newer JSON cache files to older --- extra_data/run_files_map.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/extra_data/run_files_map.py b/extra_data/run_files_map.py index a2dd2a8f..4bebb197 100644 --- a/extra_data/run_files_map.py +++ b/extra_data/run_files_map.py @@ -94,7 +94,17 @@ def load(self): loaded_data = [] t0 = time.monotonic() + paths_mtimes = [] + for path in self.candidate_paths: + try: + st = os.stat(path) + paths_mtimes.append((path, st.st_mtime)) + except (FileNotFoundError, PermissionError): + pass + + # Try the newest found file (greatest mtime) first + for path, _ in sorted(paths_mtimes, key=lambda x: x[1], reverse=True): try: with open(path) as f: loaded_data = json.load(f)