From 12ca04b2986dbfbf1e5cfc49a2f11e2687db54cd 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 (cherry picked from commit 78a0def46a4c8628d9bcf6af2701aa35b3f959b9) --- .../ImportApprovedMoviesFixture.cs | 48 ++++++++++++++++++- .../Download/DownloadClientItem.cs | 2 + .../MovieImport/ImportApprovedMovie.cs | 2 +- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core.Test/MediaFiles/MovieImport/ImportApprovedMoviesFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/MovieImport/ImportApprovedMoviesFixture.cs index f9ed898d8..022fac29a 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/MovieImport/ImportApprovedMoviesFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/MovieImport/ImportApprovedMoviesFixture.cs @@ -67,8 +67,9 @@ public void Setup() .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() @@ -193,6 +194,7 @@ public void should_copy_when_cannot_move_files_downloads() GivenNewDownload(); _downloadClientItem.Title = "30.Rock.S01E01"; _downloadClientItem.CanMoveFiles = false; + _downloadClientItem.DownloadClientInfo = null; Subject.Import(new List { _approvedDecisions.First() }, true, _downloadClientItem); @@ -200,6 +202,48 @@ public void should_copy_when_cannot_move_files_downloads() .Verify(v => v.UpgradeMovieFile(It.IsAny(), _approvedDecisions.First().LocalMovie, 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 c32afa1e3..720cb3055 100644 --- a/src/NzbDrone.Core/Download/DownloadClientItem.cs +++ b/src/NzbDrone.Core/Download/DownloadClientItem.cs @@ -38,6 +38,7 @@ public class DownloadClientItemClientInfo 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( @@ -50,6 +51,7 @@ public static DownloadClientItemClientInfo FromDownloadClient( 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/MovieImport/ImportApprovedMovie.cs b/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs index 56016dda6..879bbc10f 100644 --- a/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs +++ b/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs @@ -118,7 +118,7 @@ public List Import(List decisions, bool newDownloa { default: case ImportMode.Auto: - copyOnly = downloadClientItem != null && !downloadClientItem.CanMoveFiles; + copyOnly = downloadClientItem is { CanMoveFiles: false } or { DownloadClientInfo.RemoveCompletedDownloads: false }; break; case ImportMode.Move: copyOnly = false;