From d6997b0588e28cd6ac16a7632ad8fb8c23751f3d Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 1 Jan 2019 15:01:24 -0800 Subject: [PATCH] Fixed getting parent path from a path without another slash Fixed: Manual Import failing for some paths --- src/NzbDrone.Common.Test/PathExtensionFixture.cs | 2 ++ src/NzbDrone.Common/Extensions/PathExtensions.cs | 3 ++- .../MediaFiles/ImportApprovedEpisodesFixture.cs | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Common.Test/PathExtensionFixture.cs b/src/NzbDrone.Common.Test/PathExtensionFixture.cs index ec5451029..19eadea7a 100644 --- a/src/NzbDrone.Common.Test/PathExtensionFixture.cs +++ b/src/NzbDrone.Common.Test/PathExtensionFixture.cs @@ -140,6 +140,8 @@ namespace NzbDrone.Common.Test [TestCase(@"C:\Test\mydir", @"C:\Test")] [TestCase(@"C:\Test\", @"C:")] [TestCase(@"C:\", null)] + [TestCase(@"/", null)] + [TestCase(@"/test", null)] public void path_should_return_parent(string path, string parentPath) { path.GetParentPath().Should().Be(parentPath); diff --git a/src/NzbDrone.Common/Extensions/PathExtensions.cs b/src/NzbDrone.Common/Extensions/PathExtensions.cs index c7fc857e8..f67733808 100644 --- a/src/NzbDrone.Common/Extensions/PathExtensions.cs +++ b/src/NzbDrone.Common/Extensions/PathExtensions.cs @@ -71,10 +71,11 @@ namespace NzbDrone.Common.Extensions var index = parentPath.LastIndexOfAny(new[] { '\\', '/' }); - if (index != -1) + if (index > 0) { return parentPath.Substring(0, index); } + return null; } diff --git a/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs index 3c510140c..9c4f6a8b9 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs @@ -317,5 +317,20 @@ namespace NzbDrone.Core.Test.MediaFiles Mocker.GetMock().Verify(v => v.Add(It.Is(c => c.OriginalFilePath == $"{name}\\subfolder\\{name}.mkv".AsOsAgnostic()))); } + + [Test] + public void should_get_relative_path_when_there_is_no_grandparent() + { + var name = "Series.Title.S01E01.720p.HDTV.x264-Sonarr"; + var outputPath = Path.Combine(@"C:\".AsOsAgnostic()); + var localEpisode = _approvedDecisions.First().LocalEpisode; + + localEpisode.FolderEpisodeInfo = new ParsedEpisodeInfo { ReleaseTitle = name }; + localEpisode.Path = Path.Combine(outputPath, name + ".mkv"); + + Subject.Import(new List { _approvedDecisions.First() }, true, null); + + Mocker.GetMock().Verify(v => v.Add(It.Is(c => c.OriginalFilePath == $"{name}.mkv".AsOsAgnostic()))); + } } }