From 4a2277b4249414ecbf56433cc84201af6b29abb7 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 10 Jan 2019 20:32:18 -0800 Subject: [PATCH] Fix path tests --- src/NzbDrone.Common.Test/PathExtensionFixture.cs | 6 +++--- src/NzbDrone.Common/Extensions/PathExtensions.cs | 5 +++++ .../MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/NzbDrone.Common.Test/PathExtensionFixture.cs b/src/NzbDrone.Common.Test/PathExtensionFixture.cs index 53d27ea8c..b85fdfcdd 100644 --- a/src/NzbDrone.Common.Test/PathExtensionFixture.cs +++ b/src/NzbDrone.Common.Test/PathExtensionFixture.cs @@ -149,7 +149,7 @@ public void path_should_return_parent_windows(string path, string parentPath) } [TestCase(@"/", null)] - [TestCase(@"/test", null)] + [TestCase(@"/test", "/")] public void path_should_return_parent_mono(string path, string parentPath) { MonoOnly(); @@ -164,8 +164,8 @@ public void path_should_return_parent_for_oversized_path() // This test will fail on Windows if long path support is not enabled: https://www.howtogeek.com/266621/how-to-make-windows-10-accept-file-paths-over-260-characters/ // It will also fail if the app isn't configured to use long path (such as resharper): https://blogs.msdn.microsoft.com/jeremykuhne/2016/07/30/net-4-6-2-and-long-paths-on-windows-10/ - var path = @"C:\media\2e168617-f2ae-43fb-b88c-3663af1c8eea\downloads\sabnzbd\nzbdrone\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories"; - var parentPath = @"C:\media\2e168617-f2ae-43fb-b88c-3663af1c8eea\downloads\sabnzbd\nzbdrone\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing"; + var path = @"C:\media\2e168617-f2ae-43fb-b88c-3663af1c8eea\downloads\sabnzbd\nzbdrone\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories".AsOsAgnostic(); + var parentPath = @"C:\media\2e168617-f2ae-43fb-b88c-3663af1c8eea\downloads\sabnzbd\nzbdrone\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing\With.Alot.Of.Nested.Directories\Some.Real.Big.Thing".AsOsAgnostic(); path.GetParentPath().Should().Be(parentPath); } diff --git a/src/NzbDrone.Common/Extensions/PathExtensions.cs b/src/NzbDrone.Common/Extensions/PathExtensions.cs index 5a29bdc9c..f4c0d0d21 100644 --- a/src/NzbDrone.Common/Extensions/PathExtensions.cs +++ b/src/NzbDrone.Common/Extensions/PathExtensions.cs @@ -73,6 +73,11 @@ public static string GetParentPath(this string childPath) ? PARENT_PATH_END_SLASH_REGEX.Replace(childPath, "") : childPath.TrimEnd(Path.DirectorySeparatorChar); + if (cleanPath.IsNullOrWhiteSpace()) + { + return null; + } + return Directory.GetParent(cleanPath)?.FullName; } diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs index f44dcdf0a..7593615f6 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs @@ -183,7 +183,7 @@ private string GetOriginalFilePath(DownloadClientItem downloadClientItem, LocalE return grandparentPath.GetRelativePath(path); } - return Path.Combine(Path.GetFileName(parentPath), Path.GetFileName(path)); + return Path.GetFileName(path); } private string GetSceneName(DownloadClientItem downloadClientItem, LocalEpisode localEpisode)