Améliore traitement erreurs archives

This commit is contained in:
Emmanuel Viennet 2023-09-18 22:45:45 +02:00
parent c65bbc3872
commit d21af70abb

View File

@ -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}")
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):