Commit 6c89cc31 authored by James Valleroy's avatar James Valleroy

backups: Confirm that archive exists before restoring

Signed-off-by: James Valleroy's avatarJames Valleroy <jvalleroy@mailbox.org>
parent 9b82fa2f
......@@ -18,6 +18,7 @@
FreedomBox app to manage backup archives.
"""
import errno
import json
import os
......@@ -138,15 +139,28 @@ def get_export_files():
return export_files
def restore_exported(label, name):
"""Restore files from exported backup archive."""
def _find_exported_archive(disk_label, archive_name):
"""Return the full path for the exported archive file."""
path = None
locations = get_export_locations()
for location in locations:
if location[1] == label:
filename = location[0]
if filename[-1] != '/':
filename += '/'
filename += 'FreedomBox-backups/' + name
if location[1] == disk_label:
path = location[0]
if path[-1] != '/':
path += '/'
path += 'FreedomBox-backups/' + archive_name
break
return path
def restore_exported(label, name, apps=None):
"""Restore files from exported backup archive."""
filename = _find_exported_archive(label, name)
if filename:
# TODO: Use backups API.
actions.superuser_run(
'backups', ['restore', '--filename', filename])
break
else:
raise FileNotFoundError(
errno.ENOENT, os.strerror(errno.ENOENT), filename)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment