From 26ae10bbff9306ed00ce482e2f9d6a32da69fa10 Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Tue, 20 Aug 2024 21:10:54 +0200 Subject: [PATCH] Made fields readonly --- .../Database/Connection.cs | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/Duplicati.Library.RestAPI/Database/Connection.cs b/Duplicati.Library.RestAPI/Database/Connection.cs index 70e00be87..2f41e866a 100644 --- a/Duplicati.Library.RestAPI/Database/Connection.cs +++ b/Duplicati.Library.RestAPI/Database/Connection.cs @@ -34,13 +34,13 @@ namespace Duplicati.Server.Database public class Connection : IDisposable { private readonly System.Data.IDbConnection m_connection; - private System.Data.IDbCommand m_errorcmd; + private readonly System.Data.IDbCommand m_errorcmd; public readonly object m_lock = new object(); public const int ANY_BACKUP_ID = -1; public const int SERVER_SETTINGS_ID = -2; private readonly Dictionary m_temporaryBackups = new Dictionary(); private readonly bool m_encryptSensitiveFields; - private static HashSet _encryptedFields = + private static readonly HashSet _encryptedFields = BackendLoader.Backends.SelectMany(x => x.SupportedCommands ?? []) .Concat(EncryptionLoader.Modules.SelectMany(x => x.SupportedCommands ?? [])) .Concat(CompressionLoader.Modules.SelectMany(x => x.SupportedCommands ?? [])) @@ -1334,20 +1334,11 @@ namespace Duplicati.Server.Database #region IDisposable implementation public void Dispose() { - if (m_errorcmd != null) - try { if (m_errorcmd != null) m_errorcmd.Dispose(); } - catch { } - finally { m_errorcmd = null; } + try { m_errorcmd?.Dispose(); } + catch { } - - try - { - if (m_connection != null) - m_connection.Dispose(); - } - catch - { - } + try { m_connection?.Dispose(); } + catch { } } #endregion }