[fix] Don't run hooks not in the backup

This commit is contained in:
zamentur 2015-10-03 23:27:06 +02:00
parent 66f61be90e
commit ffc9bcaf33
2 changed files with 12 additions and 2 deletions

View file

@ -284,7 +284,8 @@ def backup_restore(name, hooks=[], apps=[], ignore_apps=False, ignore_hooks=Fals
from yunohost.hook import hook_exec
# Retrieve and open the archive
archive_file = backup_info(name)['path']
info = backup_info(name)
archive_file = info['path']
try:
tar = tarfile.open(archive_file, "r:gz")
except:
@ -348,8 +349,16 @@ def backup_restore(name, hooks=[], apps=[], ignore_apps=False, ignore_hooks=Fals
# Run hooks
if not ignore_hooks:
if hooks is None or len(hooks)==0:
hooks=info['hooks'].keys()
hooks_filtered=list(set(hooks) & set(info['hooks'].keys()))
hooks_unexecuted=set(hooks) - set(info['hooks'].keys())
for hook in hooks_unexecuted:
logger.warning("hook '%s' not in this backup", hook)
msignals.display(m18n.n('backup_hook_unavailable', hook), 'warning')
msignals.display(m18n.n('restore_running_hooks'))
hook_callback('restore', hooks, args=[tmp_dir])
hook_callback('restore', hooks_filtered, args=[tmp_dir])
# Add apps restore hook
if not ignore_apps:

View file

@ -155,6 +155,7 @@
"backup_cleaning_failed" : "Unable to clean backup directory",
"backup_complete" : "Backup complete",
"backup_invalid_archive" : "Invalid backup archive",
"backup_hook_unavailable" : "The hook '{:s}' is not in this backup",
"restore_confirm_yunohost_installed" : "Do you really want to restore an already installed system? [{answers:s}]",
"restore_app_failed" : "Unable to restore the app '{app:s}'",
"restore_running_hooks" : "Running restoration hooks...",