From 0d6b9969d25f8748b840132d4dd63d623be45dc2 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 27 Aug 2013 12:13:11 -0700 Subject: [PATCH] FilterExistingFiles no longer converts paths to all lower case --- NzbDrone.Common/PathEqualityComparer.cs | 8 +++- .../MediaFileTests/MediaFileServiceTest.cs | 44 +++++++++++++++++-- NzbDrone.Core/MediaFiles/MediaFileService.cs | 4 +- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/NzbDrone.Common/PathEqualityComparer.cs b/NzbDrone.Common/PathEqualityComparer.cs index c70abb7b7..2bf854727 100644 --- a/NzbDrone.Common/PathEqualityComparer.cs +++ b/NzbDrone.Common/PathEqualityComparer.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using NzbDrone.Common.EnvironmentInfo; namespace NzbDrone.Common { @@ -14,7 +15,12 @@ namespace NzbDrone.Common public int GetHashCode(string obj) { - return obj.CleanFilePath().GetHashCode(); + if (OsInfo.IsLinux) + { + return obj.CleanFilePath().GetHashCode(); + } + + return obj.CleanFilePath().ToLower().GetHashCode(); } } } diff --git a/NzbDrone.Core.Test/MediaFileTests/MediaFileServiceTest.cs b/NzbDrone.Core.Test/MediaFileTests/MediaFileServiceTest.cs index c97082e3d..1e1060239 100644 --- a/NzbDrone.Core.Test/MediaFileTests/MediaFileServiceTest.cs +++ b/NzbDrone.Core.Test/MediaFileTests/MediaFileServiceTest.cs @@ -81,12 +81,11 @@ namespace NzbDrone.Core.Test.MediaFileTests Subject.FilterExistingFiles(files, 10).Should().NotContain("c:\\file2.avi".AsOsAgnostic()); } - - - [Test] public void filter_should_return_none_existing_files_ignoring_case() { + WindowsOnly(); + var files = new List() { "c:\\file1.avi".AsOsAgnostic(), @@ -105,5 +104,44 @@ namespace NzbDrone.Core.Test.MediaFileTests Subject.FilterExistingFiles(files, 10).Should().HaveCount(2); Subject.FilterExistingFiles(files, 10).Should().NotContain("c:\\file2.avi".AsOsAgnostic()); } + + [Test] + public void filter_should_return_none_existing_files_not_ignoring_case() + { + LinuxOnly(); + + var files = new List() + { + "c:\\file1.avi".AsOsAgnostic(), + "c:\\FILE2.avi".AsOsAgnostic(), + "c:\\file3.avi".AsOsAgnostic() + }; + + Mocker.GetMock() + .Setup(c => c.GetFilesBySeries(It.IsAny())) + .Returns(new List + { + new EpisodeFile{Path = "c:\\file2.avi".AsOsAgnostic()} + }); + + Subject.FilterExistingFiles(files, 10).Should().HaveCount(3); + } + + [Test] + public void filter_should_not_change_casing() + { + var files = new List() + { + "c:\\FILE1.avi".AsOsAgnostic() + }; + + Mocker.GetMock() + .Setup(c => c.GetFilesBySeries(It.IsAny())) + .Returns(new List()); + + Subject.FilterExistingFiles(files, 10).Should().HaveCount(1); + Subject.FilterExistingFiles(files, 10).Should().NotContain(files.First().ToLower()); + Subject.FilterExistingFiles(files, 10).Should().Contain(files.First()); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/MediaFiles/MediaFileService.cs b/NzbDrone.Core/MediaFiles/MediaFileService.cs index a2fe8ba22..54501c859 100644 --- a/NzbDrone.Core/MediaFiles/MediaFileService.cs +++ b/NzbDrone.Core/MediaFiles/MediaFileService.cs @@ -76,11 +76,11 @@ namespace NzbDrone.Core.MediaFiles public List FilterExistingFiles(List files, int seriesId) { - var seriesFiles = GetFilesBySeries(seriesId).Select(f => f.Path.CleanFilePath().ToLower()).ToList(); + var seriesFiles = GetFilesBySeries(seriesId).Select(f => f.Path.CleanFilePath()).ToList(); if (!seriesFiles.Any()) return files; - return files.Select(f => f.CleanFilePath().ToLower()).Except(seriesFiles).ToList(); + return files.Select(f => f.CleanFilePath()).Except(seriesFiles, new PathEqualityComparer()).ToList(); } public EpisodeFile Get(int id)