mirror of
https://0xacab.org/jvoisin/mat2-web.git
synced 2025-05-12 11:12:17 -04:00
removed randint from bandit inspection
This commit is contained in:
parent
28ab47c4eb
commit
e20ae95502
1 changed files with 18 additions and 3 deletions
|
@ -1,3 +1,8 @@
|
|||
"""
|
||||
Check regularly if files have not been downloaded
|
||||
and delete them if they're too old
|
||||
"""
|
||||
|
||||
import glob
|
||||
import time
|
||||
import sys
|
||||
|
@ -7,13 +12,23 @@ import random
|
|||
from matweb import utils
|
||||
|
||||
|
||||
def run_file_removal_job(upload_folder_path):
|
||||
if random.randint(0, 10) == 0:
|
||||
def run_file_removal_job(upload_folder_path: str):
|
||||
"""
|
||||
Check for removals at about every 10th request
|
||||
:param upload_folder_path: path were the uploaded files are stored
|
||||
:return: Void
|
||||
"""
|
||||
if random.randint(0, 10) == 0: # nosec
|
||||
for file in glob.glob(upload_folder_path + '/*'):
|
||||
delete_file_when_too_old(file)
|
||||
|
||||
|
||||
def delete_file_when_too_old(filepath):
|
||||
def delete_file_when_too_old(filepath: str):
|
||||
"""
|
||||
Check if files are too old and remove em
|
||||
:param filepath: Path of the file to check
|
||||
:return: Void
|
||||
"""
|
||||
file_mod_time = os.stat(filepath).st_mtime
|
||||
|
||||
# time in second since last modification of file
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue