From df0082c0770a72daf883dd9fb7379f44c59bada9 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sat, 12 Jul 2014 00:16:49 +0200 Subject: [PATCH] Fixed issue with a relative complete dir in sabnzbd. --- .../SabnzbdTests/SabnzbdFixture.cs | 39 ++++++++++++++----- .../Download/Clients/Sabnzbd/Sabnzbd.cs | 14 +++++++ .../Download/Clients/Sabnzbd/SabnzbdQueue.cs | 3 ++ 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs index 455b9d4b7..ae40543b6 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs @@ -23,6 +23,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests private SabnzbdQueue _queued; private SabnzbdHistory _failed; private SabnzbdHistory _completed; + private SabnzbdConfig _config; [SetUp] public void Setup() @@ -40,6 +41,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests }; _queued = new SabnzbdQueue { + DefaultRootFolder = @"Y:\nzbget\root".AsOsAgnostic(), Paused = false, Items = new List() { @@ -87,19 +89,21 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests } }; - Mocker.GetMock() - .Setup(s => s.GetConfig(It.IsAny())) - .Returns(new SabnzbdConfig + _config = new SabnzbdConfig { - Misc = new SabnzbdConfigMisc + Misc = new SabnzbdConfigMisc { - complete_dir = "/remote/mount/" + complete_dir = @"/remote/mount" }, Categories = new List { new SabnzbdCategory { Name = "tv", Dir = "vv" } } - }); + }; + + Mocker.GetMock() + .Setup(s => s.GetConfig(It.IsAny())) + .Returns(_config); } protected void WithMountPoint(String mountPath) @@ -129,7 +133,11 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests { if (queue == null) { - queue = new SabnzbdQueue() { Items = new List() }; + queue = new SabnzbdQueue() + { + DefaultRootFolder = _queued.DefaultRootFolder, + Items = new List() + }; } Mocker.GetMock() @@ -314,14 +322,23 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests result.OutputPath.Should().Be(@"C:\".AsOsAgnostic()); } - [Test] - public void should_return_status_with_outputdir() + [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")] + [TestCase(@"/nzbget/root", @"completed", @"vv", @"/nzbget/root/completed/vv")] + public void should_return_status_with_outputdir(String rootFolder, String completeDir, String categoryDir, String expectedDir) { + _queued.DefaultRootFolder = rootFolder; + _config.Misc.complete_dir = completeDir; + _config.Categories.First().Dir = categoryDir; + + WithQueue(null); + var result = Subject.GetStatus(); result.IsLocalhost.Should().BeTrue(); result.OutputRootFolders.Should().NotBeNull(); - result.OutputRootFolders.First().Should().Be(@"/remote/mount/vv"); + result.OutputRootFolders.First().Should().Be(expectedDir); } [Test] @@ -329,6 +346,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests { WithMountPoint(@"O:\mymount".AsOsAgnostic()); + WithQueue(null); + var result = Subject.GetStatus(); result.IsLocalhost.Should().BeTrue(); diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs index 43e383b98..5009bb828 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs @@ -236,6 +236,20 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd { var completeDir = config.Misc.complete_dir.TrimEnd('\\', '/'); + if (!completeDir.StartsWith("/") && !completeDir.StartsWith("\\") && !completeDir.Contains(':')) + { + var queue = _proxy.GetQueue(0, 1, Settings); + + if (queue.DefaultRootFolder.StartsWith("/")) + { + completeDir = queue.DefaultRootFolder + "/" + completeDir; + } + else + { + completeDir = queue.DefaultRootFolder + "\\" + completeDir; + } + } + foreach (var category in config.Categories) { var relativeDir = category.Dir.TrimEnd('*'); diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdQueue.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdQueue.cs index edbdab5da..5640ae4ec 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdQueue.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdQueue.cs @@ -5,6 +5,9 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd { public class SabnzbdQueue { + [JsonProperty(PropertyName = "my_home")] + public string DefaultRootFolder { get; set; } + public bool Paused { get; set; } [JsonProperty(PropertyName = "slots")]