From ff673b0d73c8c81767a54befba63d35e4a9816a6 Mon Sep 17 00:00:00 2001 From: Michael Pimmer Date: Mon, 17 Sep 2018 05:53:57 +0000 Subject: [PATCH] Backups: export and download archives in one step Reviewed-by: James Valleroy --- actions/backups | 3 ++ plinth/modules/backups/__init__.py | 14 +++++--- plinth/modules/backups/templates/backups.html | 4 +++ plinth/modules/backups/urls.py | 5 ++- plinth/modules/backups/views.py | 36 ++++++++++++++++++- 5 files changed, 56 insertions(+), 6 deletions(-) diff --git a/actions/backups b/actions/backups index 788995f08..aaad064b7 100755 --- a/actions/backups +++ b/actions/backups @@ -132,6 +132,9 @@ def subcommand_extract(arguments): def subcommand_export(arguments): """Export archive contents as tarball.""" + # TODO: if this is only used for files in /tmp, add checks to verify that + # arguments.filename is within /tmp + # TODO: arguments.filename is not a filename but a path path = os.path.dirname(arguments.filename) if not os.path.exists(path): os.makedirs(path) diff --git a/plinth/modules/backups/__init__.py b/plinth/modules/backups/__init__.py index bb00be006..3656a779e 100644 --- a/plinth/modules/backups/__init__.py +++ b/plinth/modules/backups/__init__.py @@ -47,6 +47,8 @@ service = None MANIFESTS_FOLDER = '/var/lib/plinth/backups-manifests/' BACKUP_FOLDER_NAME = 'FreedomBox-backups' +# default backup path for temporary actions like imports or download +TMP_BACKUP_PATH = '/tmp/freedombox-backup.tar.gz' def init(): @@ -108,10 +110,14 @@ def delete_archive(name): actions.superuser_run('backups', ['delete', '--name', name]) -def export_archive(name, location): - location_path = get_location_path(location) - filepath = get_archive_path(location_path, - get_valid_filename(name) + '.tar.gz') +def export_archive(name, location, tmp_dir=False): + # TODO: find a better solution for distinguishing exports to /tmp + if tmp_dir: + filepath = TMP_BACKUP_PATH + else: + location_path = get_location_path(location) + filepath = get_archive_path(location_path, + get_valid_filename(name) + '.tar.gz') # TODO: that's a full path, not a filename; rename argument actions.superuser_run('backups', ['export', '--name', name, '--filename', filepath]) diff --git a/plinth/modules/backups/templates/backups.html b/plinth/modules/backups/templates/backups.html index 3797bd3ac..440dcac0e 100644 --- a/plinth/modules/backups/templates/backups.html +++ b/plinth/modules/backups/templates/backups.html @@ -86,6 +86,10 @@ href="{% url 'backups:export' archive.name %}"> {% trans "Export" %} + + {% trans "Download" %} +