From 3b884a0caab902ef0c5640b0048da978bb2058c1 Mon Sep 17 00:00:00 2001 From: Liam Keegan Date: Fri, 22 Nov 2024 10:15:30 +0100 Subject: [PATCH] Add `parents=True` to mkdir calls in backend (#181) - if parent dir is missing it is now created instead of raising an error - resolves #180 --- .../src/mondey_backend/routers/admin_routers/languages.py | 2 +- mondey_backend/src/mondey_backend/routers/utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mondey_backend/src/mondey_backend/routers/admin_routers/languages.py b/mondey_backend/src/mondey_backend/routers/admin_routers/languages.py index 6ef5c52..d0e7398 100644 --- a/mondey_backend/src/mondey_backend/routers/admin_routers/languages.py +++ b/mondey_backend/src/mondey_backend/routers/admin_routers/languages.py @@ -40,7 +40,7 @@ async def update_i18n( ): language = get(session, Language, language_id) i18json_path = i18n_language_path(language.id) - i18json_path.parent.mkdir(exist_ok=True) + i18json_path.parent.mkdir(parents=True, exist_ok=True) with open(i18json_path, "w", encoding="utf-8") as i18json_file: json.dump(i18dict, i18json_file, separators=(",", ":"), ensure_ascii=False) return {"ok": True} diff --git a/mondey_backend/src/mondey_backend/routers/utils.py b/mondey_backend/src/mondey_backend/routers/utils.py index 17786c7..7371cbf 100644 --- a/mondey_backend/src/mondey_backend/routers/utils.py +++ b/mondey_backend/src/mondey_backend/routers/utils.py @@ -49,7 +49,7 @@ def write_image_file(file: UploadFile, filename: pathlib.Path | str): image_max_height = 1024 image_quality = 90 try: - pathlib.Path(filename).parent.mkdir(exist_ok=True) + pathlib.Path(filename).parent.mkdir(parents=True, exist_ok=True) with Image.open(file.file) as img: # remove EXIF Orientation tag if present ImageOps.exif_transpose(img, in_place=True)