From e9a244800244cd785c0cd672ca0dafd8ad892bc6 Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Tue, 3 May 2022 14:26:29 +0300 Subject: [PATCH] Update remove_temp_files --- app/main.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index cc2a590..7d4564d 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,7 @@ import asyncio import os import os.path +import shutil import time from typing import AsyncIterator import uuid @@ -99,9 +100,19 @@ app.include_router(router) def remove_temp_files(): current_time = time.time() + try: + os.remove("./conversion.log") + except IOError: + pass + for f in os.listdir("/tmp/"): target_path = f"/tmp/{f}" + is_file = os.path.isfile(target_path) + creation_time = os.path.getctime(target_path) if (current_time - creation_time) // 3600 >= 3: - os.unlink(target_path) + if is_file: + os.remove(target_path) + else: + shutil.rmtree(target_path)