mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
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:
parent
8df5b09d0a
commit
968f2a19ed
@ -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."""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user