1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00

Fixed getting parent path from a path without another slash

Fixed: Manual Import failing for some paths
This commit is contained in:
Mark McDowall 2019-01-01 15:01:24 -08:00
parent 779ab39f50
commit d6997b0588
3 changed files with 19 additions and 1 deletions

View File

@ -140,6 +140,8 @@ public void path_should_be_parent_on_windows_only(string parentPath, string chil
[TestCase(@"C:\Test\mydir", @"C:\Test")]
[TestCase(@"C:\Test\", @"C:")]
[TestCase(@"C:\", null)]
[TestCase(@"/", null)]
[TestCase(@"/test", null)]
public void path_should_return_parent(string path, string parentPath)
{
path.GetParentPath().Should().Be(parentPath);

View File

@ -71,10 +71,11 @@ public static string GetParentPath(this string childPath)
var index = parentPath.LastIndexOfAny(new[] { '\\', '/' });
if (index != -1)
if (index > 0)
{
return parentPath.Substring(0, index);
}
return null;
}

View File

@ -317,5 +317,20 @@ public void should_use_folder_info_release_title_to_find_relative_path()
Mocker.GetMock<IMediaFileService>().Verify(v => v.Add(It.Is<EpisodeFile>(c => c.OriginalFilePath == $"{name}\\subfolder\\{name}.mkv".AsOsAgnostic())));
}
[Test]
public void should_get_relative_path_when_there_is_no_grandparent()
{
var name = "Series.Title.S01E01.720p.HDTV.x264-Sonarr";
var outputPath = Path.Combine(@"C:\".AsOsAgnostic());
var localEpisode = _approvedDecisions.First().LocalEpisode;
localEpisode.FolderEpisodeInfo = new ParsedEpisodeInfo { ReleaseTitle = name };
localEpisode.Path = Path.Combine(outputPath, name + ".mkv");
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true, null);
Mocker.GetMock<IMediaFileService>().Verify(v => v.Add(It.Is<EpisodeFile>(c => c.OriginalFilePath == $"{name}.mkv".AsOsAgnostic())));
}
}
}