From 70b3faa8b3de36c6a92c59ab3ece39305399d4bd Mon Sep 17 00:00:00 2001 From: mnilsen <32636970+ostepizza@users.noreply.github.com> Date: Wed, 10 Apr 2024 14:38:55 +0200 Subject: [PATCH] Moved when temp folder is cleared on BE startup (#104) Moved when and where temp folder is cleared when starting the backend. This fixes a bug accidentally introduced earlier, where the sub-temp folder would be created and then instantly deleted again on startup. --- backend/img2mapAPI/Img2mapAPI.py | 4 ---- backend/img2mapAPI/utils/storage/files/localFileStorage.py | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/img2mapAPI/Img2mapAPI.py b/backend/img2mapAPI/Img2mapAPI.py index 72f3b73..498d6ee 100644 --- a/backend/img2mapAPI/Img2mapAPI.py +++ b/backend/img2mapAPI/Img2mapAPI.py @@ -2,7 +2,6 @@ from fastapi.middleware.cors import CORSMiddleware from img2mapAPI.routers import * from dotenv import load_dotenv, get_key -from .utils.core.FileHelper import clearTmpFolder import os #setting the default environment to development @@ -81,9 +80,6 @@ allow_headers=["*"], ) -# Clear files in the temp folder -clearTmpFolder() - # Default route @router.get("/") async def root(): diff --git a/backend/img2mapAPI/utils/storage/files/localFileStorage.py b/backend/img2mapAPI/utils/storage/files/localFileStorage.py index e162140..cca2073 100644 --- a/backend/img2mapAPI/utils/storage/files/localFileStorage.py +++ b/backend/img2mapAPI/utils/storage/files/localFileStorage.py @@ -2,12 +2,16 @@ import shutil import tempfile from .fileStorage import FileStorage +from ...core.FileHelper import clearTmpFolder from fastapi import UploadFile _tempPath = "./temp" if not os.path.exists(_tempPath): os.makedirs(_tempPath) +# Clear files in the temp folder +clearTmpFolder() + #File storage using the local file system class LocalFileStorage(FileStorage): #temp folder should be in main script folder