From c669be317fffa252d59851e9a8ca9e56032a01fb Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 19 Apr 2021 22:00:33 -0700 Subject: [PATCH] Fixed: Removing completed download from SABnzbd Closes #4445 --- src/NzbDrone.Api/Queue/QueueActionModule.cs | 2 +- .../Blackhole/TorrentBlackholeFixture.cs | 14 ++++-- .../Blackhole/UsenetBlackholeFixture.cs | 14 ++++-- .../NzbgetTests/NzbgetFixture.cs | 8 +++- .../PneumaticProviderFixture.cs | 8 +++- .../SabnzbdTests/SabnzbdFixture.cs | 13 ++++-- .../Clients/Blackhole/TorrentBlackhole.cs | 4 +- .../Clients/Blackhole/UsenetBlackhole.cs | 4 +- .../Download/Clients/Deluge/Deluge.cs | 4 +- .../DownloadStation/TorrentDownloadStation.cs | 8 ++-- .../DownloadStation/UsenetDownloadStation.cs | 8 ++-- .../Download/Clients/Flood/Flood.cs | 5 +- .../Download/Clients/Hadouken/Hadouken.cs | 6 +-- .../Download/Clients/NzbVortex/NzbVortex.cs | 6 +-- .../Download/Clients/Nzbget/Nzbget.cs | 6 +-- .../Download/Clients/Pneumatic/Pneumatic.cs | 2 +- .../Clients/QBittorrent/QBittorrent.cs | 6 +-- .../Download/Clients/Sabnzbd/Sabnzbd.cs | 46 ++++--------------- .../Clients/Transmission/TransmissionBase.cs | 4 +- .../Download/Clients/Vuze/Vuze.cs | 4 +- .../Download/Clients/rTorrent/RTorrent.cs | 6 +-- .../Download/Clients/uTorrent/UTorrent.cs | 4 +- .../Download/DownloadClientBase.cs | 13 +----- .../Download/DownloadEventHub.cs | 2 +- src/NzbDrone.Core/Download/IDownloadClient.cs | 3 +- src/Sonarr.Api.V3/Queue/QueueActionModule.cs | 2 +- 26 files changed, 98 insertions(+), 104 deletions(-) diff --git a/src/NzbDrone.Api/Queue/QueueActionModule.cs b/src/NzbDrone.Api/Queue/QueueActionModule.cs index 55762eb07..f741b6afa 100644 --- a/src/NzbDrone.Api/Queue/QueueActionModule.cs +++ b/src/NzbDrone.Api/Queue/QueueActionModule.cs @@ -74,7 +74,7 @@ private object Remove(int id) throw new BadRequestException(); } - downloadClient.RemoveItem(trackedDownload.DownloadItem.DownloadId, true); + downloadClient.RemoveItem(trackedDownload.DownloadItem, true); if (blacklist) { diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/TorrentBlackholeFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/TorrentBlackholeFixture.cs index e560617e7..45efcb0d7 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/TorrentBlackholeFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/TorrentBlackholeFixture.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Net; +using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; @@ -25,6 +26,7 @@ public class TorrentBlackholeFixture : DownloadClientFixtureBase + .CreateNew().With(d => d.DownloadId = "_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0") + .Build(); + Mocker.SetConstant(Mocker.Resolve()); Subject.Definition = new DownloadClientDefinition(); @@ -246,7 +252,7 @@ public void RemoveItem_should_delete_file() .Setup(c => c.FileExists(It.IsAny())) .Returns(true); - Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true); + Subject.RemoveItem(_downloadClientItem, true); Mocker.GetMock() .Verify(c => c.DeleteFile(It.IsAny()), Times.Once()); @@ -261,7 +267,7 @@ public void RemoveItem_should_delete_directory() .Setup(c => c.FolderExists(It.IsAny())) .Returns(true); - Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true); + Subject.RemoveItem(_downloadClientItem, true); Mocker.GetMock() .Verify(c => c.DeleteFolder(It.IsAny(), true), Times.Once()); @@ -270,7 +276,7 @@ public void RemoveItem_should_delete_directory() [Test] public void RemoveItem_should_ignore_if_unknown_item() { - Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true); + Subject.RemoveItem(_downloadClientItem, true); Mocker.GetMock() .Verify(c => c.DeleteFile(It.IsAny()), Times.Never()); @@ -284,7 +290,7 @@ public void RemoveItem_should_throw_if_deleteData_is_false() { GivenCompletedItem(); - Assert.Throws(() => Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", false)); + Assert.Throws(() => Subject.RemoveItem(_downloadClientItem, false)); Mocker.GetMock() .Verify(c => c.DeleteFile(It.IsAny()), Times.Never()); diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/UsenetBlackholeFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/UsenetBlackholeFixture.cs index 8d0f3ed8e..ed63fad5b 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/UsenetBlackholeFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/UsenetBlackholeFixture.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Net; +using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; @@ -23,6 +24,7 @@ public class UsenetBlackholeFixture : DownloadClientFixtureBase protected string _completedDownloadFolder; protected string _blackholeFolder; protected string _filePath; + protected DownloadClientItem _downloadClientItem; [SetUp] public void Setup() @@ -31,6 +33,10 @@ public void Setup() _blackholeFolder = @"c:\blackhole\nzb".AsOsAgnostic(); _filePath = (@"c:\blackhole\nzb\" + _title + ".nzb").AsOsAgnostic(); + _downloadClientItem = Builder + .CreateNew().With(d => d.DownloadId = "_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0") + .Build(); + Mocker.SetConstant(Mocker.Resolve()); Subject.Definition = new DownloadClientDefinition(); @@ -146,7 +152,7 @@ public void RemoveItem_should_delete_file() .Setup(c => c.FileExists(It.IsAny())) .Returns(true); - Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true); + Subject.RemoveItem(_downloadClientItem, true); Mocker.GetMock() .Verify(c => c.DeleteFile(It.IsAny()), Times.Once()); @@ -161,7 +167,7 @@ public void RemoveItem_should_delete_directory() .Setup(c => c.FolderExists(It.IsAny())) .Returns(true); - Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true); + Subject.RemoveItem(_downloadClientItem, true); Mocker.GetMock() .Verify(c => c.DeleteFolder(It.IsAny(), true), Times.Once()); @@ -170,7 +176,7 @@ public void RemoveItem_should_delete_directory() [Test] public void RemoveItem_should_ignore_if_unknown_item() { - Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true); + Subject.RemoveItem(_downloadClientItem, true); Mocker.GetMock() .Verify(c => c.DeleteFile(It.IsAny()), Times.Never()); @@ -184,7 +190,7 @@ public void RemoveItem_should_throw_if_deleteData_is_false() { GivenCompletedItem(); - Assert.Throws(() => Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", false)); + Assert.Throws(() => Subject.RemoveItem(_downloadClientItem, false)); Mocker.GetMock() .Verify(c => c.DeleteFile(It.IsAny()), Times.Never()); diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs index 49c128ed5..9448e3aa3 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Collections.Generic; +using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; @@ -20,6 +21,7 @@ public class NzbgetFixture : DownloadClientFixtureBase private NzbgetHistoryItem _failed; private NzbgetHistoryItem _completed; private Dictionary _configItems; + private DownloadClientItem _downloadClientItem; [SetUp] public void Setup() @@ -74,6 +76,10 @@ public void Setup() MarkStatus = "NONE" }; + _downloadClientItem = Builder + .CreateNew().With(d => d.DownloadId = "_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0") + .Build(); + Mocker.GetMock() .Setup(s => s.GetGlobalStatus(It.IsAny())) .Returns(new NzbgetGlobalStatus @@ -156,7 +162,7 @@ public void RemoveItem_should_delete_folder() .Setup(v => v.FolderExists(It.IsAny())) .Returns(true); - Subject.RemoveItem("id", true); + Subject.RemoveItem(_downloadClientItem, true); Mocker.GetMock() .Verify(v => v.DeleteFolder(It.IsAny(), true), Times.Once()); diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs index 0de6b66d8..00d90c438 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Net; +using FizzWare.NBuilder; using Moq; using NUnit.Framework; using NzbDrone.Common.Http; @@ -21,6 +22,7 @@ public class PneumaticProviderFixture : CoreTest private string _strmFolder; private string _nzbPath; private RemoteEpisode _remoteEpisode; + private DownloadClientItem _downloadClientItem; [SetUp] public void Setup() @@ -38,6 +40,10 @@ public void Setup() _remoteEpisode.ParsedEpisodeInfo = new ParsedEpisodeInfo(); _remoteEpisode.ParsedEpisodeInfo.FullSeason = false; + _downloadClientItem = Builder + .CreateNew().With(d => d.DownloadId = "_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0") + .Build(); + Subject.Definition = new DownloadClientDefinition(); Subject.Definition.Settings = new PneumaticSettings { @@ -79,7 +85,7 @@ public void should_throw_if_full_season_download() [Test] public void should_throw_item_is_removed() { - Assert.Throws(() => Subject.RemoveItem("", true)); + Assert.Throws(() => Subject.RemoveItem(_downloadClientItem, true)); } [Test] diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs index 8865159d3..137e8f4d2 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs @@ -24,6 +24,7 @@ public class SabnzbdFixture : DownloadClientFixtureBase private SabnzbdHistory _completed; private SabnzbdConfig _config; private SabnzbdFullStatus _fullStatus; + private DownloadClientItem _downloadClientItem; [SetUp] public void Setup() @@ -101,6 +102,10 @@ public void Setup() } }; + _downloadClientItem = Builder + .CreateNew().With(d => d.DownloadId = _completed.Items.First().Id) + .Build(); + Mocker.GetMock() .Setup(v => v.GetVersion(It.IsAny())) .Returns("1.2.3"); @@ -591,7 +596,7 @@ public void should_remove_output_path_folder_when_deleting_a_completed_item_and_ GivenQueue(null); GivenHistory(_completed); - Subject.RemoveItem(_completed.Items.First().Id, true); + Subject.RemoveItem(_downloadClientItem, true); Mocker.GetMock() .Verify(v => v.DeleteFolder(path, true), Times.Once); @@ -618,7 +623,7 @@ public void should_remove_output_path_file_when_deleting_a_completed_item_and_de GivenQueue(null); GivenHistory(_completed); - Subject.RemoveItem(_completed.Items.First().Id, true); + Subject.RemoveItem(_downloadClientItem, true); Mocker.GetMock() .Verify(v => v.DeleteFolder(path, true), Times.Never); @@ -645,7 +650,7 @@ public void should_not_remove_output_path_file_when_deleting_a_completed_item_an GivenQueue(null); GivenHistory(_completed); - Subject.RemoveItem(_completed.Items.First().Id, true); + Subject.RemoveItem(_downloadClientItem, true); Mocker.GetMock() .Verify(v => v.DeleteFolder(path, true), Times.Never); @@ -672,7 +677,7 @@ public void should_not_remove_output_path_file_when_deleting_a_completed_item_an GivenQueue(null); GivenHistory(_completed); - Subject.RemoveItem(_completed.Items.First().Id, false); + Subject.RemoveItem(_downloadClientItem, false); Mocker.GetMock() .Verify(v => v.FolderExists(path), Times.Never); diff --git a/src/NzbDrone.Core/Download/Clients/Blackhole/TorrentBlackhole.cs b/src/NzbDrone.Core/Download/Clients/Blackhole/TorrentBlackhole.cs index 1d6395751..f40b1f237 100644 --- a/src/NzbDrone.Core/Download/Clients/Blackhole/TorrentBlackhole.cs +++ b/src/NzbDrone.Core/Download/Clients/Blackhole/TorrentBlackhole.cs @@ -106,14 +106,14 @@ public override IEnumerable GetItems() } } - public override void RemoveItem(string downloadId, bool deleteData) + public override void RemoveItem(DownloadClientItem item, bool deleteData) { if (!deleteData) { throw new NotSupportedException("Blackhole cannot remove DownloadItem without deleting the data as well, ignoring."); } - DeleteItemData(downloadId); + DeleteItemData(item); } public override DownloadClientInfo GetStatus() diff --git a/src/NzbDrone.Core/Download/Clients/Blackhole/UsenetBlackhole.cs b/src/NzbDrone.Core/Download/Clients/Blackhole/UsenetBlackhole.cs index 0d89b48a6..5fbc74a74 100644 --- a/src/NzbDrone.Core/Download/Clients/Blackhole/UsenetBlackhole.cs +++ b/src/NzbDrone.Core/Download/Clients/Blackhole/UsenetBlackhole.cs @@ -77,14 +77,14 @@ public override IEnumerable GetItems() } } - public override void RemoveItem(string downloadId, bool deleteData) + public override void RemoveItem(DownloadClientItem item, bool deleteData) { if (!deleteData) { throw new NotSupportedException("Blackhole cannot remove DownloadItem without deleting the data as well, ignoring."); } - DeleteItemData(downloadId); + DeleteItemData(item); } public override DownloadClientInfo GetStatus() diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs b/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs index 91d421529..5e7c9954c 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs @@ -184,9 +184,9 @@ public override IEnumerable GetItems() return items; } - public override void RemoveItem(string downloadId, bool deleteData) + public override void RemoveItem(DownloadClientItem item, bool deleteData) { - _proxy.RemoveTorrent(downloadId.ToLower(), deleteData, Settings); + _proxy.RemoveTorrent(item.DownloadId.ToLower(), deleteData, Settings); } public override DownloadClientInfo GetStatus() diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs index 07ff72c42..2e4bfa067 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs @@ -129,15 +129,15 @@ public override DownloadClientInfo GetStatus() } } - public override void RemoveItem(string downloadId, bool deleteData) + public override void RemoveItem(DownloadClientItem item, bool deleteData) { if (deleteData) { - DeleteItemData(downloadId); + DeleteItemData(item); } - _dsTaskProxy.RemoveTask(ParseDownloadId(downloadId), Settings); - _logger.Debug("{0} removed correctly", downloadId); + _dsTaskProxy.RemoveTask(ParseDownloadId(item.DownloadId), Settings); + _logger.Debug("{0} removed correctly", item.DownloadId); } protected OsPath GetOutputPath(OsPath outputPath, DownloadStationTask torrent, string serialNumber) diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs index ea2b4d8b8..fa470562b 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs @@ -154,15 +154,15 @@ public override DownloadClientInfo GetStatus() } } - public override void RemoveItem(string downloadId, bool deleteData) + public override void RemoveItem(DownloadClientItem item, bool deleteData) { if (deleteData) { - DeleteItemData(downloadId); + DeleteItemData(item); } - _dsTaskProxy.RemoveTask(ParseDownloadId(downloadId), Settings); - _logger.Debug("{0} removed correctly", downloadId); + _dsTaskProxy.RemoveTask(ParseDownloadId(item.DownloadId), Settings); + _logger.Debug("{0} removed correctly", item.DownloadId); } protected override string AddFromNzbFile(RemoteEpisode remoteEpisode, string filename, byte[] fileContent) diff --git a/src/NzbDrone.Core/Download/Clients/Flood/Flood.cs b/src/NzbDrone.Core/Download/Clients/Flood/Flood.cs index 0bd624ba6..a9cf03b22 100644 --- a/src/NzbDrone.Core/Download/Clients/Flood/Flood.cs +++ b/src/NzbDrone.Core/Download/Clients/Flood/Flood.cs @@ -200,9 +200,10 @@ public override void MarkItemAsImported(DownloadClientItem downloadClientItem) } } - public override void RemoveItem(string downloadId, bool deleteData) + public override void RemoveItem(DownloadClientItem item, bool deleteData) { - _proxy.DeleteTorrent(downloadId, deleteData, Settings); + _proxy.DeleteTorrent(item.DownloadId, deleteData, Settings); + _proxy.DeleteTorrent(item.DownloadId, deleteData, Settings); } public override DownloadClientInfo GetStatus() diff --git a/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs b/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs index fa5ee215c..3f37addca 100644 --- a/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs +++ b/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs @@ -97,15 +97,15 @@ public override IEnumerable GetItems() return items; } - public override void RemoveItem(string downloadId, bool deleteData) + public override void RemoveItem(DownloadClientItem item, bool deleteData) { if (deleteData) { - _proxy.RemoveTorrentAndData(Settings, downloadId); + _proxy.RemoveTorrentAndData(Settings, item.DownloadId); } else { - _proxy.RemoveTorrent(Settings, downloadId); + _proxy.RemoveTorrent(Settings, item.DownloadId); } } diff --git a/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs b/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs index 769dc0e82..c47d819ca 100644 --- a/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs +++ b/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs @@ -106,12 +106,12 @@ public override IEnumerable GetItems() return queueItems; } - public override void RemoveItem(string downloadId, bool deleteData) + public override void RemoveItem(DownloadClientItem item, bool deleteData) { // Try to find the download by numerical ID, otherwise try by AddUUID int id; - if (int.TryParse(downloadId, out id)) + if (int.TryParse(item.DownloadId, out id)) { _proxy.Remove(id, deleteData, Settings); } @@ -119,7 +119,7 @@ public override void RemoveItem(string downloadId, bool deleteData) else { var queue = _proxy.GetQueue(30, Settings); - var queueItem = queue.FirstOrDefault(c => c.AddUUID == downloadId); + var queueItem = queue.FirstOrDefault(c => c.AddUUID == item.DownloadId); if (queueItem != null) { diff --git a/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs b/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs index d9645c0e1..7a46c0a31 100644 --- a/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs +++ b/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs @@ -191,14 +191,14 @@ public override IEnumerable GetItems() return GetQueue().Concat(GetHistory()).Where(downloadClientItem => downloadClientItem.Category == Settings.TvCategory); } - public override void RemoveItem(string downloadId, bool deleteData) + public override void RemoveItem(DownloadClientItem item, bool deleteData) { if (deleteData) { - DeleteItemData(downloadId); + DeleteItemData(item); } - _proxy.RemoveItem(downloadId, Settings); + _proxy.RemoveItem(item.DownloadId, Settings); } public override DownloadClientInfo GetStatus() diff --git a/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs b/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs index 38c6a54aa..97730ee74 100644 --- a/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs +++ b/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs @@ -98,7 +98,7 @@ public override IEnumerable GetItems() } } - public override void RemoveItem(string downloadId, bool deleteData) + public override void RemoveItem(DownloadClientItem item, bool deleteData) { throw new NotSupportedException(); } diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs index 92d592d45..953d37819 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs @@ -154,7 +154,7 @@ protected override string AddFromTorrentFile(RemoteEpisode remoteEpisode, string { _logger.Warn(ex, "Failed to set the torrent seed criteria for {0}.", hash); } - } + } if (moveToTop) { @@ -313,9 +313,9 @@ public override IEnumerable GetItems() return queueItems; } - public override void RemoveItem(string hash, bool deleteData) + public override void RemoveItem(DownloadClientItem item, bool deleteData) { - Proxy.RemoveTorrent(hash.ToLower(), deleteData, Settings); + Proxy.RemoveTorrent(item.DownloadId.ToLower(), deleteData, Settings); } public override DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt) diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs index 0ed069f14..c0f859ce8 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs @@ -191,48 +191,22 @@ public override IEnumerable GetItems() } } - public override void RemoveItem(string downloadId, bool deleteData) + public override void RemoveItem(DownloadClientItem item, bool deleteData) { - var historyItem = GetHistory().SingleOrDefault(v => v.DownloadId == downloadId); + var queueClientItem = GetQueue().SingleOrDefault(v => v.DownloadId == item.DownloadId); - if (historyItem == null) + if (queueClientItem == null) { - _proxy.RemoveFrom("queue", downloadId, deleteData, Settings); + if (deleteData && item.Status == DownloadItemStatus.Completed) + { + DeleteItemData(item); + } + + _proxy.RemoveFrom("history", item.DownloadId, deleteData, Settings); } else { - _proxy.RemoveFrom("history", downloadId, deleteData, Settings); - - // Completed items in SAB's history do not remove the files from the file system when deleted, even if instructed to. - // If the output path is valid delete the file(s), otherwise warn that they cannot be deleted. - - if (deleteData && historyItem.Status == DownloadItemStatus.Completed) - { - if (ValidatePath(historyItem)) - { - var outputPath = historyItem.OutputPath; - - try - { - if (_diskProvider.FolderExists(outputPath.FullPath)) - { - _diskProvider.DeleteFolder(outputPath.FullPath.ToString(), true); - } - else if (_diskProvider.FileExists(outputPath.FullPath)) - { - _diskProvider.DeleteFile(outputPath.FullPath.ToString()); - } - } - catch (Exception e) - { - _logger.Error("Unable to delete output path: '{0}'. Delete file(s) manually", outputPath.FullPath); - } - } - else - { - _logger.Warn("Invalid path '{0}'. Delete file(s) manually"); - } - } + _proxy.RemoveFrom("queue", item.DownloadId, deleteData, Settings); } } diff --git a/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs b/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs index 945276457..2888c96a2 100644 --- a/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs +++ b/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs @@ -148,9 +148,9 @@ protected bool HasReachedSeedLimit(TransmissionTorrent torrent, double? ratio, L return false; } - public override void RemoveItem(string downloadId, bool deleteData) + public override void RemoveItem(DownloadClientItem item, bool deleteData) { - _proxy.RemoveTorrent(downloadId.ToLower(), deleteData, Settings); + _proxy.RemoveTorrent(item.DownloadId.ToLower(), deleteData, Settings); } public override DownloadClientInfo GetStatus() diff --git a/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs b/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs index ac355204c..93ca1edfc 100644 --- a/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs +++ b/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs @@ -24,9 +24,9 @@ public Vuze(ITransmissionProxy proxy, { } - public override void RemoveItem(string downloadId, bool deleteData) + public override void RemoveItem(DownloadClientItem item, bool deleteData) { - _proxy.RemoveTorrent(downloadId, deleteData, Settings); + _proxy.RemoveTorrent(item.DownloadId, deleteData, Settings); } protected override OsPath GetOutputPath(OsPath outputPath, TransmissionTorrent torrent) diff --git a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs index ddd41f435..2d13b251e 100644 --- a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs @@ -156,14 +156,14 @@ public override IEnumerable GetItems() return items; } - public override void RemoveItem(string downloadId, bool deleteData) + public override void RemoveItem(DownloadClientItem item, bool deleteData) { if (deleteData) { - DeleteItemData(downloadId); + DeleteItemData(item); } - _proxy.RemoveTorrent(downloadId, Settings); + _proxy.RemoveTorrent(item.DownloadId, Settings); } public override DownloadClientInfo GetStatus() diff --git a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs index 429cec5dd..391ef1876 100644 --- a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs @@ -206,9 +206,9 @@ private List GetTorrents() return torrents; } - public override void RemoveItem(string downloadId, bool deleteData) + public override void RemoveItem(DownloadClientItem item, bool deleteData) { - _proxy.RemoveTorrent(downloadId, deleteData, Settings); + _proxy.RemoveTorrent(item.DownloadId, deleteData, Settings); } public override DownloadClientInfo GetStatus() diff --git a/src/NzbDrone.Core/Download/DownloadClientBase.cs b/src/NzbDrone.Core/Download/DownloadClientBase.cs index 3746b4698..99c11c0d0 100644 --- a/src/NzbDrone.Core/Download/DownloadClientBase.cs +++ b/src/NzbDrone.Core/Download/DownloadClientBase.cs @@ -1,10 +1,8 @@ using System; -using System.Linq; using System.Collections.Generic; using FluentValidation.Results; using NLog; using NzbDrone.Common.Disk; -using NzbDrone.Common.Extensions; using NzbDrone.Core.Configuration; using NzbDrone.Core.Indexers; using NzbDrone.Core.Parser.Model; @@ -65,20 +63,13 @@ public virtual DownloadClientItem GetImportItem(DownloadClientItem item, Downloa return item; } - public abstract void RemoveItem(string downloadId, bool deleteData); + public abstract void RemoveItem(DownloadClientItem item, bool deleteData); public abstract DownloadClientInfo GetStatus(); - protected virtual void DeleteItemData(string downloadId) + protected virtual void DeleteItemData(DownloadClientItem item) { - if (downloadId.IsNullOrWhiteSpace()) - { - return; - } - - var item = GetItems().FirstOrDefault(v => v.DownloadId == downloadId); if (item == null) { - _logger.Trace("DownloadItem {0} in {1} history not found, skipping delete data.", downloadId, Name); return; } diff --git a/src/NzbDrone.Core/Download/DownloadEventHub.cs b/src/NzbDrone.Core/Download/DownloadEventHub.cs index eab0c6fdc..3feb31cd5 100644 --- a/src/NzbDrone.Core/Download/DownloadEventHub.cs +++ b/src/NzbDrone.Core/Download/DownloadEventHub.cs @@ -62,7 +62,7 @@ private void RemoveFromDownloadClient(TrackedDownload trackedDownload) try { _logger.Debug("[{0}] Removing download from {1} history", trackedDownload.DownloadItem.Title, trackedDownload.DownloadItem.DownloadClientInfo.Name); - downloadClient.RemoveItem(trackedDownload.DownloadItem.DownloadId, true); + downloadClient.RemoveItem(trackedDownload.DownloadItem, true); trackedDownload.DownloadItem.Removed = true; } catch (NotSupportedException) diff --git a/src/NzbDrone.Core/Download/IDownloadClient.cs b/src/NzbDrone.Core/Download/IDownloadClient.cs index 108f79f15..612ba79c3 100644 --- a/src/NzbDrone.Core/Download/IDownloadClient.cs +++ b/src/NzbDrone.Core/Download/IDownloadClient.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using NzbDrone.Common.Disk; using NzbDrone.Core.Indexers; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.ThingiProvider; @@ -12,7 +11,7 @@ public interface IDownloadClient : IProvider string Download(RemoteEpisode remoteEpisode); IEnumerable GetItems(); DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt); - void RemoveItem(string downloadId, bool deleteData); + void RemoveItem(DownloadClientItem item, bool deleteData); DownloadClientInfo GetStatus(); void MarkItemAsImported(DownloadClientItem downloadClientItem); } diff --git a/src/Sonarr.Api.V3/Queue/QueueActionModule.cs b/src/Sonarr.Api.V3/Queue/QueueActionModule.cs index ea6f77bb3..7796a286f 100644 --- a/src/Sonarr.Api.V3/Queue/QueueActionModule.cs +++ b/src/Sonarr.Api.V3/Queue/QueueActionModule.cs @@ -143,7 +143,7 @@ private TrackedDownload Remove(int id, bool removeFromClient, bool blacklist) throw new BadRequestException(); } - downloadClient.RemoveItem(trackedDownload.DownloadItem.DownloadId, true); + downloadClient.RemoveItem(trackedDownload.DownloadItem, true); } if (blacklist)