From 8bf8534a9a68c9ca324559c1aede7a939d495a52 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 30 Nov 2016 00:02:52 -0500 Subject: [PATCH 1/3] [fix] Need to create archives_path even for custom output directory --- src/yunohost/backup.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/yunohost/backup.py b/src/yunohost/backup.py index dd7c7385..7d2e9d44 100644 --- a/src/yunohost/backup.py +++ b/src/yunohost/backup.py @@ -120,8 +120,10 @@ def backup_create(name=None, description=None, output_directory=None, env_var['CAN_BIND'] = 0 else: output_directory = archives_path - if not os.path.isdir(archives_path): - os.mkdir(archives_path, 0750) + + # Create archives directory if it does not exists + if not os.path.isdir(archives_path): + os.mkdir(archives_path, 0750) def _clean_tmp_dir(retcode=0): ret = hook_callback('post_backup_create', args=[tmp_dir, retcode]) From 6171fbdb0302cf524f1e17517b27f2a16294306b Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 30 Nov 2016 00:04:17 -0500 Subject: [PATCH 2/3] Keep track of backups with custom directory using symlinks --- locales/en.json | 1 + src/yunohost/backup.py | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/locales/en.json b/locales/en.json index efeb66e6..c50f3d3d 100644 --- a/locales/en.json +++ b/locales/en.json @@ -43,6 +43,7 @@ "backup_action_required": "You must specify something to save", "backup_app_failed": "Unable to back up the app '{app:s}'", "backup_archive_app_not_found": "App '{app:s}' not found in the backup archive", + "backup_archive_broken_link": "Unable to access backup archive (broken link to {path:s})", "backup_archive_hook_not_exec": "Hook '{hook:s}' not executed in this backup", "backup_archive_name_exists": "The backup's archive name already exists", "backup_archive_name_unknown": "Unknown local backup archive named '{name:s}'", diff --git a/src/yunohost/backup.py b/src/yunohost/backup.py index 7d2e9d44..0e991e8f 100644 --- a/src/yunohost/backup.py +++ b/src/yunohost/backup.py @@ -290,7 +290,7 @@ def backup_create(name=None, description=None, output_directory=None, raise MoulinetteError(errno.EIO, m18n.n('backup_archive_open_failed')) - # Add files to the arvhice + # Add files to the archive try: tar.add(tmp_dir, arcname='') tar.close() @@ -300,10 +300,22 @@ def backup_create(name=None, description=None, output_directory=None, raise MoulinetteError(errno.EIO, m18n.n('backup_creation_failed')) + # FIXME : it looks weird that the "move info file" is not enabled if + # user activated "no_compress" ... or does it really means + # "dont_keep_track_of_this_backup_in_history" ? + # Move info file shutil.move(tmp_dir + '/info.json', '{:s}/{:s}.info.json'.format(archives_path, name)) + # If backuped to a non-default location, keep a symlink of the archive + # to that location + if output_directory != archives_path: + link = "%s/%s.tar.gz" % (archives_path, name) + os.symlink(archive_file, link) + + + # Clean temporary directory if tmp_dir != output_directory: _clean_tmp_dir() @@ -604,10 +616,21 @@ def backup_info(name, with_details=False, human_readable=False): """ archive_file = '%s/%s.tar.gz' % (archives_path, name) - if not os.path.isfile(archive_file): + + # Check file exist (even if it's a broken symlink) + if not os.path.lexists(archive_file): raise MoulinetteError(errno.EIO, m18n.n('backup_archive_name_unknown', name=name)) + # If symlink, retrieve the real path + if os.path.islink(archive_file) : + archive_file = os.path.realpath(archive_file) + + # Raise exception if link is broken (e.g. on unmounted external storage) + if (not os.path.exists(archive_file)) : + raise MoulinetteError(errno.EIO, + m18n.n('backup_archive_broken_link', path=archive_file)) + info_file = "%s/%s.info.json" % (archives_path, name) try: with open(info_file) as f: From 1b6d8b64637bbebf630139315c5674e5733b57ad Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Fri, 9 Dec 2016 00:50:28 +0100 Subject: [PATCH 3/3] [mod] pep8 --- src/yunohost/backup.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/yunohost/backup.py b/src/yunohost/backup.py index 0e991e8f..4aec5959 100644 --- a/src/yunohost/backup.py +++ b/src/yunohost/backup.py @@ -623,15 +623,16 @@ def backup_info(name, with_details=False, human_readable=False): m18n.n('backup_archive_name_unknown', name=name)) # If symlink, retrieve the real path - if os.path.islink(archive_file) : + if os.path.islink(archive_file): archive_file = os.path.realpath(archive_file) # Raise exception if link is broken (e.g. on unmounted external storage) - if (not os.path.exists(archive_file)) : + if not os.path.exists(archive_file): raise MoulinetteError(errno.EIO, m18n.n('backup_archive_broken_link', path=archive_file)) info_file = "%s/%s.info.json" % (archives_path, name) + try: with open(info_file) as f: # Retrieve backup info