1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-09-17 15:02:34 +02:00

Fixed: Removing completed download from SABnzbd

Closes #4445

(cherry picked from commit c669be317fffa252d59851e9a8ca9e56032a01fb)
This commit is contained in:
Mark McDowall 2021-04-19 22:00:33 -07:00 committed by Robin Dadswell
parent 9bf872c9fa
commit efdb9c20d4
26 changed files with 99 additions and 102 deletions

View File

@ -71,7 +71,7 @@ private object Remove(int id)
throw new BadRequestException(); throw new BadRequestException();
} }
downloadClient.RemoveItem(trackedDownload.DownloadItem.DownloadId, true); downloadClient.RemoveItem(trackedDownload.DownloadItem, true);
if (blacklist) if (blacklist)
{ {

View File

@ -3,6 +3,7 @@
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
@ -25,6 +26,7 @@ public class TorrentBlackholeFixture : DownloadClientFixtureBase<TorrentBlackhol
protected string _blackholeFolder; protected string _blackholeFolder;
protected string _filePath; protected string _filePath;
protected string _magnetFilePath; protected string _magnetFilePath;
protected DownloadClientItem _downloadClientItem;
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -34,6 +36,10 @@ public void Setup()
_filePath = (@"c:\blackhole\torrent\" + _title + ".torrent").AsOsAgnostic(); _filePath = (@"c:\blackhole\torrent\" + _title + ".torrent").AsOsAgnostic();
_magnetFilePath = Path.ChangeExtension(_filePath, ".magnet"); _magnetFilePath = Path.ChangeExtension(_filePath, ".magnet");
_downloadClientItem = Builder<DownloadClientItem>
.CreateNew().With(d => d.DownloadId = "_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0")
.Build();
Mocker.SetConstant<IScanWatchFolder>(Mocker.Resolve<ScanWatchFolder>()); Mocker.SetConstant<IScanWatchFolder>(Mocker.Resolve<ScanWatchFolder>());
Subject.Definition = new DownloadClientDefinition(); Subject.Definition = new DownloadClientDefinition();
@ -246,7 +252,7 @@ public void RemoveItem_should_delete_file()
.Setup(c => c.FileExists(It.IsAny<string>())) .Setup(c => c.FileExists(It.IsAny<string>()))
.Returns(true); .Returns(true);
Subject.RemoveItem("_Droned.1998.1080p.WEB-DL-DRONE_0", true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Once()); .Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Once());
@ -261,7 +267,7 @@ public void RemoveItem_should_delete_directory()
.Setup(c => c.FolderExists(It.IsAny<string>())) .Setup(c => c.FolderExists(It.IsAny<string>()))
.Returns(true); .Returns(true);
Subject.RemoveItem("_Droned.1998.1080p.WEB-DL-DRONE_0", true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFolder(It.IsAny<string>(), true), Times.Once()); .Verify(c => c.DeleteFolder(It.IsAny<string>(), true), Times.Once());
@ -270,7 +276,7 @@ public void RemoveItem_should_delete_directory()
[Test] [Test]
public void RemoveItem_should_ignore_if_unknown_item() public void RemoveItem_should_ignore_if_unknown_item()
{ {
Subject.RemoveItem("_Droned.1998.1080p.WEB-DL-DRONE_0", true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never()); .Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never());
@ -284,7 +290,7 @@ public void RemoveItem_should_throw_if_deleteData_is_false()
{ {
GivenCompletedItem(); GivenCompletedItem();
Assert.Throws<NotSupportedException>(() => Subject.RemoveItem("_Droned.1998.1080p.WEB-DL-DRONE_0", false)); Assert.Throws<NotSupportedException>(() => Subject.RemoveItem(_downloadClientItem, false));
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never()); .Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never());

View File

@ -3,6 +3,7 @@
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
@ -21,6 +22,7 @@ public class UsenetBlackholeFixture : DownloadClientFixtureBase<UsenetBlackhole>
protected string _completedDownloadFolder; protected string _completedDownloadFolder;
protected string _blackholeFolder; protected string _blackholeFolder;
protected string _filePath; protected string _filePath;
protected DownloadClientItem _downloadClientItem;
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -29,6 +31,10 @@ public void Setup()
_blackholeFolder = @"c:\blackhole\nzb".AsOsAgnostic(); _blackholeFolder = @"c:\blackhole\nzb".AsOsAgnostic();
_filePath = (@"c:\blackhole\nzb\" + _title + ".nzb").AsOsAgnostic(); _filePath = (@"c:\blackhole\nzb\" + _title + ".nzb").AsOsAgnostic();
_downloadClientItem = Builder<DownloadClientItem>
.CreateNew().With(d => d.DownloadId = "_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0")
.Build();
Mocker.SetConstant<IScanWatchFolder>(Mocker.Resolve<ScanWatchFolder>()); Mocker.SetConstant<IScanWatchFolder>(Mocker.Resolve<ScanWatchFolder>());
Subject.Definition = new DownloadClientDefinition(); Subject.Definition = new DownloadClientDefinition();
@ -143,7 +149,7 @@ public void RemoveItem_should_delete_file()
.Setup(c => c.FileExists(It.IsAny<string>())) .Setup(c => c.FileExists(It.IsAny<string>()))
.Returns(true); .Returns(true);
Subject.RemoveItem("_Droned.1998.1080p.WEB-DL-DRONE_0", true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Once()); .Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Once());
@ -158,7 +164,7 @@ public void RemoveItem_should_delete_directory()
.Setup(c => c.FolderExists(It.IsAny<string>())) .Setup(c => c.FolderExists(It.IsAny<string>()))
.Returns(true); .Returns(true);
Subject.RemoveItem("_Droned.1998.1080p.WEB-DL-DRONE_0", true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFolder(It.IsAny<string>(), true), Times.Once()); .Verify(c => c.DeleteFolder(It.IsAny<string>(), true), Times.Once());
@ -167,7 +173,7 @@ public void RemoveItem_should_delete_directory()
[Test] [Test]
public void RemoveItem_should_ignore_if_unknown_item() public void RemoveItem_should_ignore_if_unknown_item()
{ {
Subject.RemoveItem("_Droned.1998.1080p.WEB-DL-DRONE_0", true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never()); .Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never());
@ -181,7 +187,7 @@ public void RemoveItem_should_throw_if_deleteData_is_false()
{ {
GivenCompletedItem(); GivenCompletedItem();
Assert.Throws<NotSupportedException>(() => Subject.RemoveItem("_Droned.1998.1080p.WEB-DL-DRONE_0", false)); Assert.Throws<NotSupportedException>(() => Subject.RemoveItem(_downloadClientItem, false));
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never()); .Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never());

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
@ -20,6 +21,7 @@ public class NzbgetFixture : DownloadClientFixtureBase<Nzbget>
private NzbgetHistoryItem _failed; private NzbgetHistoryItem _failed;
private NzbgetHistoryItem _completed; private NzbgetHistoryItem _completed;
private Dictionary<string, string> _configItems; private Dictionary<string, string> _configItems;
private DownloadClientItem _downloadClientItem;
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -74,6 +76,10 @@ public void Setup()
MarkStatus = "NONE" MarkStatus = "NONE"
}; };
_downloadClientItem = Builder<DownloadClientItem>
.CreateNew().With(d => d.DownloadId = "_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0")
.Build();
Mocker.GetMock<INzbgetProxy>() Mocker.GetMock<INzbgetProxy>()
.Setup(s => s.GetGlobalStatus(It.IsAny<NzbgetSettings>())) .Setup(s => s.GetGlobalStatus(It.IsAny<NzbgetSettings>()))
.Returns(new NzbgetGlobalStatus .Returns(new NzbgetGlobalStatus
@ -155,7 +161,7 @@ public void RemoveItem_should_delete_folder()
.Setup(v => v.FolderExists(It.IsAny<string>())) .Setup(v => v.FolderExists(It.IsAny<string>()))
.Returns(true); .Returns(true);
Subject.RemoveItem("id", true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Once()); .Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Once());

View File

@ -1,6 +1,7 @@
using System; using System;
using System.IO; using System.IO;
using System.Net; using System.Net;
using FizzWare.NBuilder;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Http; using NzbDrone.Common.Http;
@ -21,6 +22,7 @@ public class PneumaticProviderFixture : CoreTest<Pneumatic>
private string _strmFolder; private string _strmFolder;
private string _nzbPath; private string _nzbPath;
private RemoteMovie _remoteMovie; private RemoteMovie _remoteMovie;
private DownloadClientItem _downloadClientItem;
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -37,6 +39,10 @@ public void Setup()
_remoteMovie.ParsedMovieInfo = new ParsedMovieInfo(); _remoteMovie.ParsedMovieInfo = new ParsedMovieInfo();
_downloadClientItem = Builder<DownloadClientItem>
.CreateNew().With(d => d.DownloadId = "_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0")
.Build();
Subject.Definition = new DownloadClientDefinition(); Subject.Definition = new DownloadClientDefinition();
Subject.Definition.Settings = new PneumaticSettings Subject.Definition.Settings = new PneumaticSettings
{ {
@ -69,7 +75,7 @@ public void should_throw_on_failed_download()
[Test] [Test]
public void should_throw_item_is_removed() public void should_throw_item_is_removed()
{ {
Assert.Throws<NotSupportedException>(() => Subject.RemoveItem("", true)); Assert.Throws<NotSupportedException>(() => Subject.RemoveItem(_downloadClientItem, true));
} }
[Test] [Test]

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
@ -22,6 +23,7 @@ public class SabnzbdFixture : DownloadClientFixtureBase<Sabnzbd>
private SabnzbdHistory _completed; private SabnzbdHistory _completed;
private SabnzbdConfig _config; private SabnzbdConfig _config;
private SabnzbdFullStatus _fullStatus; private SabnzbdFullStatus _fullStatus;
private DownloadClientItem _downloadClientItem;
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -99,6 +101,10 @@ public void Setup()
} }
}; };
_downloadClientItem = Builder<DownloadClientItem>
.CreateNew().With(d => d.DownloadId = _completed.Items.First().Id)
.Build();
Mocker.GetMock<ISabnzbdProxy>() Mocker.GetMock<ISabnzbdProxy>()
.Setup(v => v.GetVersion(It.IsAny<SabnzbdSettings>())) .Setup(v => v.GetVersion(It.IsAny<SabnzbdSettings>()))
.Returns("1.2.3"); .Returns("1.2.3");
@ -592,7 +598,7 @@ public void should_remove_output_path_folder_when_deleting_a_completed_item_and_
GivenQueue(null); GivenQueue(null);
GivenHistory(_completed); GivenHistory(_completed);
Subject.RemoveItem(_completed.Items.First().Id, true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(path, true), Times.Once); .Verify(v => v.DeleteFolder(path, true), Times.Once);
@ -619,7 +625,7 @@ public void should_remove_output_path_file_when_deleting_a_completed_item_and_de
GivenQueue(null); GivenQueue(null);
GivenHistory(_completed); GivenHistory(_completed);
Subject.RemoveItem(_completed.Items.First().Id, true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(path, true), Times.Never); .Verify(v => v.DeleteFolder(path, true), Times.Never);
@ -646,7 +652,7 @@ public void should_not_remove_output_path_file_when_deleting_a_completed_item_an
GivenQueue(null); GivenQueue(null);
GivenHistory(_completed); GivenHistory(_completed);
Subject.RemoveItem(_completed.Items.First().Id, true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(path, true), Times.Never); .Verify(v => v.DeleteFolder(path, true), Times.Never);
@ -673,7 +679,7 @@ public void should_not_remove_output_path_file_when_deleting_a_completed_item_an
GivenQueue(null); GivenQueue(null);
GivenHistory(_completed); GivenHistory(_completed);
Subject.RemoveItem(_completed.Items.First().Id, false); Subject.RemoveItem(_downloadClientItem, false);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(v => v.FolderExists(path), Times.Never); .Verify(v => v.FolderExists(path), Times.Never);

View File

@ -106,14 +106,14 @@ public override IEnumerable<DownloadClientItem> GetItems()
} }
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
if (!deleteData) if (!deleteData)
{ {
throw new NotSupportedException("Blackhole cannot remove DownloadItem without deleting the data as well, ignoring."); throw new NotSupportedException("Blackhole cannot remove DownloadItem without deleting the data as well, ignoring.");
} }
DeleteItemData(downloadId); DeleteItemData(item);
} }
public override DownloadClientInfo GetStatus() public override DownloadClientInfo GetStatus()

View File

@ -78,14 +78,14 @@ public override IEnumerable<DownloadClientItem> GetItems()
} }
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
if (!deleteData) if (!deleteData)
{ {
throw new NotSupportedException("Blackhole cannot remove DownloadItem without deleting the data as well, ignoring."); throw new NotSupportedException("Blackhole cannot remove DownloadItem without deleting the data as well, ignoring.");
} }
DeleteItemData(downloadId); DeleteItemData(item);
} }
public override DownloadClientInfo GetStatus() public override DownloadClientInfo GetStatus()

View File

@ -190,9 +190,9 @@ public override IEnumerable<DownloadClientItem> GetItems()
return items; 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() public override DownloadClientInfo GetStatus()

View File

@ -134,15 +134,15 @@ public override DownloadClientInfo GetStatus()
} }
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
if (deleteData) if (deleteData)
{ {
DeleteItemData(downloadId); DeleteItemData(item);
} }
_dsTaskProxy.RemoveTask(ParseDownloadId(downloadId), Settings); _dsTaskProxy.RemoveTask(ParseDownloadId(item.DownloadId), Settings);
_logger.Debug("{0} removed correctly", downloadId); _logger.Debug("{0} removed correctly", item.DownloadId);
} }
protected OsPath GetOutputPath(OsPath outputPath, DownloadStationTask torrent, string serialNumber) protected OsPath GetOutputPath(OsPath outputPath, DownloadStationTask torrent, string serialNumber)

View File

@ -158,15 +158,15 @@ public override DownloadClientInfo GetStatus()
} }
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
if (deleteData) if (deleteData)
{ {
DeleteItemData(downloadId); DeleteItemData(item);
} }
_dsTaskProxy.RemoveTask(ParseDownloadId(downloadId), Settings); _dsTaskProxy.RemoveTask(ParseDownloadId(item.DownloadId), Settings);
_logger.Debug("{0} removed correctly", downloadId); _logger.Debug("{0} removed correctly", item.DownloadId);
} }
protected override string AddFromNzbFile(RemoteMovie remoteMovie, string filename, byte[] fileContent) protected override string AddFromNzbFile(RemoteMovie remoteMovie, string filename, byte[] fileContent)

View File

@ -201,9 +201,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() public override DownloadClientInfo GetStatus()

View File

@ -109,15 +109,15 @@ public override IEnumerable<DownloadClientItem> GetItems()
return items; return items;
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
if (deleteData) if (deleteData)
{ {
_proxy.RemoveTorrentAndData(Settings, downloadId); _proxy.RemoveTorrentAndData(Settings, item.DownloadId);
} }
else else
{ {
_proxy.RemoveTorrent(Settings, downloadId); _proxy.RemoveTorrent(Settings, item.DownloadId);
} }
} }

View File

@ -121,19 +121,19 @@ public override IEnumerable<DownloadClientItem> GetItems()
return queueItems; 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 // Try to find the download by numerical ID, otherwise try by AddUUID
int id; int id;
if (int.TryParse(downloadId, out id)) if (int.TryParse(item.DownloadId, out id))
{ {
_proxy.Remove(id, deleteData, Settings); _proxy.Remove(id, deleteData, Settings);
} }
else else
{ {
var queue = _proxy.GetQueue(30, Settings); 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) if (queueItem != null)
{ {

View File

@ -195,14 +195,14 @@ public override IEnumerable<DownloadClientItem> GetItems()
return GetQueue().Concat(GetHistory()).Where(downloadClientItem => downloadClientItem.Category == Settings.MovieCategory); return GetQueue().Concat(GetHistory()).Where(downloadClientItem => downloadClientItem.Category == Settings.MovieCategory);
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
if (deleteData) if (deleteData)
{ {
DeleteItemData(downloadId); DeleteItemData(item);
} }
_proxy.RemoveItem(downloadId, Settings); _proxy.RemoveItem(item.DownloadId, Settings);
} }
public override DownloadClientInfo GetStatus() public override DownloadClientInfo GetStatus()

View File

@ -98,7 +98,7 @@ public override IEnumerable<DownloadClientItem> GetItems()
} }
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }

View File

@ -155,7 +155,7 @@ protected override string AddFromTorrentFile(RemoteMovie remoteMovie, string has
{ {
_logger.Warn(ex, "Failed to set the torrent seed criteria for {0}.", hash); _logger.Warn(ex, "Failed to set the torrent seed criteria for {0}.", hash);
} }
} }
if (moveToTop) if (moveToTop)
{ {
@ -320,9 +320,9 @@ public override IEnumerable<DownloadClientItem> GetItems()
return queueItems; 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) public override DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt)

View File

@ -194,47 +194,22 @@ public override IEnumerable<DownloadClientItem> 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 else
{ {
_proxy.RemoveFrom("history", downloadId, deleteData, Settings); _proxy.RemoveFrom("queue", item.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)
{
_logger.Error("Unable to delete output path: '{0}'. Delete file(s) manually", outputPath.FullPath);
}
}
else
{
_logger.Warn("Invalid path '{0}'. Delete file(s) manually");
}
}
} }
} }

View File

@ -159,9 +159,9 @@ protected bool HasReachedSeedLimit(TransmissionTorrent torrent, double? ratio, L
return false; 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() public override DownloadClientInfo GetStatus()

View File

@ -26,9 +26,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) protected override OsPath GetOutputPath(OsPath outputPath, TransmissionTorrent torrent)

View File

@ -163,14 +163,14 @@ public override IEnumerable<DownloadClientItem> GetItems()
return items; return items;
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
if (deleteData) if (deleteData)
{ {
DeleteItemData(downloadId); DeleteItemData(item);
} }
_proxy.RemoveTorrent(downloadId, Settings); _proxy.RemoveTorrent(item.DownloadId, Settings);
} }
public override DownloadClientInfo GetStatus() public override DownloadClientInfo GetStatus()

View File

@ -208,9 +208,9 @@ private List<UTorrentTorrent> GetTorrents()
return torrents; 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() public override DownloadClientInfo GetStatus()

View File

@ -4,7 +4,6 @@
using FluentValidation.Results; using FluentValidation.Results;
using NLog; using NLog;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Organizer; using NzbDrone.Core.Organizer;
@ -72,20 +71,13 @@ public virtual DownloadClientItem GetImportItem(DownloadClientItem item, Downloa
return item; return item;
} }
public abstract void RemoveItem(string downloadId, bool deleteData); public abstract void RemoveItem(DownloadClientItem item, bool deleteData);
public abstract DownloadClientInfo GetStatus(); 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) if (item == null)
{ {
_logger.Trace("DownloadItem {0} in {1} history not found, skipping delete data.", downloadId, Name);
return; return;
} }

View File

@ -62,7 +62,7 @@ private void RemoveFromDownloadClient(TrackedDownload trackedDownload)
try try
{ {
_logger.Debug("[{0}] Removing download from {1} history", trackedDownload.DownloadItem.Title, trackedDownload.DownloadItem.DownloadClientInfo.Name); _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; trackedDownload.DownloadItem.Removed = true;
} }
catch (NotSupportedException) catch (NotSupportedException)

View File

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using NzbDrone.Common.Disk;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.ThingiProvider;
@ -12,7 +11,7 @@ public interface IDownloadClient : IProvider
string Download(RemoteMovie remoteMovie); string Download(RemoteMovie remoteMovie);
IEnumerable<DownloadClientItem> GetItems(); IEnumerable<DownloadClientItem> GetItems();
DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt); DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt);
void RemoveItem(string downloadId, bool deleteData); void RemoveItem(DownloadClientItem item, bool deleteData);
DownloadClientInfo GetStatus(); DownloadClientInfo GetStatus();
void MarkItemAsImported(DownloadClientItem downloadClientItem); void MarkItemAsImported(DownloadClientItem downloadClientItem);
} }

View File

@ -141,7 +141,7 @@ private TrackedDownload Remove(int id, bool removeFromClient, bool blacklist)
throw new BadRequestException(); throw new BadRequestException();
} }
downloadClient.RemoveItem(trackedDownload.DownloadItem.DownloadId, true); downloadClient.RemoveItem(trackedDownload.DownloadItem, true);
} }
if (blacklist) if (blacklist)