From 3ed8f0ea8441d11f2506de847b0a480dca13b2a5 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 13 Feb 2015 16:52:42 -0800 Subject: [PATCH] Fixed: Not properly getting the parent of a folder with a trailing slash GetParentFolder will trim trailing slashes --- .../DiskTests/DiskProviderFixtureBase.cs | 9 +++++++++ src/NzbDrone.Common/Disk/DiskProviderBase.cs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Common.Test/DiskTests/DiskProviderFixtureBase.cs b/src/NzbDrone.Common.Test/DiskTests/DiskProviderFixtureBase.cs index fc34df228..c4930d4d1 100644 --- a/src/NzbDrone.Common.Test/DiskTests/DiskProviderFixtureBase.cs +++ b/src/NzbDrone.Common.Test/DiskTests/DiskProviderFixtureBase.cs @@ -346,6 +346,15 @@ namespace NzbDrone.Common.Test.DiskTests Console.WriteLine(GetFilledTempFolder().LastWriteTimeUtc); } + [Test] + public void GetParentFolder_should_remove_trailing_slash_before_getting_parent_folder() + { + var path = @"C:\Test\TV\".AsOsAgnostic(); + var parent = @"C:\Test".AsOsAgnostic(); + + Subject.GetParentFolder(path).Should().Be(parent); + } + private void VerifyCopy(string source, string destination) { var sourceFiles = Directory.GetFileSystemEntries(source, "*", SearchOption.AllDirectories).Select(v => v.Substring(source.Length + 1)).ToArray(); diff --git a/src/NzbDrone.Common/Disk/DiskProviderBase.cs b/src/NzbDrone.Common/Disk/DiskProviderBase.cs index de3075901..20855d6b3 100644 --- a/src/NzbDrone.Common/Disk/DiskProviderBase.cs +++ b/src/NzbDrone.Common/Disk/DiskProviderBase.cs @@ -355,7 +355,7 @@ namespace NzbDrone.Common.Disk { Ensure.That(path, () => path).IsValidPath(); - var parent = Directory.GetParent(path); + var parent = Directory.GetParent(path.TrimEnd(Path.DirectorySeparatorChar)); if (parent == null) {