diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-04-19 20:53:56 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-19 20:53:56 -0500 |
| commit | 7961741f740abd240754ff6e39cda6d69f727268 (patch) | |
| tree | 036cc70ac34c0030d035b203a31e711e0bfb979d /src | |
| parent | 2c333c74207fe28fd971002ee15620dcf266d2ac (diff) | |
| parent | 1003a677bea3925bdff9e5489b84729d71415b3d (diff) | |
| download | slskd-7961741f740abd240754ff6e39cda6d69f727268.tar.gz | |
Merge pull request #1711 from slskd/config-diff
Fix bug preventing configuration changes from being applied
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Application.cs | 2 | ||||
| -rw-r--r-- | src/slskd/Common/CommonExtensions.cs | 27 |
2 files changed, 25 insertions, 4 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index a8a7883a..86dd9dd1 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -1452,7 +1452,7 @@ namespace slskd foreach (var (property, fqn, left, right) in diff) { - static bool HasAttribute<T>(PropertyInfo property) => property.CustomAttributes.Any(a => a.AttributeType == typeof(T)); + static bool HasAttribute<T>(PropertyInfo property) => property?.CustomAttributes.Any(a => a.AttributeType == typeof(T)) ?? false; var requiresRestart = HasAttribute<RequiresRestartAttribute>(property); var requiresReconnect = HasAttribute<RequiresReconnectAttribute>(property); diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs index 88e6d3c8..77db91ef 100644 --- a/src/slskd/Common/CommonExtensions.cs +++ b/src/slskd/Common/CommonExtensions.cs @@ -111,20 +111,41 @@ namespace slskd /// <returns>A list of differences between the two objects.</returns> public static IEnumerable<(PropertyInfo Property, string FQN, object Left, object Right)> DiffWith(this object left, object right, string parentFqn = null) { - if (left?.GetType() != right?.GetType()) + if (left is null || right is null) { - throw new InvalidCastException($"Unable to diff types {left?.GetType()} and {right?.GetType()}"); + if (left is null == right is null) + { + return []; + } + + return [(null, parentFqn ?? string.Empty, left, right)]; + } + + if (left.GetType() != right.GetType()) + { + throw new InvalidCastException($"Unable to diff types {left.GetType()} and {right.GetType()}"); } var differences = new List<(PropertyInfo Property, string FQN, object Left, object Right)>(); - foreach (var prop in left?.GetType().GetProperties()) + foreach (var prop in left.GetType().GetProperties()) { var leftVal = prop.GetValue(left); var rightVal = prop.GetValue(right); var propType = prop.PropertyType; var fqn = string.IsNullOrEmpty(parentFqn) ? prop.Name : string.Join(".", parentFqn, prop.Name); + if (leftVal is null || rightVal is null) + { + if (leftVal is null == rightVal is null) + { + continue; + } + + differences.Add((prop, fqn, leftVal, rightVal)); + continue; + } + if (propType.IsArray || (propType.IsGenericType && propType.GetGenericTypeDefinition() == typeof(Dictionary<,>))) { if (leftVal.ToJson() != rightVal.ToJson()) |
