mirror of
https://github.com/Radarr/Radarr.git
synced 2024-08-18 16:29:41 +02:00
New: Remove completed downloads from disk when removing from SABnzbd
(cherry picked from commit ac8283d7339b3d9e8ccf70f3d1ff031d1b0a71d1)
This commit is contained in:
parent
2716bd6ae1
commit
f2c9fcde7c
@ -577,5 +577,115 @@ public void should_test_failed_if_tv_sorting_default_category()
|
||||
|
||||
result.IsValid.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_remove_output_path_folder_when_deleting_a_completed_item_and_delete_data_is_true()
|
||||
{
|
||||
var path = @"C:\Test\Series.Title.S01E01".AsOsAgnostic();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.FolderExists(path))
|
||||
.Returns(true);
|
||||
|
||||
_completed.Items.First().Storage = path;
|
||||
|
||||
GivenQueue(null);
|
||||
GivenHistory(_completed);
|
||||
|
||||
Subject.RemoveItem(_completed.Items.First().Id, true);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.DeleteFolder(path, true), Times.Once);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.DeleteFile(path), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_remove_output_path_file_when_deleting_a_completed_item_and_delete_data_is_true()
|
||||
{
|
||||
var path = @"C:\Test\Series.Title.S01E01.mkv".AsOsAgnostic();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.FolderExists(path))
|
||||
.Returns(false);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.FileExists(path))
|
||||
.Returns(true);
|
||||
|
||||
_completed.Items.First().Storage = path;
|
||||
|
||||
GivenQueue(null);
|
||||
GivenHistory(_completed);
|
||||
|
||||
Subject.RemoveItem(_completed.Items.First().Id, true);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.DeleteFolder(path, true), Times.Never);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.DeleteFile(path), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_remove_output_path_file_when_deleting_a_completed_item_and_delete_data_is_true_if_it_does_not_exist()
|
||||
{
|
||||
var path = @"C:\Test\Series.Title.S01E01.mkv".AsOsAgnostic();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.FolderExists(path))
|
||||
.Returns(false);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.FileExists(path))
|
||||
.Returns(false);
|
||||
|
||||
_completed.Items.First().Storage = path;
|
||||
|
||||
GivenQueue(null);
|
||||
GivenHistory(_completed);
|
||||
|
||||
Subject.RemoveItem(_completed.Items.First().Id, true);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.DeleteFolder(path, true), Times.Never);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.DeleteFile(path), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_remove_output_path_file_when_deleting_a_completed_item_and_delete_data_is_false()
|
||||
{
|
||||
var path = @"C:\Test\Series.Title.S01E01.mkv".AsOsAgnostic();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.FolderExists(path))
|
||||
.Returns(false);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.FileExists(path))
|
||||
.Returns(false);
|
||||
|
||||
_completed.Items.First().Storage = path;
|
||||
|
||||
GivenQueue(null);
|
||||
GivenHistory(_completed);
|
||||
|
||||
Subject.RemoveItem(_completed.Items.First().Id, false);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.FolderExists(path), Times.Never);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.FileExists(path), Times.Never);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.DeleteFolder(path, true), Times.Never);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.DeleteFile(path), Times.Never);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
using FluentValidation.Results;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Configuration;
|
||||
@ -195,13 +196,45 @@ public override IEnumerable<DownloadClientItem> GetItems()
|
||||
|
||||
public override void RemoveItem(string downloadId, bool deleteData)
|
||||
{
|
||||
if (GetQueue().Any(v => v.DownloadId == downloadId))
|
||||
var historyItem = GetHistory().SingleOrDefault(v => v.DownloadId == downloadId);
|
||||
|
||||
if (historyItem == null)
|
||||
{
|
||||
_proxy.RemoveFrom("queue", 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -496,5 +529,23 @@ private bool ContainsCategory(IEnumerable<string> categories, string category)
|
||||
|
||||
return categories.Contains(category);
|
||||
}
|
||||
|
||||
private bool ValidatePath(DownloadClientItem downloadClientItem)
|
||||
{
|
||||
var downloadItemOutputPath = downloadClientItem.OutputPath;
|
||||
|
||||
if (downloadItemOutputPath.IsEmpty)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((OsInfo.IsWindows && !downloadItemOutputPath.IsWindowsPath) ||
|
||||
(OsInfo.IsNotWindows && !downloadItemOutputPath.IsUnixPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user