diff --git a/CHANGELOG.md b/CHANGELOG.md index 7504d50a..ae0d1fe4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Address regression causing `reset_unmatched_scores: false` to not be respected. +- Do not show deleted custom formats in console output when `delete_old_custom_formats` is set to + `false`. ## [5.0.0] - 2023-06-22 diff --git a/src/Recyclarr.Cli/Pipelines/CustomFormat/PipelinePhases/CustomFormatApiPersistencePhase.cs b/src/Recyclarr.Cli/Pipelines/CustomFormat/PipelinePhases/CustomFormatApiPersistencePhase.cs index 3750b1f1..340df45c 100644 --- a/src/Recyclarr.Cli/Pipelines/CustomFormat/PipelinePhases/CustomFormatApiPersistencePhase.cs +++ b/src/Recyclarr.Cli/Pipelines/CustomFormat/PipelinePhases/CustomFormatApiPersistencePhase.cs @@ -28,12 +28,9 @@ public class CustomFormatApiPersistencePhase await _api.UpdateCustomFormat(config, dto); } - if (config.DeleteOldCustomFormats) + foreach (var map in transactions.DeletedCustomFormats) { - foreach (var map in transactions.DeletedCustomFormats) - { - await _api.DeleteCustomFormat(config, map.CustomFormatId); - } + await _api.DeleteCustomFormat(config, map.CustomFormatId); } } } diff --git a/src/Recyclarr.Cli/Pipelines/CustomFormat/PipelinePhases/CustomFormatTransactionPhase.cs b/src/Recyclarr.Cli/Pipelines/CustomFormat/PipelinePhases/CustomFormatTransactionPhase.cs index e2c7a090..28218a1d 100644 --- a/src/Recyclarr.Cli/Pipelines/CustomFormat/PipelinePhases/CustomFormatTransactionPhase.cs +++ b/src/Recyclarr.Cli/Pipelines/CustomFormat/PipelinePhases/CustomFormatTransactionPhase.cs @@ -52,11 +52,14 @@ public class CustomFormatTransactionPhase } } - transactions.DeletedCustomFormats.AddRange(cache.TrashIdMappings - // Custom format must be in the cache but NOT in the user's config - .Where(map => guideCfs.All(cf => cf.TrashId != map.TrashId)) - // Also, that cache-only CF must exist in the service (otherwise there is nothing to delete) - .Where(map => serviceData.Any(cf => cf.Id == map.CustomFormatId))); + if (config.DeleteOldCustomFormats) + { + transactions.DeletedCustomFormats.AddRange(cache.TrashIdMappings + // Custom format must be in the cache but NOT in the user's config + .Where(map => guideCfs.All(cf => cf.TrashId != map.TrashId)) + // Also, that cache-only CF must exist in the service (otherwise there is nothing to delete) + .Where(map => serviceData.Any(cf => cf.Id == map.CustomFormatId))); + } return transactions; } diff --git a/src/tests/Recyclarr.Cli.Tests/Pipelines/CustomFormat/PipelinePhases/CustomFormatTransactionPhaseTest.cs b/src/tests/Recyclarr.Cli.Tests/Pipelines/CustomFormat/PipelinePhases/CustomFormatTransactionPhaseTest.cs index e49bd8cf..f5c024f0 100644 --- a/src/tests/Recyclarr.Cli.Tests/Pipelines/CustomFormat/PipelinePhases/CustomFormatTransactionPhaseTest.cs +++ b/src/tests/Recyclarr.Cli.Tests/Pipelines/CustomFormat/PipelinePhases/CustomFormatTransactionPhaseTest.cs @@ -352,7 +352,7 @@ public class CustomFormatTransactionPhaseTest : CliIntegrationFixture } [Test] - public void Deleted_cfs() + public void Deleted_cfs_when_enabled() { var sut = Resolve(); @@ -371,7 +371,10 @@ public class CustomFormatTransactionPhaseTest : CliIntegrationFixture } }; - var config = NewConfig.Radarr(); + var config = NewConfig.Radarr() with + { + DeleteOldCustomFormats = true + }; var result = sut.Execute(config, guideCfs, serviceData, cache); @@ -384,6 +387,36 @@ public class CustomFormatTransactionPhaseTest : CliIntegrationFixture }); } + [Test] + public void No_deleted_cfs_when_disabled() + { + var sut = Resolve(); + + var guideCfs = Array.Empty(); + + var serviceData = new[] + { + new CustomFormatData {Name = "two", Id = 2} + }; + + var cache = new CustomFormatCache + { + TrashIdMappings = new[] + { + new TrashIdMapping("cf2", "two", 2) + } + }; + + var config = NewConfig.Radarr() with + { + DeleteOldCustomFormats = false + }; + + var result = sut.Execute(config, guideCfs, serviceData, cache); + + result.Should().BeEquivalentTo(new CustomFormatTransactionData()); + } + [Test] public void Do_not_delete_cfs_in_config() {