[cli/lfs] Prune game metadata that's no longer needed

This commit is contained in:
derrod 2021-10-16 19:44:48 +02:00
parent 8c002a76e0
commit 0ef916e9c5
2 changed files with 22 additions and 0 deletions

View file

@ -394,9 +394,28 @@ class LegendaryCore:
if not platform_override: if not platform_override:
self.update_aliases(force=meta_updated) self.update_aliases(force=meta_updated)
if meta_updated:
self._prune_metadata()
return _ret, _dlc return _ret, _dlc
def _prune_metadata(self):
# compile list of games without assets, then delete their metadata
available_assets = {i.app_name for i in self.get_assets()}
for app_name in self.lgd.get_game_app_names():
if app_name in available_assets:
continue
# if metadata is still used by an install hold-off on deleting it
if self.is_installed(app_name):
continue
game = self.get_game(app_name)
# Origin games etc.
if game.third_party_store:
continue
self.log.debug(f'Removing old/unused metadata for "{app_name}"')
self.lgd.delete_game_meta(app_name)
def get_non_asset_library_items(self, force_refresh=False, def get_non_asset_library_items(self, force_refresh=False,
skip_ue=True) -> (List[Game], Dict[str, List[Game]]): skip_ue=True) -> (List[Game], Dict[str, List[Game]]):
""" """

View file

@ -230,6 +230,9 @@ class LGDLFS:
else: else:
raise ValueError(f'Game {app_name} does not exist in metadata DB!') raise ValueError(f'Game {app_name} does not exist in metadata DB!')
def get_game_app_names(self):
return sorted(self._game_metadata.keys())
def get_tmp_path(self): def get_tmp_path(self):
return os.path.join(self.path, 'tmp') return os.path.join(self.path, 'tmp')