Delink console text on duplication

pull/1559/head
Piero Toffanin 2024-09-28 18:17:35 -04:00
rodzic 0cc4be5829
commit 9ee1474df7
2 zmienionych plików z 14 dodań i 0 usunięć

Wyświetl plik

@ -51,3 +51,14 @@ class Console:
f.write(text)
except IOError:
logger.warn("Cannot reset console file: %s" % self.file)
def delink(self):
try:
if os.path.isfile(self.file) and os.stat(self.file).st_nlink > 1:
with open(self.file, "r", encoding="utf-8") as f:
text = f.read()
os.unlink(self.file)
with open(self.file, "w", encoding="utf-8") as f:
f.write(text)
except OSError:
logger.warn("Cannot delink console file: %s" % self.file)

Wyświetl plik

@ -438,6 +438,9 @@ class Task(models.Model):
try:
# Try to use hard links first
shutil.copytree(self.task_path(), task.task_path(), copy_function=os.link)
# Make sure the console output is not linked to the original task
task.console.delink()
except Exception as e:
logger.warning("Cannot duplicate task using hard links, will use normal copy instead: {}".format(str(e)))
shutil.copytree(self.task_path(), task.task_path())