From 1e51854cb54cc8d169268b1c370499cd23feacbd Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 14 Jul 2024 09:00:17 -0700 Subject: [PATCH] fixup! Fixed: Updating series path from different OS paths --- src/NzbDrone.Common.Test/PathExtensionFixture.cs | 9 +++++++-- src/NzbDrone.Common/Disk/OsPath.cs | 9 +++++++-- src/NzbDrone.Common/Extensions/PathExtensions.cs | 11 ++--------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/NzbDrone.Common.Test/PathExtensionFixture.cs b/src/NzbDrone.Common.Test/PathExtensionFixture.cs index 0eddbb0fa..ddb54c538 100644 --- a/src/NzbDrone.Common.Test/PathExtensionFixture.cs +++ b/src/NzbDrone.Common.Test/PathExtensionFixture.cs @@ -135,9 +135,14 @@ namespace NzbDrone.Common.Test [TestCase(@"C:\test", @"C:\Test\mydir\")] public void windows_path_should_be_parent(string parentPath, string childPath) { - var expectedResult = OsInfo.IsWindows; + parentPath.IsParentPath(childPath).Should().Be(true); + } - parentPath.IsParentPath(childPath).Should().Be(expectedResult); + [TestCase("/test", "/test/mydir/")] + [TestCase("/test/", "/test/mydir")] + public void posix_path_should_be_parent(string parentPath, string childPath) + { + parentPath.IsParentPath(childPath).Should().Be(true); } [TestCase(@"C:\Test\mydir", @"C:\Test")] diff --git a/src/NzbDrone.Common/Disk/OsPath.cs b/src/NzbDrone.Common/Disk/OsPath.cs index 5b7a4f7ce..45e520761 100644 --- a/src/NzbDrone.Common/Disk/OsPath.cs +++ b/src/NzbDrone.Common/Disk/OsPath.cs @@ -360,6 +360,11 @@ namespace NzbDrone.Common.Disk } public bool Equals(OsPath other) + { + return Equals(other, false); + } + + public bool Equals(OsPath other, bool ignoreTrailingSlash) { if (ReferenceEquals(other, null)) { @@ -371,8 +376,8 @@ namespace NzbDrone.Common.Disk return true; } - var left = PathWithoutTrailingSlash; - var right = other.PathWithoutTrailingSlash; + var left = ignoreTrailingSlash ? PathWithoutTrailingSlash : _path; + var right = ignoreTrailingSlash ? other.PathWithoutTrailingSlash : other._path; if (Kind == OsPathKind.Windows || other.Kind == OsPathKind.Windows) { diff --git a/src/NzbDrone.Common/Extensions/PathExtensions.cs b/src/NzbDrone.Common/Extensions/PathExtensions.cs index 15d58ecd2..7dced0c0e 100644 --- a/src/NzbDrone.Common/Extensions/PathExtensions.cs +++ b/src/NzbDrone.Common/Extensions/PathExtensions.cs @@ -92,14 +92,7 @@ namespace NzbDrone.Common.Extensions public static string GetParentPath(this string childPath) { - var cleanPath = childPath.GetCleanPath(); - - if (cleanPath.IsNullOrWhiteSpace()) - { - return null; - } - - var path = new OsPath(cleanPath).Directory; + var path = new OsPath(childPath).Directory; return path == OsPath.Null ? null : path.PathWithoutTrailingSlash; } @@ -134,7 +127,7 @@ namespace NzbDrone.Common.Extensions while (child.Directory != OsPath.Null) { - if (child.Directory.Equals(parent)) + if (child.Directory.Equals(parent, true)) { return true; }