Pull Sonarr commit 'Fixed: Removing completed download from SABnzbd'

(cherry picked from c669be317fffa252d59851e9a8ca9e56032a01fb)
pull/1071/head
Mark McDowall 4 years ago committed by ta264
parent 5fff24bf69
commit 0ffc44f3da

@ -4,6 +4,7 @@ using System.IO;
using System.IO.Abstractions;
using System.Linq;
using System.Net;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
@ -26,6 +27,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
protected string _blackholeFolder;
protected string _filePath;
protected string _magnetFilePath;
protected DownloadClientItem _downloadClientItem;
[SetUp]
public void Setup()
@ -34,6 +36,10 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
_blackholeFolder = @"c:\blackhole\torrent".AsOsAgnostic();
_filePath = (@"c:\blackhole\torrent\" + _title + ".torrent").AsOsAgnostic();
_downloadClientItem = Builder<DownloadClientItem>
.CreateNew().With(d => d.DownloadId = "_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0")
.Build();
Mocker.SetConstant<IScanWatchFolder>(Mocker.Resolve<ScanWatchFolder>());
Subject.Definition = new DownloadClientDefinition();
@ -248,7 +254,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Setup(c => c.FileExists(It.IsAny<string>()))
.Returns(true);
Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true);
Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Once());
@ -263,7 +269,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Setup(c => c.FolderExists(It.IsAny<string>()))
.Returns(true);
Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true);
Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFolder(It.IsAny<string>(), true), Times.Once());
@ -272,7 +278,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
[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<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never());
@ -286,7 +292,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
{
GivenCompletedItem();
Assert.Throws<NotSupportedException>(() => Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", false));
Assert.Throws<NotSupportedException>(() => Subject.RemoveItem(_downloadClientItem, false));
Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never());

@ -4,6 +4,7 @@ using System.IO;
using System.IO.Abstractions;
using System.Linq;
using System.Net;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
@ -22,6 +23,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
protected string _completedDownloadFolder;
protected string _blackholeFolder;
protected string _filePath;
protected DownloadClientItem _downloadClientItem;
[SetUp]
public void Setup()
@ -30,6 +32,10 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
_blackholeFolder = @"c:\blackhole\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>());
Subject.Definition = new DownloadClientDefinition();
@ -147,7 +153,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Setup(c => c.FileExists(It.IsAny<string>()))
.Returns(true);
Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true);
Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Once());
@ -162,7 +168,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Setup(c => c.FolderExists(It.IsAny<string>()))
.Returns(true);
Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true);
Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFolder(It.IsAny<string>(), true), Times.Once());
@ -171,7 +177,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
[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<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never());
@ -185,7 +191,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
{
GivenCompletedItem();
Assert.Throws<NotSupportedException>(() => Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", false));
Assert.Throws<NotSupportedException>(() => Subject.RemoveItem(_downloadClientItem, false));
Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never());

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

@ -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 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
private string _strmFolder;
private string _nzbPath;
private RemoteBook _remoteBook;
private DownloadClientItem _downloadClientItem;
[SetUp]
public void Setup()
@ -37,6 +39,10 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
_remoteBook.ParsedBookInfo = new ParsedBookInfo();
_downloadClientItem = Builder<DownloadClientItem>
.CreateNew().With(d => d.DownloadId = "_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0")
.Build();
Subject.Definition = new DownloadClientDefinition();
Subject.Definition.Settings = new PneumaticSettings
{
@ -78,7 +84,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
[Test]
public void should_throw_item_is_removed()
{
Assert.Throws<NotSupportedException>(() => Subject.RemoveItem("", true));
Assert.Throws<NotSupportedException>(() => Subject.RemoveItem(_downloadClientItem, true));
}
[Test]

@ -24,6 +24,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
private SabnzbdHistory _completed;
private SabnzbdConfig _config;
private SabnzbdFullStatus _fullStatus;
private DownloadClientItem _downloadClientItem;
[SetUp]
public void Setup()
@ -101,6 +102,10 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
}
};
_downloadClientItem = Builder<DownloadClientItem>
.CreateNew().With(d => d.DownloadId = _completed.Items.First().Id)
.Build();
Mocker.GetMock<ISabnzbdProxy>()
.Setup(v => v.GetVersion(It.IsAny<SabnzbdSettings>()))
.Returns("1.2.3");
@ -594,7 +599,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
GivenQueue(null);
GivenHistory(_completed);
Subject.RemoveItem(_completed.Items.First().Id, true);
Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(path, true), Times.Once);
@ -621,7 +626,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
GivenQueue(null);
GivenHistory(_completed);
Subject.RemoveItem(_completed.Items.First().Id, true);
Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(path, true), Times.Never);
@ -648,7 +653,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
GivenQueue(null);
GivenHistory(_completed);
Subject.RemoveItem(_completed.Items.First().Id, true);
Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(path, true), Times.Never);
@ -675,7 +680,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
GivenQueue(null);
GivenHistory(_completed);
Subject.RemoveItem(_completed.Items.First().Id, false);
Subject.RemoveItem(_downloadClientItem, false);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.FolderExists(path), Times.Never);

@ -105,14 +105,14 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
}
}
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()

@ -77,14 +77,14 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
}
}
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()

@ -188,9 +188,9 @@ namespace NzbDrone.Core.Download.Clients.Deluge
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()

@ -132,15 +132,15 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
}
}
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)

@ -156,15 +156,15 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
}
}
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(RemoteBook remoteBook, string filename, byte[] fileContent)

@ -193,9 +193,10 @@ namespace NzbDrone.Core.Download.Clients.Flood
}
}
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()

@ -96,15 +96,15 @@ namespace NzbDrone.Core.Download.Clients.Hadouken
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);
}
}

@ -110,19 +110,19 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex
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);
}
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)
{

@ -192,14 +192,14 @@ namespace NzbDrone.Core.Download.Clients.Nzbget
return GetQueue().Concat(GetHistory()).Where(downloadClientItem => downloadClientItem.Category == Settings.MusicCategory);
}
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()

@ -97,7 +97,7 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic
}
}
public override void RemoveItem(string downloadId, bool deleteData)
public override void RemoveItem(DownloadClientItem item, bool deleteData)
{
throw new NotSupportedException();
}

@ -223,9 +223,9 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
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)

@ -192,47 +192,22 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
}
}
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)
{
_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);
}
}

@ -157,9 +157,9 @@ namespace NzbDrone.Core.Download.Clients.Transmission
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()

@ -24,9 +24,9 @@ namespace NzbDrone.Core.Download.Clients.Vuze
{
}
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)

@ -161,14 +161,14 @@ namespace NzbDrone.Core.Download.Clients.RTorrent
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()

@ -206,9 +206,9 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
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()

@ -4,7 +4,6 @@ using System.Linq;
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;
@ -68,20 +67,13 @@ namespace NzbDrone.Core.Download
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;
}

@ -62,7 +62,7 @@ namespace NzbDrone.Core.Download
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)

@ -12,7 +12,7 @@ namespace NzbDrone.Core.Download
string Download(RemoteBook remoteBook);
IEnumerable<DownloadClientItem> 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);
}

@ -218,7 +218,7 @@ namespace Readarr.Api.V1.Queue
throw new BadRequestException();
}
downloadClient.RemoveItem(trackedDownload.DownloadItem.DownloadId, true);
downloadClient.RemoveItem(trackedDownload.DownloadItem, true);
}
if (blacklist)

Loading…
Cancel
Save