Skip to content
Snippets Groups Projects
Commit eea79ad9 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Check file size in ava mode

parent baac9880
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,8 @@ web_url = http://localhost:5000
# Max size of uploaded files (also for files from URL, size uncompressed):
# Please set the unit: M for Megabyte or G for Gigabyte (-1 without unit to don't set a limit)
max_upload_size = 3G
# Max upload file size for all-vs-all (only target):
max_upload_size_ava = 1G
# Max upload file size (compressed or not, only for uploaded files, not from URL):
# Please set the unit: M for Megabyte or G for Gigabyte (-1 without unit to don't set a limit)
max_upload_file_size = 1G
......
......@@ -102,6 +102,22 @@ class AppConfigReader:
except NoOptionError:
return -1
def _get_max_upload_size_ava(self):
try:
max_size_b = self._replace_vars(self.reader.get("global", "max_upload_size_ava"))
if max_size_b == "-1":
return -1
size_v = float(max_size_b[:-1])
size_unit = max_size_b[-1].upper()
if size_unit not in ["M", "G"]:
raise ValueError("Max size unit must be M or G")
max_size = int(size_v * 1024 * 1024)
if size_unit == "G":
max_size *= 1024
return max_size
except NoOptionError:
return -1
def _get_max_upload_file_size(self):
try:
max_size_b = self._replace_vars(self.reader.get("global", "max_upload_file_size"))
......
......@@ -433,22 +433,25 @@ class JobManager:
:param max_upload_size_readable: max upload size human readable
:return: (True if correct, True if error set [for fail], True if should be local)
"""
if input_type == "target" and self.query is None:
max_upload_size_readable = self.config.max_upload_size_ava / 1024 / 1024
with Job.connect():
my_input = getattr(self, input_type)
if my_input.get_path().endswith(".gz") and not self.is_gz_file(my_input.get_path()):
# Check file is correctly gzipped
job = Job.get(Job.id_job == self.id_job)
job.status = "fail"
job.error = "Query file is not a correct gzip file"
job.error = input_type + " file is not a correct gzip file"
job.save()
self.clear()
return False, True, None
# Check size:
file_size = self.get_file_size(my_input.get_path())
if -1 < self.config.max_upload_size < file_size:
if -1 < (self.config.max_upload_size if (input_type == "query" or self.query is not None)
else self.config.max_upload_size_ava) < file_size:
job = Job.get(Job.id_job == self.id_job)
job.status = "fail"
job.error = "Query file exceed size limit of %d Mb (uncompressed)" % max_upload_size_readable
job.error = input_type + " file exceed size limit of %d Mb (uncompressed)" % max_upload_size_readable
job.save()
self.clear()
return False, True, None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment