From 254b6ae11847c956258fd44ac4c559f229392779 Mon Sep 17 00:00:00 2001 From: Michael Genson <71845777+michael-genson@users.noreply.github.com> Date: Thu, 25 Jan 2024 19:10:40 +0000 Subject: [PATCH] fixed breaking change with temp dir injection --- mealie/core/dependencies/dependencies.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mealie/core/dependencies/dependencies.py b/mealie/core/dependencies/dependencies.py index da55d6f12..e92ca5042 100644 --- a/mealie/core/dependencies/dependencies.py +++ b/mealie/core/dependencies/dependencies.py @@ -5,7 +5,7 @@ from pathlib import Path from uuid import uuid4 import fastapi -from fastapi import Depends, HTTPException, Request, status +from fastapi import BackgroundTasks, Depends, HTTPException, Request, status from fastapi.security import OAuth2PasswordBearer from jose import JWTError, jwt from sqlalchemy.orm.session import Session @@ -215,14 +215,14 @@ async def temporary_zip_path() -> AsyncGenerator[Path, None]: temp_path.unlink(missing_ok=True) -async def temporary_dir() -> AsyncGenerator[Path, None]: +async def temporary_dir(background_tasks: BackgroundTasks) -> AsyncGenerator[Path, None]: temp_path = app_dirs.TEMP_DIR.joinpath(uuid4().hex) temp_path.mkdir(exist_ok=True, parents=True) try: yield temp_path finally: - shutil.rmtree(temp_path) + background_tasks.add_task(shutil.rmtree, temp_path) def temporary_file(ext: str = "") -> Callable[[], Generator[tempfile._TemporaryFileWrapper, None, None]]: