backups: Allow restoring backups with no files

This still makes sense because restoration might restore settings and state of
application being installed (to be implemented).

Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Joseph Nuthalapati 2018-09-29 16:55:38 -07:00 committed by James Valleroy
parent 8df5b09d0a
commit 968f2a19ed
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -178,24 +178,17 @@ def subcommand_restore(arguments):
locations_data = ''.join(sys.stdin)
locations = json.loads(locations_data)
found_file = False
with tarfile.open(arguments.filename) as t:
for member in t.getmembers():
with tarfile.open(arguments.filename) as tar_handle:
for member in tar_handle.getmembers():
path = '/' + member.name
if path in locations['files']:
t.extract(member, '/')
found_file = True
tar_handle.extract(member, '/')
else:
for d in locations['directories']:
if path.startswith(d):
t.extract(member, '/')
found_file = True
for directory in locations['directories']:
if path.startswith(directory):
tar_handle.extract(member, '/')
break
if not found_file:
print('No matching files or directories found in archive:', locations)
sys.exit(1)
def main():
"""Parse arguments and perform all duties."""