Fixed: Nzbget will now properly remove data from original directory if Remove option is enabled. (nzbToMedia transcoding)

pull/3113/head
Taloth Saldono 10 years ago
parent 25c77711cd
commit 97cbdfdc5c

@ -151,6 +151,10 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
{
GivenCompletedItem();
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.FolderExists(It.IsAny<string>()))
.Returns(true);
Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true);
Mocker.GetMock<IDiskProvider>()
@ -158,9 +162,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
}
[Test]
public void RemoveItem_should_throw_if_unknown_item()
public void RemoveItem_should_ignore_if_unknown_item()
{
Assert.Throws<ArgumentException>(() => Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true));
Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true);
Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never());

@ -148,6 +148,10 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
{
GivenCompletedItem();
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.FolderExists(It.IsAny<string>()))
.Returns(true);
Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true);
Mocker.GetMock<IDiskProvider>()
@ -155,9 +159,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
}
[Test]
public void RemoveItem_should_throw_if_unknown_item()
public void RemoveItem_should_ignore_if_unknown_item()
{
Assert.Throws<ArgumentException>(() => Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true));
Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true);
Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never());

@ -140,6 +140,22 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests
Subject.GetItems().Should().BeEmpty();
}
[Test]
public void RemoveItem_should_delete_folder()
{
GivenQueue(null);
GivenHistory(_completed);
Mocker.GetMock<IDiskProvider>()
.Setup(v => v.FolderExists(It.IsAny<string>()))
.Returns(true);
Subject.RemoveItem("id", true);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Once());
}
[Test]
public void queued_item_should_have_required_properties()
{

@ -202,6 +202,11 @@ namespace NzbDrone.Core.Download.Clients.Nzbget
public override void RemoveItem(string downloadId, bool deleteData)
{
if (deleteData)
{
DeleteItemData(downloadId);
}
_proxy.RemoveItem(downloadId, Settings);
}

@ -129,28 +129,12 @@ namespace NzbDrone.Core.Download.Clients.TorrentBlackhole
public override void RemoveItem(string downloadId, bool deleteData)
{
var downloadItem = GetItems().FirstOrDefault(v => v.DownloadId == downloadId);
if (downloadItem == null)
{
throw new ArgumentException(string.Format("Cannot remove DownloadItem {0} because it was not found.", downloadId));
}
if (!deleteData)
{
throw new NotSupportedException("Blackhole cannot remove DownloadItem without deleting the data as well, ignoring.");
}
var outputPath = downloadItem.OutputPath.FullPath;
if (_diskProvider.FileExists(outputPath))
{
_diskProvider.DeleteFile(outputPath);
}
else
{
_diskProvider.DeleteFolder(outputPath, true);
}
DeleteItemData(downloadId);
}
public override DownloadClientStatus GetStatus()

@ -122,28 +122,12 @@ namespace NzbDrone.Core.Download.Clients.UsenetBlackhole
public override void RemoveItem(string downloadId, bool deleteData)
{
var downloadItem = GetItems().FirstOrDefault(v => v.DownloadId == downloadId);
if (downloadItem == null)
{
throw new ArgumentException(string.Format("Cannot remove DownloadItem {0} because it was not found.", downloadId));
}
if (!deleteData)
{
throw new NotSupportedException("Blackhole cannot remove DownloadItem without deleting the data as well, ignoring.");
}
var outputPath = downloadItem.OutputPath.FullPath;
if (_diskProvider.FileExists(outputPath))
{
_diskProvider.DeleteFile(outputPath);
}
else
{
_diskProvider.DeleteFolder(outputPath, true);
}
DeleteItemData(downloadId);
}
public override DownloadClientStatus GetStatus()

@ -1,14 +1,16 @@
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;
using NzbDrone.Core.RemotePathMappings;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Configuration;
using NLog;
using FluentValidation.Results;
using NzbDrone.Core.Validation;
using NzbDrone.Core.RemotePathMappings;
namespace NzbDrone.Core.Download
{
@ -74,6 +76,51 @@ namespace NzbDrone.Core.Download
public abstract void RemoveItem(string downloadId, bool deleteData);
public abstract DownloadClientStatus GetStatus();
protected virtual void DeleteItemData(string downloadId)
{
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;
}
if (item.OutputPath == null)
{
_logger.Trace("[{0}] Doesn't have an outputPath, skipping delete data.", item.Title);
return;
}
try
{
if (_diskProvider.FolderExists(item.OutputPath.FullPath))
{
_logger.Debug("[{0}] Deleting folder '{1}'.", item.Title, item.OutputPath);
_diskProvider.DeleteFolder(item.OutputPath.FullPath, true);
}
else if (_diskProvider.FileExists(item.OutputPath.FullPath))
{
_logger.Debug("[{0}] Deleting file '{1}'.", item.Title, item.OutputPath);
_diskProvider.DeleteFile(item.OutputPath.FullPath);
}
else
{
_logger.Trace("[{0}] File or folder '{1}' doesn't exist, skipping cleanup.", item.Title, item.OutputPath);
}
}
catch (Exception ex)
{
_logger.WarnException(string.Format("[{0}] Error occurred while trying to delete data from '{1}'.", item.Title, item.OutputPath), ex);
}
}
public ValidationResult Test()
{
var failures = new List<ValidationFailure>();

Loading…
Cancel
Save