From ce6afa4157b844ca809e61893bac8ce4c04397d3 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Fri, 20 Jan 2023 20:16:50 -0600 Subject: [PATCH] refactor: Fix more analysis issues --- .../Migration/MigrationExecutorTest.cs | 2 +- src/Recyclarr.TestLibrary/FileUtils.cs | 17 ++++++++++------- .../Http/IServiceRequestBuilder.cs | 1 - .../Http/ServiceRequestBuilder.cs | 2 -- .../CustomFormat/CustomFormatUpdater.cs | 9 ++------- .../Models/ProcessedCustomFormatData.cs | 2 ++ 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/Recyclarr.Cli.Tests/Migration/MigrationExecutorTest.cs b/src/Recyclarr.Cli.Tests/Migration/MigrationExecutorTest.cs index 3d1ddf46..ddc09f5f 100644 --- a/src/Recyclarr.Cli.Tests/Migration/MigrationExecutorTest.cs +++ b/src/Recyclarr.Cli.Tests/Migration/MigrationExecutorTest.cs @@ -105,7 +105,7 @@ public class MigrationExecutorTest : IntegrationFixture using var console = new TestConsole(); var step = Substitute.For(); var executor = new MigrationExecutor(new[] {step}, console); - var exception = new MigrationException(new Exception(), "a", new[] {"b"}); + var exception = new MigrationException(new ArgumentException(), "a", new[] {"b"}); step.CheckIfNeeded().Returns(true); step.When(x => x.Execute(null)).Throw(exception); diff --git a/src/Recyclarr.TestLibrary/FileUtils.cs b/src/Recyclarr.TestLibrary/FileUtils.cs index 98ec8332..d5fb9a00 100644 --- a/src/Recyclarr.TestLibrary/FileUtils.cs +++ b/src/Recyclarr.TestLibrary/FileUtils.cs @@ -3,18 +3,21 @@ using System.Text.RegularExpressions; namespace Recyclarr.TestLibrary; -public static class FileUtils +public static partial class FileUtils { public static ICollection NormalizePaths(IEnumerable paths) => paths.Select(NormalizePath).ToList(); public static string NormalizePath(string path) { - if (MockUnixSupport.IsUnixPlatform()) - { - return Regex.Replace(path, @"^C:\\", "/").Replace("\\", "/"); - } - - return Regex.Replace(path, @"^/", @"C:\").Replace("/", "\\"); + return MockUnixSupport.IsUnixPlatform() + ? WindowsRootRegex().Replace(path, "/").Replace("\\", "/") + : LinuxRootRegex().Replace(path, @"C:\").Replace("/", "\\"); } + + [GeneratedRegex(@"^C:\\")] + private static partial Regex WindowsRootRegex(); + + [GeneratedRegex("^/")] + private static partial Regex LinuxRootRegex(); } diff --git a/src/Recyclarr.TrashLib/Http/IServiceRequestBuilder.cs b/src/Recyclarr.TrashLib/Http/IServiceRequestBuilder.cs index e7489829..3142cc34 100644 --- a/src/Recyclarr.TrashLib/Http/IServiceRequestBuilder.cs +++ b/src/Recyclarr.TrashLib/Http/IServiceRequestBuilder.cs @@ -4,6 +4,5 @@ namespace Recyclarr.TrashLib.Http; public interface IServiceRequestBuilder { - string SanitizedBaseUrl { get; } IFlurlRequest Request(params object[] path); } diff --git a/src/Recyclarr.TrashLib/Http/ServiceRequestBuilder.cs b/src/Recyclarr.TrashLib/Http/ServiceRequestBuilder.cs index 2fdad51f..b3002b83 100644 --- a/src/Recyclarr.TrashLib/Http/ServiceRequestBuilder.cs +++ b/src/Recyclarr.TrashLib/Http/ServiceRequestBuilder.cs @@ -20,6 +20,4 @@ public class ServiceRequestBuilder : IServiceRequestBuilder return client.Request(new[] {"api", "v3"}.Concat(path).ToArray()) .SetQueryParams(new {apikey = _config.ApiKey}); } - - public string SanitizedBaseUrl => FlurlLogging.SanitizeUrl(_config.BaseUrl); } diff --git a/src/Recyclarr.TrashLib/Services/CustomFormat/CustomFormatUpdater.cs b/src/Recyclarr.TrashLib/Services/CustomFormat/CustomFormatUpdater.cs index 8b165c90..03e9251c 100644 --- a/src/Recyclarr.TrashLib/Services/CustomFormat/CustomFormatUpdater.cs +++ b/src/Recyclarr.TrashLib/Services/CustomFormat/CustomFormatUpdater.cs @@ -1,6 +1,5 @@ using Recyclarr.Common.Extensions; using Recyclarr.TrashLib.Config.Services; -using Recyclarr.TrashLib.Http; using Recyclarr.TrashLib.Services.Common; using Recyclarr.TrashLib.Services.CustomFormat.Processors; using Recyclarr.TrashLib.Services.CustomFormat.Processors.PersistenceSteps; @@ -15,7 +14,6 @@ internal class CustomFormatUpdater : ICustomFormatUpdater private readonly IGuideProcessor _guideProcessor; private readonly IPersistenceProcessor _persistenceProcessor; private readonly IAnsiConsole _console; - private readonly IServiceRequestBuilder _service; private readonly ILogger _log; public CustomFormatUpdater( @@ -23,15 +21,13 @@ internal class CustomFormatUpdater : ICustomFormatUpdater ICachePersister cache, IGuideProcessor guideProcessor, IPersistenceProcessor persistenceProcessor, - IAnsiConsole console, - IServiceRequestBuilder service) + IAnsiConsole console) { _log = log; _cache = cache; _guideProcessor = guideProcessor; _persistenceProcessor = persistenceProcessor; _console = console; - _service = service; } public async Task Process(bool isPreview, IEnumerable configs, IGuideService guideService) @@ -197,8 +193,7 @@ internal class CustomFormatUpdater : ICustomFormatUpdater // No CFs are defined in this item, or they are all invalid. Skip this whole instance. if (_guideProcessor.ConfigData.Count == 0) { - _log.Error("Guide processing yielded no custom formats for configured instance host {BaseUrl}", - _service.SanitizedBaseUrl); + _log.Error("Guide processing yielded no custom formats"); return false; } diff --git a/src/Recyclarr.TrashLib/Services/CustomFormat/Models/ProcessedCustomFormatData.cs b/src/Recyclarr.TrashLib/Services/CustomFormat/Models/ProcessedCustomFormatData.cs index 43e95096..9cf8cba8 100644 --- a/src/Recyclarr.TrashLib/Services/CustomFormat/Models/ProcessedCustomFormatData.cs +++ b/src/Recyclarr.TrashLib/Services/CustomFormat/Models/ProcessedCustomFormatData.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Newtonsoft.Json.Linq; namespace Recyclarr.TrashLib.Services.CustomFormat.Models; @@ -15,6 +16,7 @@ public class ProcessedCustomFormatData public string Name => _data.Name; public string TrashId => _data.TrashId; public int? Score => _data.Score; + [SuppressMessage("Usage", "CA2227:Collection properties should be read only")] public JObject Json { get; set; } public int FormatId { get; set; } }