fixup! Fixed: Updating series path from different OS paths

This commit is contained in:
Mark McDowall 2024-07-14 09:00:17 -07:00
parent ff12c36204
commit 1e51854cb5
3 changed files with 16 additions and 13 deletions

View File

@ -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")]

View File

@ -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)
{

View File

@ -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;
}