From 067497ddd0d4406bb8341853608528ea7adbb133 Mon Sep 17 00:00:00 2001 From: Glax Date: Wed, 30 Oct 2024 20:38:53 +0100 Subject: [PATCH] Delete duplicate files on startup. --- Tranga/Jobs/JobBoss.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index 7377c38..bbdf95d 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -17,18 +17,21 @@ public class JobBoss : GlobalBase Log($"Next job in {jobs.MinBy(job => job.nextExecution)?.nextExecution.Subtract(DateTime.Now)} {jobs.MinBy(job => job.nextExecution)?.id}"); } - public void AddJob(Job job) + public bool AddJob(Job job, string? jobFile = null) { if (ContainsJobLike(job)) { Log($"Already Contains Job {job}"); + return false; } else { Log($"Added {job}"); - this.jobs.Add(job); - UpdateJobFile(job); + if (!this.jobs.Add(job)) + return false; + UpdateJobFile(job, jobFile); } + return true; } public void AddJobs(IEnumerable jobsToAdd) @@ -162,8 +165,8 @@ public class JobBoss : GlobalBase else { Log($"Adding Job {job}"); - this.jobs.Add(job); - UpdateJobFile(job, file.Name); + if(!AddJob(job, file.Name)) //If we detect a duplicate, delete the file. + file.Delete(); } }