From b6cdb07e3f59fd23d716ee521dae0886472dc88d Mon Sep 17 00:00:00 2001 From: glax Date: Tue, 19 Sep 2023 23:15:18 +0200 Subject: [PATCH] Remove filewrites --- Tranga/Jobs/JobBoss.cs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index 141aec1..6ecd8ea 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -165,11 +165,28 @@ public class JobBoss : GlobalBase public void ExportJob(Job job) { string jobFilePath = Path.Join(settings.jobsFolderPath, $"{job.id}.json"); - string jobStr = JsonConvert.SerializeObject(job); - while(IsFileInUse(jobFilePath)) - Thread.Sleep(10); Log($"Exporting Job {jobFilePath}"); - File.WriteAllText(jobFilePath, jobStr); + + if (!this.jobs.Any(jjob => jjob.id == job.id)) + { + try + { + while(IsFileInUse(jobFilePath)) + Thread.Sleep(10); + File.Delete(jobFilePath); + } + catch (Exception e) + { + Log(e.ToString()); + } + } + else + { + string jobStr = JsonConvert.SerializeObject(job); + while(IsFileInUse(jobFilePath)) + Thread.Sleep(10); + File.WriteAllText(jobFilePath, jobStr); + } } public void ExportJobsList()