1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-07 06:25:21 +02:00

fixed breaking change with temp dir injection

This commit is contained in:
Michael Genson 2024-01-25 19:10:40 +00:00
parent a840cb0800
commit 254b6ae118

View file

@ -5,7 +5,7 @@ from pathlib import Path
from uuid import uuid4 from uuid import uuid4
import fastapi import fastapi
from fastapi import Depends, HTTPException, Request, status from fastapi import BackgroundTasks, Depends, HTTPException, Request, status
from fastapi.security import OAuth2PasswordBearer from fastapi.security import OAuth2PasswordBearer
from jose import JWTError, jwt from jose import JWTError, jwt
from sqlalchemy.orm.session import Session from sqlalchemy.orm.session import Session
@ -215,14 +215,14 @@ async def temporary_zip_path() -> AsyncGenerator[Path, None]:
temp_path.unlink(missing_ok=True) 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 = app_dirs.TEMP_DIR.joinpath(uuid4().hex)
temp_path.mkdir(exist_ok=True, parents=True) temp_path.mkdir(exist_ok=True, parents=True)
try: try:
yield temp_path yield temp_path
finally: finally:
shutil.rmtree(temp_path) background_tasks.add_task(shutil.rmtree, temp_path)
def temporary_file(ext: str = "") -> Callable[[], Generator[tempfile._TemporaryFileWrapper, None, None]]: def temporary_file(ext: str = "") -> Callable[[], Generator[tempfile._TemporaryFileWrapper, None, None]]: