mirror of
https://github.com/flibusta-apps/fb2converter_server.git
synced 2025-12-06 06:55:36 +01:00
Update remove_temp_files
This commit is contained in:
13
app/main.py
13
app/main.py
@@ -1,6 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
|
import shutil
|
||||||
import time
|
import time
|
||||||
from typing import AsyncIterator
|
from typing import AsyncIterator
|
||||||
import uuid
|
import uuid
|
||||||
@@ -99,9 +100,19 @@ app.include_router(router)
|
|||||||
def remove_temp_files():
|
def remove_temp_files():
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.remove("./conversion.log")
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
|
||||||
for f in os.listdir("/tmp/"):
|
for f in os.listdir("/tmp/"):
|
||||||
target_path = f"/tmp/{f}"
|
target_path = f"/tmp/{f}"
|
||||||
|
|
||||||
|
is_file = os.path.isfile(target_path)
|
||||||
|
|
||||||
creation_time = os.path.getctime(target_path)
|
creation_time = os.path.getctime(target_path)
|
||||||
if (current_time - creation_time) // 3600 >= 3:
|
if (current_time - creation_time) // 3600 >= 3:
|
||||||
os.unlink(target_path)
|
if is_file:
|
||||||
|
os.remove(target_path)
|
||||||
|
else:
|
||||||
|
shutil.rmtree(target_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user