1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-24 22:36:19 -04:00

Fixed: Updating series path from different OS paths

Closes #6953
This commit is contained in:
Mark McDowall
2024-07-28 16:57:54 -07:00
committed by GitHub
parent 6dd85a5af9
commit e791f4b743
4 changed files with 162 additions and 42 deletions
@@ -92,26 +92,23 @@ namespace NzbDrone.Common.Extensions
public static string GetParentPath(this string childPath)
{
var cleanPath = childPath.GetCleanPath();
var path = new OsPath(childPath).Directory;
if (cleanPath.IsNullOrWhiteSpace())
{
return null;
}
return Directory.GetParent(cleanPath)?.FullName;
return path == OsPath.Null ? null : path.PathWithoutTrailingSlash;
}
public static string GetParentName(this string childPath)
{
var cleanPath = childPath.GetCleanPath();
var path = new OsPath(childPath).Directory;
if (cleanPath.IsNullOrWhiteSpace())
{
return null;
}
return path == OsPath.Null ? null : path.Name;
}
return Directory.GetParent(cleanPath)?.Name;
public static string GetDirectoryName(this string childPath)
{
var path = new OsPath(childPath);
return path == OsPath.Null ? null : path.Name;
}
public static string GetCleanPath(this string path)
@@ -125,27 +122,17 @@ namespace NzbDrone.Common.Extensions
public static bool IsParentPath(this string parentPath, string childPath)
{
if (parentPath != "/" && !parentPath.EndsWith(":\\"))
{
parentPath = parentPath.TrimEnd(Path.DirectorySeparatorChar);
}
var parent = new OsPath(parentPath);
var child = new OsPath(childPath);
if (childPath != "/" && !parentPath.EndsWith(":\\"))
while (child.Directory != OsPath.Null)
{
childPath = childPath.TrimEnd(Path.DirectorySeparatorChar);
}
var parent = new DirectoryInfo(parentPath);
var child = new DirectoryInfo(childPath);
while (child.Parent != null)
{
if (child.Parent.FullName.Equals(parent.FullName, DiskProviderBase.PathStringComparison))
if (child.Directory.Equals(parent, true))
{
return true;
}
child = child.Parent;
child = child.Directory;
}
return false;