From 3130bb59ace5fa2ffdbe8ad275e2c76be55ea74d Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Wed, 7 Aug 2019 02:28:37 +0200 Subject: [PATCH] [mod] stop apps upgrade if one upgrade fail --- locales/en.json | 3 ++- src/yunohost/app.py | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/locales/en.json b/locales/en.json index be00d5b1e..cf15bb6f5 100644 --- a/locales/en.json +++ b/locales/en.json @@ -28,7 +28,8 @@ "app_location_unavailable": "This url is not available or conflicts with the already installed app(s):\n{apps:s}", "app_manifest_invalid": "Invalid app manifest: {error}", "app_no_upgrade": "No apps to upgrade", - "app_not_upgraded": "The following apps were not upgraded: {apps}", + "app_not_upgraded": "The following apps were not upgraded because a the app '{app}' failed to upgrade: {apps}", + "app_upgrade_stoped": "The upgrade of alls applications has been stopped to prevent possible dommages because the previous application failed to upgrade", "app_not_correctly_installed": "{app:s} seems to be incorrectly installed", "app_not_installed": "The application '{app:s}' is not installed. Here is the list of all installed apps: {all_apps}", "app_not_properly_removed": "{app:s} has not been properly removed", diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 1bab5eb31..a45766907 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -618,7 +618,7 @@ def app_upgrade(app=[], url=None, file=None): if len(apps) > 1: logger.info(m18n.n("app_upgrade_several_apps", apps=", ".join(apps))) - for app_instance_name in apps: + for number, app_instance_name in enumerate(apps): logger.info(m18n.n('app_upgrade_app_name', app=app_instance_name)) app_dict = app_info(app_instance_name, raw=True) @@ -672,9 +672,19 @@ def app_upgrade(app=[], url=None, file=None): if hook_exec(extracted_app_folder + '/scripts/upgrade', args=args_list, env=env_dict)[0] != 0: msg = m18n.n('app_upgrade_failed', app=app_instance_name) - not_upgraded_apps.append(app_instance_name) - logger.error(msg) operation_logger.error(msg) + + # display this is there are remaining apps + if apps[number + 1:]: + logger.error(m18n.n('app_upgrade_stoped')) + not_upgraded_apps = apps[number:] + # we don't want to continue upgrading apps here in case that breaks + # everything + raise YunohostError('app_not_upgraded', + failed_app=app_instance_name, + apps=', '.join(not_upgraded_apps)) + else: + raise YunohostError(msg) else: now = int(time.time()) # TODO: Move install_time away from app_setting @@ -709,9 +719,6 @@ def app_upgrade(app=[], url=None, file=None): hook_callback('post_app_upgrade', args=args_list, env=env_dict) operation_logger.success() - if not_upgraded_apps: - raise YunohostError('app_not_upgraded', apps=', '.join(not_upgraded_apps)) - permission_sync_to_user() logger.success(m18n.n('upgrade_complete'))