mirror of https://github.com/Sonarr/Sonarr
Fixed: NzbDrone running on Windows should no longer fail while getting a very long path from a sabnzbd running on linux.
This commit is contained in:
parent
34edeac391
commit
839a2ac742
|
@ -136,6 +136,23 @@ namespace NzbDrone.Common.Test
|
||||||
parentPath.IsParentPath(childPath).Should().Be(expectedResult);
|
parentPath.IsParentPath(childPath).Should().Be(expectedResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestCase(@"C:\Test\mydir", @"C:\Test")]
|
||||||
|
[TestCase(@"C:\Test\", @"C:")]
|
||||||
|
[TestCase(@"C:\", null)]
|
||||||
|
public void path_should_return_parent(string path, string parentPath)
|
||||||
|
{
|
||||||
|
path.GetParentPath().Should().Be(parentPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void path_should_return_parent_for_oversized_path()
|
||||||
|
{
|
||||||
|
var path = @"/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 = @"/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";
|
||||||
|
|
||||||
|
path.GetParentPath().Should().Be(parentPath);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[Ignore]
|
[Ignore]
|
||||||
public void should_not_be_parent_when_it_is_grandparent()
|
public void should_not_be_parent_when_it_is_grandparent()
|
||||||
|
|
|
@ -53,6 +53,22 @@ namespace NzbDrone.Common
|
||||||
return childPath.Substring(parentPath.Length).Trim(Path.DirectorySeparatorChar);
|
return childPath.Substring(parentPath.Length).Trim(Path.DirectorySeparatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetParentPath(this string childPath)
|
||||||
|
{
|
||||||
|
var parentPath = childPath.TrimEnd('\\', '/');
|
||||||
|
|
||||||
|
var index = parentPath.LastIndexOfAny(new[] { '\\', '/' });
|
||||||
|
|
||||||
|
if (index != -1)
|
||||||
|
{
|
||||||
|
return parentPath.Substring(0, index);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static bool IsParentPath(this string parentPath, string childPath)
|
public static bool IsParentPath(this string parentPath, string childPath)
|
||||||
{
|
{
|
||||||
parentPath = parentPath.TrimEnd(Path.DirectorySeparatorChar);
|
parentPath = parentPath.TrimEnd(Path.DirectorySeparatorChar);
|
||||||
|
|
|
@ -161,10 +161,10 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
|
||||||
|
|
||||||
if (!sabHistoryItem.Storage.IsNullOrWhiteSpace())
|
if (!sabHistoryItem.Storage.IsNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
var parent = Directory.GetParent(sabHistoryItem.Storage);
|
var parent = sabHistoryItem.Storage.GetParentPath();
|
||||||
if (parent != null && parent.Name == sabHistoryItem.Title)
|
if (parent != null && Path.GetFileName(parent) == sabHistoryItem.Title)
|
||||||
{
|
{
|
||||||
historyItem.OutputPath = parent.FullName;
|
historyItem.OutputPath = parent;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue