From e9f39493f40a9b90f2e21404c91537cca27cbd43 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sun, 20 Jul 2014 00:53:22 +0200 Subject: [PATCH] Fixed: Sabnzbd downloads with single obfuscated files in nested subdirectories are now handled appropriately. --- .../SabnzbdTests/SabnzbdFixture.cs | 27 +++++++++++++++---- .../Download/Clients/Sabnzbd/Sabnzbd.cs | 14 +++++----- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs index ae40543b6..8e73da554 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs @@ -283,17 +283,21 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests .Verify(v => v.DownloadNzb(It.IsAny(), It.IsAny(), It.IsAny(), (int)SabnzbdPriority.High, It.IsAny()), Times.Once()); } - [Test] - public void should_return_path_to_folder_instead_of_file() + [TestCase(@"Droned.S01E01.Pilot.1080p.WEB-DL-DRONE", @"Droned.S01E01_Pilot_1080p_WEB-DL-DRONE.mkv")] + [TestCase(@"Droned.S01E01.Pilot.1080p.WEB-DL-DRONE", @"SubDir\Droned.S01E01_Pilot_1080p_WEB-DL-DRONE.mkv")] + [TestCase(@"Droned.S01E01.Pilot.1080p.WEB-DL-DRONE.mkv", @"SubDir\Droned.S01E01_Pilot_1080p_WEB-DL-DRONE.mkv")] + [TestCase(@"Droned.S01E01.Pilot.1080p.WEB-DL-DRONE.mkv", @"SubDir\SubDir\Droned.S01E01_Pilot_1080p_WEB-DL-DRONE.mkv")] + public void should_return_path_to_jobfolder(String title, String storage) { - _completed.Items.First().Storage = @"C:\sorted\Droned.S01E01.Pilot.1080p.WEB-DL-DRONE\Droned.S01E01_Pilot_1080p_WEB-DL-DRONE.mkv".AsOsAgnostic(); + _completed.Items.First().Title = title; + _completed.Items.First().Storage = (@"C:\sorted\" + title + @"\" + storage).AsOsAgnostic(); WithQueue(null); WithHistory(_completed); - + var result = Subject.GetItems().Single(); - result.OutputPath.Should().Be(@"C:\sorted\Droned.S01E01.Pilot.1080p.WEB-DL-DRONE".AsOsAgnostic()); + result.OutputPath.Should().Be((@"C:\sorted\" + title).AsOsAgnostic()); } [Test] @@ -322,6 +326,19 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests result.OutputPath.Should().Be(@"C:\".AsOsAgnostic()); } + [Test] + public void should_not_blow_up_if_storage_doesnt_have_jobfolder() + { + _completed.Items.First().Storage = @"C:\sorted\somewhere\asdfasdf\asdfasdf.mkv".AsOsAgnostic(); + + WithQueue(null); + WithHistory(_completed); + + var result = Subject.GetItems().Single(); + + result.OutputPath.Should().Be(@"C:\sorted\somewhere\asdfasdf\asdfasdf.mkv".AsOsAgnostic()); + } + [TestCase(@"Y:\nzbget\root", @"completed\downloads", @"vv", @"Y:\nzbget\root\completed\downloads\vv")] [TestCase(@"Y:\nzbget\root", @"completed", @"vv", @"Y:\nzbget\root\completed\vv")] [TestCase(@"/nzbget/root", @"completed/downloads", @"vv", @"/nzbget/root/completed/downloads/vv")] diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs index a11e13c74..9dbd60a8f 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs @@ -163,14 +163,16 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd if (!sabHistoryItem.Storage.IsNullOrWhiteSpace()) { + historyItem.OutputPath = sabHistoryItem.Storage; + var parent = sabHistoryItem.Storage.GetParentPath(); - if (parent != null && Path.GetFileName(parent) == sabHistoryItem.Title) + while (parent != null) { - historyItem.OutputPath = parent; - } - else - { - historyItem.OutputPath = sabHistoryItem.Storage; + if (Path.GetFileName(parent) == sabHistoryItem.Title) + { + historyItem.OutputPath = parent; + } + parent = parent.GetParentPath(); } }