Skip to content
Snippets Groups Projects

Reforma uploadů

1 unresolved thread
Merged Martin Mareš requested to merge mj/upload into devel
1 unresolved thread
1 file
+ 4
11
Compare changes
  • Side-by-side
  • Inline
+ 4
11
@@ -2,7 +2,6 @@
@@ -2,7 +2,6 @@
from datetime import timedelta
from datetime import timedelta
import os
import os
import secrets
from sqlalchemy import or_
from sqlalchemy import or_
from typing import Optional, Dict, Callable, List
from typing import Optional, Dict, Callable, List
@@ -49,14 +48,8 @@ class TheJob:
@@ -49,14 +48,8 @@ class TheJob:
def attach_file(self, tmp_name: str, suffix: str):
def attach_file(self, tmp_name: str, suffix: str):
"""Vytvoří hardlink na daný pracovní soubor v adresáři jobů."""
"""Vytvoří hardlink na daný pracovní soubor v adresáři jobů."""
while True:
full_name = mo.util.link_to_dir(tmp_name, mo.util.data_dir('jobs'))
name = secrets.token_hex(16) + suffix
name = os.path.basename(full_name)
try:
os.link(tmp_name, job_file_path(name))
break
except FileExistsError:
pass
logger.debug(f'Job: Příloha {tmp_name} -> {name}')
logger.debug(f'Job: Příloha {tmp_name} -> {name}')
return name
return name
@@ -74,10 +67,10 @@ class TheJob:
@@ -74,10 +67,10 @@ class TheJob:
job = self.job
job = self.job
if job.in_file is not None:
if job.in_file is not None:
os.unlink(job_file_path(job.in_file))
mo.util.unlink_if_needed(job_file_path(job.in_file))
if job.out_file is not None:
if job.out_file is not None:
os.unlink(job_file_path(job.out_file))
mo.util.unlink_if_needed(job_file_path(job.out_file))
sess.delete(job)
sess.delete(job)
sess.commit()
sess.commit()
Loading