From 93c978ba422b26971180a4277a0b69e82848ee78 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 22 Mar 2019 17:58:46 +0100 Subject: [PATCH] Backup / restore original appslist to handle backward case properly --- .../0009_migrate_to_apps_json.py | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/yunohost/data_migrations/0009_migrate_to_apps_json.py b/src/yunohost/data_migrations/0009_migrate_to_apps_json.py index b5ae1130b..8c81746d9 100644 --- a/src/yunohost/data_migrations/0009_migrate_to_apps_json.py +++ b/src/yunohost/data_migrations/0009_migrate_to_apps_json.py @@ -1,15 +1,25 @@ +import os + from moulinette.utils.log import getActionLogger -from yunohost.app import app_fetchlist, app_removelist, _read_appslist_list +from yunohost.app import app_fetchlist, app_removelist, _read_appslist_list, APPSLISTS_JSON from yunohost.tools import Migration logger = getActionLogger('yunohost.migration') +BASE_CONF_PATH = '/home/yunohost.conf' +BACKUP_CONF_DIR = os.path.join(BASE_CONF_PATH, 'backup') +APPSLISTS_BACKUP = os.path.join(BACKUP_CONF_DIR, "appslist_before_migration_0009.json") + + class MyMigration(Migration): "Migrate from official.json to apps.json" def migrate(self): + # Backup current app list json + os.system("cp %s %s") % (APPSLISTS_JSON, APPSLISTS_BACKUP) + # Remove all the deprecated lists lists_to_remove = [ "https://app.yunohost.org/official.json", @@ -28,9 +38,5 @@ class MyMigration(Migration): def backward(self): - # Remove apps.json list - app_removelist(name="yunohost") - - # Replace by official.json list - app_fetchlist(name="yunohost", - url="https://app.yunohost.org/official.json") + if os.path.exists(APPSLISTS_BACKUP): + os.system("cp %s %s") % (APPSLISTS_BACKUP, APPSLISTS_JSON)