From 4373026f0ed621e6c0129fb568bcdc1954625e5b Mon Sep 17 00:00:00 2001 From: Laurent LAPORTE Date: Wed, 5 Jun 2024 23:03:40 +0200 Subject: [PATCH] feat(archive-output): improved study output deletion --- .../storage/rawstudy/raw_study_service.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/antarest/study/storage/rawstudy/raw_study_service.py b/antarest/study/storage/rawstudy/raw_study_service.py index c0af08675a..ec53fb697f 100644 --- a/antarest/study/storage/rawstudy/raw_study_service.py +++ b/antarest/study/storage/rawstudy/raw_study_service.py @@ -278,23 +278,20 @@ def delete(self, metadata: RawStudy) -> None: def delete_output(self, metadata: RawStudy, output_name: str) -> None: """ - Delete output folder - Args: - metadata: study - output_name: output simulation - - Returns: + Delete output folder or archive (zip or 7z) of a study. + Args: + metadata: The study metadata. + output_name: Output name to be deleted. """ study_path = self.get_study_path(metadata) output_path = study_path / "output" / output_name - if output_path.exists() and output_path.is_dir(): + if output_path.is_dir(): shutil.rmtree(output_path, ignore_errors=True) - elif (output_path.parent / f"{output_name}.7z").exists(): - (output_path.parent / f"{output_name}.7z").unlink(missing_ok=True) else: - output_path = output_path.parent / f"{output_name}.zip" - output_path.unlink(missing_ok=True) + locations = [output_path.with_suffix(".7z"), output_path.with_suffix(".zip")] + for path in locations: + path.unlink(missing_ok=True) remove_from_cache(self.cache, metadata.id) def import_study(self, metadata: RawStudy, stream: t.BinaryIO) -> Study: