From d21af70abbfb637ab96b670b9d2e83b0619757f7 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 18 Sep 2023 22:45:45 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9liore=20traitement=20erreurs=20archives?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scodoc/sco_archives.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/scodoc/sco_archives.py b/app/scodoc/sco_archives.py index 9c05c6535..6fe8f7669 100644 --- a/app/scodoc/sco_archives.py +++ b/app/scodoc/sco_archives.py @@ -270,6 +270,10 @@ class BaseArchiver: fname = os.path.join(archive_id, filename) with open(fname, "wb") as f: f.write(data) + except FileNotFoundError as exc: + raise ScoValueError( + f"Erreur stockage archive (dossier inexistant, chemin {fname})" + ) from exc finally: scu.GSL.release() return filename @@ -282,8 +286,13 @@ class BaseArchiver: raise ScoValueError("archive introuvable (déjà supprimée ?)") fname = os.path.join(archive_id, filename) log(f"reading archive file {fname}") - with open(fname, "rb") as f: - data = f.read() + try: + with open(fname, "rb") as f: + data = f.read() + except FileNotFoundError as exc: + raise ScoValueError( + f"Erreur lecture archive (inexistant, chemin {fname})" + ) from exc return data def get_archived_file(self, oid, archive_name, filename, dept_id: int = None):