From 237102003cec8df5c8f18b9659751f68ea79d784 Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Wed, 28 Aug 2024 12:52:33 +0200 Subject: [PATCH] Removed some `#if DEBUG` directives in favor of a boolean. Using the flag instead ensures both DEBUG and RELEASE versions of the code is compiled. JIT optimizations will remove the unused code during compilation just the same. --- Duplicati/Server/Program.cs | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/Duplicati/Server/Program.cs b/Duplicati/Server/Program.cs index 70d6d7191..43ed92c64 100644 --- a/Duplicati/Server/Program.cs +++ b/Duplicati/Server/Program.cs @@ -472,17 +472,10 @@ namespace Duplicati.Server { try { -#if DEBUG - if (Math.Abs((DateTime.Now - lastPurge).TotalHours) < 1) + if (Math.Abs((DateTime.Now - lastPurge).TotalHours) < (DEBUG_MODE ? 1 : 23)) { return; } -#else - if (Math.Abs((DateTime.Now - lastPurge).TotalHours) < 23) - { - return; - } -#endif lastPurge = DateTime.Now; @@ -520,13 +513,10 @@ namespace Duplicati.Server } }; -#if DEBUG PurgeTempFilesTimer = - new System.Threading.Timer(purgeTempFilesCallback, null, TimeSpan.FromSeconds(10), TimeSpan.FromHours(1)); -#else - PurgeTempFilesTimer = - new System.Threading.Timer(purgeTempFilesCallback, null, TimeSpan.FromHours(1), TimeSpan.FromDays(1)); -#endif + new System.Threading.Timer(purgeTempFilesCallback, null, + DEBUG_MODE ? TimeSpan.FromSeconds(10) : TimeSpan.FromHours(1), + DEBUG_MODE ? TimeSpan.FromHours(1) : TimeSpan.FromDays(1)); } private static void AdjustApplicationSettings(Dictionary commandlineOptions) @@ -599,9 +589,8 @@ namespace Duplicati.Server private static void ConfigureLogging(Dictionary commandlineOptions) { -#if DEBUG //Log various information in the logfile - if (!commandlineOptions.ContainsKey("log-file")) + if (DEBUG_MODE && !commandlineOptions.ContainsKey("log-file")) { var prefix = System.Reflection.Assembly.GetEntryAssembly().GetName().Name.StartsWith("Duplicati.Server") ? "server" : "trayicon"; commandlineOptions["log-file"] = System.IO.Path.Combine(StartupPath, $"Duplicati-{prefix}.debug.log"); @@ -611,7 +600,6 @@ namespace Duplicati.Server System.IO.File.Delete(commandlineOptions["log-file"]); } } -#endif // Setup the log redirect Library.Logging.Log.StartScope(LogHandler, null);