1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-26 01:37:07 +00: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 @@ namespace NzbDrone.Common.Test
[TestCase(@"C:\Test\mydir", @"C:\Test")] [TestCase(@"C:\Test\mydir", @"C:\Test")]
[TestCase(@"C:\Test\", @"C:")] [TestCase(@"C:\Test\", @"C:")]
[TestCase(@"C:\", null)] [TestCase(@"C:\", null)]
[TestCase(@"/", null)]
[TestCase(@"/test", null)]
public void path_should_return_parent(string path, string parentPath) public void path_should_return_parent(string path, string parentPath)
{ {
path.GetParentPath().Should().Be(parentPath); path.GetParentPath().Should().Be(parentPath);

View file

@ -71,10 +71,11 @@ namespace NzbDrone.Common.Extensions
var index = parentPath.LastIndexOfAny(new[] { '\\', '/' }); var index = parentPath.LastIndexOfAny(new[] { '\\', '/' });
if (index != -1) if (index > 0)
{ {
return parentPath.Substring(0, index); return parentPath.Substring(0, index);
} }
return null; return null;
} }

View file

@ -317,5 +317,20 @@ namespace NzbDrone.Core.Test.MediaFiles
Mocker.GetMock<IMediaFileService>().Verify(v => v.Add(It.Is<EpisodeFile>(c => c.OriginalFilePath == $"{name}\\subfolder\\{name}.mkv".AsOsAgnostic()))); 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())));
}
} }
} }