From 78a0def46a4c8628d9bcf6af2701aa35b3f959b9 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Wed, 31 Jul 2024 07:27:19 +0300 Subject: [PATCH] Fixed: Moving files for torrents when Remove Completed is disabled --- .../ImportApprovedEpisodesFixture.cs | 48 ++++++++++++++++++- .../Download/DownloadClientItem.cs | 2 + .../EpisodeImport/ImportApprovedEpisodes.cs | 2 +- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/ImportApprovedEpisodesFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/ImportApprovedEpisodesFixture.cs index 179cf5b3f..86ee8e2dd 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/ImportApprovedEpisodesFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/ImportApprovedEpisodesFixture.cs @@ -74,8 +74,9 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport .Returns(new List()); _downloadClientItem = Builder.CreateNew() - .With(d => d.OutputPath = new OsPath(outputPath)) - .Build(); + .With(d => d.OutputPath = new OsPath(outputPath)) + .With(d => d.DownloadClientInfo = new DownloadClientItemClientInfo()) + .Build(); } private void GivenNewDownload() @@ -201,6 +202,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport GivenNewDownload(); _downloadClientItem.Title = "30.Rock.S01E01"; _downloadClientItem.CanMoveFiles = false; + _downloadClientItem.DownloadClientInfo = null; Subject.Import(new List { _approvedDecisions.First() }, true, _downloadClientItem); @@ -208,6 +210,48 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport .Verify(v => v.UpgradeEpisodeFile(It.IsAny(), _approvedDecisions.First().LocalEpisode, true), Times.Once()); } + [Test] + public void should_copy_when_remove_completed_downloads_is_disabled_and_can_move_files() + { + GivenNewDownload(); + _downloadClientItem.Title = "30.Rock.S01E01"; + _downloadClientItem.CanMoveFiles = true; + _downloadClientItem.DownloadClientInfo.RemoveCompletedDownloads = false; + + Subject.Import(new List { _approvedDecisions.First() }, true, _downloadClientItem); + + Mocker.GetMock() + .Verify(v => v.UpgradeEpisodeFile(It.IsAny(), _approvedDecisions.First().LocalEpisode, true), Times.Once()); + } + + [Test] + public void should_copy_when_remove_completed_downloads_is_enabled_and_cannot_move_files() + { + GivenNewDownload(); + _downloadClientItem.Title = "30.Rock.S01E01"; + _downloadClientItem.CanMoveFiles = false; + _downloadClientItem.DownloadClientInfo.RemoveCompletedDownloads = true; + + Subject.Import(new List { _approvedDecisions.First() }, true, _downloadClientItem); + + Mocker.GetMock() + .Verify(v => v.UpgradeEpisodeFile(It.IsAny(), _approvedDecisions.First().LocalEpisode, true), Times.Once()); + } + + [Test] + public void should_move_when_remove_completed_downloads_is_enabled_and_can_move_files() + { + GivenNewDownload(); + _downloadClientItem.Title = "30.Rock.S01E01"; + _downloadClientItem.CanMoveFiles = true; + _downloadClientItem.DownloadClientInfo.RemoveCompletedDownloads = true; + + Subject.Import(new List { _approvedDecisions.First() }, true, _downloadClientItem); + + Mocker.GetMock() + .Verify(v => v.UpgradeEpisodeFile(It.IsAny(), _approvedDecisions.First().LocalEpisode, false), Times.Once()); + } + [Test] public void should_use_override_importmode() { diff --git a/src/NzbDrone.Core/Download/DownloadClientItem.cs b/src/NzbDrone.Core/Download/DownloadClientItem.cs index 6dd1b6173..76ed0cb2c 100644 --- a/src/NzbDrone.Core/Download/DownloadClientItem.cs +++ b/src/NzbDrone.Core/Download/DownloadClientItem.cs @@ -37,6 +37,7 @@ namespace NzbDrone.Core.Download public string Type { get; set; } public int Id { get; set; } public string Name { get; set; } + public bool RemoveCompletedDownloads { get; set; } public bool HasPostImportCategory { get; set; } public static DownloadClientItemClientInfo FromDownloadClient( @@ -49,6 +50,7 @@ namespace NzbDrone.Core.Download Type = downloadClient.Name, Id = downloadClient.Definition.Id, Name = downloadClient.Definition.Name, + RemoveCompletedDownloads = downloadClient.Definition is DownloadClientDefinition { RemoveCompletedDownloads: true }, HasPostImportCategory = hasPostImportCategory }; } diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs index 739620039..df2198fb1 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs @@ -140,7 +140,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport { default: case ImportMode.Auto: - copyOnly = downloadClientItem != null && !downloadClientItem.CanMoveFiles; + copyOnly = downloadClientItem is { CanMoveFiles: false } or { DownloadClientInfo.RemoveCompletedDownloads: false }; break; case ImportMode.Move: copyOnly = false;