Skip to content
Snippets Groups Projects
Commit 1e030420 authored by Martin Mareš's avatar Martin Mareš
Browse files

Joby používají link_to_dir a unlink_if_needed

parent 96effb76
No related branches found
No related tags found
1 merge request!21Reforma uploadů
This commit is part of merge request !21. Comments created here will be created in the context of that merge request.
......@@ -2,7 +2,6 @@
from datetime import timedelta
import os
import secrets
from sqlalchemy import or_
from typing import Optional, Dict, Callable, List
......@@ -49,14 +48,8 @@ class TheJob:
def attach_file(self, tmp_name: str, suffix: str):
"""Vytvoří hardlink na daný pracovní soubor v adresáři jobů."""
while True:
name = secrets.token_hex(16) + suffix
try:
os.link(tmp_name, job_file_path(name))
break
except FileExistsError:
pass
full_name = mo.util.link_to_dir(tmp_name, mo.util.data_dir('jobs'))
name = os.path.basename(full_name)
logger.debug(f'Job: Příloha {tmp_name} -> {name}')
return name
......@@ -74,10 +67,10 @@ class TheJob:
job = self.job
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:
os.unlink(job_file_path(job.out_file))
mo.util.unlink_if_needed(job_file_path(job.out_file))
sess.delete(job)
sess.commit()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment