diff --git a/src/antares/study/version/upgrade_app/__init__.py b/src/antares/study/version/upgrade_app/__init__.py index 417e7d2..bcb3fa0 100644 --- a/src/antares/study/version/upgrade_app/__init__.py +++ b/src/antares/study/version/upgrade_app/__init__.py @@ -115,17 +115,21 @@ def __call__(self) -> None: try: # Perform the upgrade for meth in self.upgrade_methods: - meth.upgrade(self.study_dir) + meth.upgrade(tmp_path) # Update the 'study.antares' file self.study_antares.version = self.version - self.study_antares.to_ini_file(self.study_dir) + self.study_antares.to_ini_file(tmp_path) except Exception: - # If an error occurs, restore the original files - self._safely_replace_original_files(files_to_retrieve, tmp_path) + # If an error occurs, removes the tmp_path + shutil.rmtree(tmp_path) raise + else: + # Everything went well, replace the original files with the upgraded ones + self._safely_replace_original_files(files_to_retrieve, tmp_path) + def _copies_only_necessary_files(self, files_to_upgrade: t.Collection[str], tmp_path: Path) -> list[str]: """ Copies files concerned by the version upgrader into a temporary directory. diff --git a/src/antares/study/version/upgrade_app/upgrader_0900.py b/src/antares/study/version/upgrade_app/upgrader_0900.py index 0683a05..51358c4 100644 --- a/src/antares/study/version/upgrade_app/upgrader_0900.py +++ b/src/antares/study/version/upgrade_app/upgrader_0900.py @@ -12,7 +12,6 @@ class UpgradeTo0900(UpgradeMethod): old = StudyVersion(8, 8) new = StudyVersion(9, 0) - files = ["study.antares"] @classmethod def upgrade(cls, study_dir: Path) -> None: diff --git a/src/antares/study/version/upgrade_app/upgrader_0903.py b/src/antares/study/version/upgrade_app/upgrader_0903.py index a406834..c835966 100644 --- a/src/antares/study/version/upgrade_app/upgrader_0903.py +++ b/src/antares/study/version/upgrade_app/upgrader_0903.py @@ -3,7 +3,7 @@ from antares.study.version.model.study_version import StudyVersion from .upgrade_method import UpgradeMethod -from ..model.general_data import GeneralData +from ..model.general_data import GeneralData, GENERAL_DATA_PATH def upgrade_thematic_trimming(data: GeneralData) -> None: @@ -75,6 +75,7 @@ class UpgradeTo0903(UpgradeMethod): old = StudyVersion(9, 2) new = StudyVersion(9, 3) + files = [GENERAL_DATA_PATH] @staticmethod def _upgrade_general_data(study_dir: Path) -> None: