[view] fix: checking wrong disk cache path

This commit is contained in:
Vinicius Moreira
2022-05-24 11:58:05 -03:00
parent fc29a1a7e9
commit 1ded68d1d5

View File

@@ -38,21 +38,32 @@ class AsyncDiskCacheLoader(Thread, DiskCacheLoader):
self.pkgs.append(pkg) self.pkgs.append(pkg)
def read(self, pkg: SoftwarePackage) -> Optional[Dict[str, Any]]: 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()): if pkg and pkg.supports_disk_cache():
disk_path = pkg.get_disk_data_path() data_path = pkg.get_disk_data_path()
ext = disk_path.split('.')[-1]
with open(disk_path) as f: 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': if ext == 'json':
cached_data = json.loads(f.read()) cached_data = json.loads(file_content)
elif ext in {'yml', 'yaml'}: elif ext in {'yml', 'yaml'}:
cached_data = yaml.load(f.read()) cached_data = yaml.load(file_content)
else: else:
raise Exception(f'The cached data file {disk_path} has an unsupported format') raise Exception(f'The cached data file {data_path} has an unsupported format')
if cached_data: if cached_data:
return cached_data return cached_data
else:
self.logger.warning(f"No cached content in file {data_path}")
def stop_working(self): def stop_working(self):
self._work = False self._work = False