From edd6c0bd4c4169282052c5251dcb7432a05a97d2 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 --- .../PathExtensionFixture.cs | 2 ++ .../Extensions/PathExtensions.cs | 3 ++- .../MediaFiles/ImportApprovedEpisodesFixture.cs | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Common.Test/PathExtensionFixture.cs b/src/NzbDrone.Common.Test/PathExtensionFixture.cs index febd93a7d..db140d626 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 da7dd1d46..ff95d8973 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 a5f50c916..f16be5c30 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs @@ -341,6 +341,23 @@ 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()))); + } + + [Test] public void should_delete_existing_metadata_files_with_the_same_path() { Mocker.GetMock()