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 @@ public void path_should_be_parent_on_windows_only(string parentPath, string chil [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 @@ public static string GetParentPath(this string childPath) 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 @@ public void should_use_folder_info_release_title_to_find_relative_path() 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()))); + } } }