From 33d1d1f875d9bf2c23f35256a2c644bea1a61e7f Mon Sep 17 00:00:00 2001 From: Stevie Robinson Date: Wed, 27 Sep 2023 16:48:15 +0200 Subject: [PATCH] Fixed: SABnzbd history retention to allow at least 14 days (cherry picked from commit a3938d8e0264b48b35f4715cbc15329fb489218a) Closes #9217 --- .../SabnzbdTests/SabnzbdFixture.cs | 24 +++++++++++++++++++ .../Download/Clients/Sabnzbd/Sabnzbd.cs | 11 ++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs index 25f8c7874c..fef51ec5d5 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs @@ -452,6 +452,30 @@ public void should_return_status_with_outputdir_for_version_lt_2(string rootFold result.OutputRootFolders.First().Should().Be(fullCategoryDir); } + [TestCase("0")] + [TestCase("15d")] + public void should_set_history_removes_completed_downloads_false(string historyRetention) + { + _config.Misc.history_retention = historyRetention; + + var downloadClientInfo = Subject.GetStatus(); + + downloadClientInfo.RemovesCompletedDownloads.Should().BeFalse(); + } + + [TestCase("-1")] + [TestCase("15")] + [TestCase("3")] + [TestCase("3d")] + public void should_set_history_removes_completed_downloads_true(string historyRetention) + { + _config.Misc.history_retention = historyRetention; + + var downloadClientInfo = Subject.GetStatus(); + + downloadClientInfo.RemovesCompletedDownloads.Should().BeTrue(); + } + [TestCase(@"Y:\sabnzbd\root", @"completed\downloads", @"vv", @"Y:\sabnzbd\root\completed\downloads", @"Y:\sabnzbd\root\completed\downloads\vv")] [TestCase(@"Y:\sabnzbd\root", @"completed", @"vv", @"Y:\sabnzbd\root\completed", @"Y:\sabnzbd\root\completed\vv")] [TestCase(@"/sabnzbd/root", @"completed/downloads", @"vv", @"/sabnzbd/root/completed/downloads", @"/sabnzbd/root/completed/downloads/vv")] diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs index 4395460dc5..c7b8e0d04c 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs @@ -278,7 +278,16 @@ public override DownloadClientInfo GetStatus() status.OutputRootFolders = new List { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, category.FullPath) }; } - status.RemovesCompletedDownloads = config.Misc.history_retention != "0"; + if (config.Misc.history_retention.IsNotNullOrWhiteSpace() && config.Misc.history_retention.EndsWith("d")) + { + int.TryParse(config.Misc.history_retention.AsSpan(0, config.Misc.history_retention.Length - 1), + out var daysRetention); + status.RemovesCompletedDownloads = daysRetention < 14; + } + else + { + status.RemovesCompletedDownloads = config.Misc.history_retention != "0"; + } return status; }