From 1ded68d1d517bde9b17fbf324aba49b77c7a489f Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Tue, 24 May 2022 11:58:05 -0300 Subject: [PATCH] [view] fix: checking wrong disk cache path --- bauh/view/util/disk.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/bauh/view/util/disk.py b/bauh/view/util/disk.py index 76fd78ab..f460f45f 100644 --- a/bauh/view/util/disk.py +++ b/bauh/view/util/disk.py @@ -38,20 +38,31 @@ class AsyncDiskCacheLoader(Thread, DiskCacheLoader): self.pkgs.append(pkg) def read(self, pkg: SoftwarePackage) -> Optional[Dict[str, Any]]: - if pkg and pkg.supports_disk_cache() and os.path.exists(pkg.get_disk_cache_path()): - disk_path = pkg.get_disk_data_path() - ext = disk_path.split('.')[-1] + if pkg and pkg.supports_disk_cache(): + data_path = pkg.get_disk_data_path() + + if data_path and os.path.isfile(data_path): + ext = data_path.split('.')[-1] + + try: + with open(data_path) as f: + file_content = f.read() + except FileNotFoundError: + return + + if file_content: + if ext == 'json': + cached_data = json.loads(file_content) + elif ext in {'yml', 'yaml'}: + cached_data = yaml.load(file_content) + else: + raise Exception(f'The cached data file {data_path} has an unsupported format') + + if cached_data: + return cached_data - with open(disk_path) as f: - if ext == 'json': - cached_data = json.loads(f.read()) - elif ext in {'yml', 'yaml'}: - cached_data = yaml.load(f.read()) else: - raise Exception(f'The cached data file {disk_path} has an unsupported format') - - if cached_data: - return cached_data + self.logger.warning(f"No cached content in file {data_path}") def stop_working(self): self._work = False