[cli/core] Do not delete merely incomplete saves unless user says so

This commit is contained in:
derrod 2021-10-21 14:27:08 +02:00
parent 658cc94dbe
commit 106ed16a49
2 changed files with 20 additions and 9 deletions

View file

@ -408,7 +408,7 @@ class LegendaryCLI:
logger.error('Login failed! Cannot continue with download process.')
exit(1)
logger.info(f'Cleaning saves...')
self.core.clean_saves(self._resolve_aliases(args.app_name))
self.core.clean_saves(self._resolve_aliases(args.app_name), args.delete_incomplete)
def sync_saves(self, args):
if not self.core.login():
@ -1941,6 +1941,9 @@ def main():
sync_saves_parser.add_argument('--disable-filters', dest='disable_filters', action='store_true',
help='Disable save game file filtering')
clean_saves_parser.add_argument('--delete-incomplete', dest='delete_incomplete', action='store_true',
help='Delete incomplete save files')
import_parser.add_argument('--disable-check', dest='disable_check', action='store_true',
help='Disables completeness check of the to-be-imported game installation '
'(useful if the imported game is a much older version or missing files)')

View file

@ -851,7 +851,7 @@ class LegendaryCore:
self.log.info('Successfully completed savegame download.')
def clean_saves(self, app_name=''):
def clean_saves(self, app_name='', delete_incomplete=False):
savegames = self.egs.get_user_cloud_saves(app_name=app_name)
files = savegames['files']
deletion_list = []
@ -886,17 +886,25 @@ class LegendaryCore:
m = self.load_manifest(r.content)
# check if all required chunks are present
chunk_fnames = set()
missing_chunks = 0
total_chunks = m.chunk_data_list.count
for chunk in m.chunk_data_list.elements:
cpath_p = fname.split('/', 3)[:3]
cpath_p.append(chunk.path)
cpath = '/'.join(cpath_p)
if cpath not in files:
self.log.error(f'Chunk missing, marking manifest for deletion.')
deletion_list.append(fname)
break
else:
chunk_fnames.add(cpath)
else:
if cpath not in files:
missing_chunks += 1
if (0 < missing_chunks < total_chunks and delete_incomplete) or missing_chunks == total_chunks:
self.log.error(f'Chunk(s) missing, marking manifest for deletion.')
deletion_list.append(fname)
continue
elif 0 < missing_chunks < total_chunks:
self.log.error(f'Some chunk(s) missing, optionally run "legendary download-saves" to obtain a backup '
f'of the corrupted save, then re-run this command with "--delete-incomplete" to remove '
f'it from the cloud save service.')
used_chunks |= chunk_fnames
# check for orphaned chunks (not used in any manifests)