checking for existing files to import is now case insensitive.

pull/4/head
Keivan Beigi 11 years ago
parent c13195046d
commit e377e02db4

@ -46,8 +46,7 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.AspNet.SignalR.Core.1.1.3\lib\net40\Microsoft.AspNet.SignalR.Core.dll</HintPath>
</Reference>
<Reference Include="Nancy, Version=0.18.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<Reference Include="Nancy">
<HintPath>..\packages\Nancy.0.18.0\lib\net40\Nancy.dll</HintPath>
</Reference>
<Reference Include="Nancy.Authentication.Basic, Version=0.18.0.0, Culture=neutral, processorArchitecture=MSIL">

@ -1,137 +0,0 @@
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Marr.Data;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.MediaFileTests.EpisodeImportTests
{
[TestFixture]
public class NotExistingFileSpecificationFixture : CoreTest<NotExistingFileSpecification>
{
private LocalEpisode _localEpisode;
[SetUp]
public void Setup()
{
_localEpisode = new LocalEpisode
{
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi".AsOsAgnostic(),
Size = 100
};
}
[Test]
public void should_return_false_if_path_and_size_are_the_same()
{
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.EpisodeFileId = 1)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
new EpisodeFile
{
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi".AsOsAgnostic(),
Size = 100
}))
.Build()
.ToList();
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
}
[Test]
public void should_return_false_if_filename_and_size_are_the_same()
{
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.EpisodeFileId = 1)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
new EpisodeFile
{
Path = @"C:\Test\30 Rock\Season 01\30.rock.s01e01.avi".AsOsAgnostic(),
Size = 100
}))
.Build()
.ToList();
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
}
[Test]
public void should_return_true_if_no_existing_file()
{
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.EpisodeFileId = 0)
.Build()
.ToList();
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_return_true_if_size_is_different()
{
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.EpisodeFileId = 1)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
new EpisodeFile
{
Path = @"C:\Test\30 Rock\Season 01\30.rock.s01e01.avi".AsOsAgnostic(),
Size = 50
}))
.Build()
.ToList();
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_return_true_if_file_names_are_different()
{
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.EpisodeFileId = 1)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
new EpisodeFile
{
Path = @"C:\Test\30 Rock\Season 01\30.rock.s01e01.pilot.avi".AsOsAgnostic(),
Size = 100
}))
.Build()
.ToList();
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_return_false_if_exact_path_exists_in_db()
{
Mocker.GetMock<IMediaFileService>()
.Setup(s => s.Exists(It.IsAny<string>()))
.Returns(true);
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.EpisodeFileId = 1)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
new EpisodeFile
{
Path = @"C:\Test\30 Rock\Season 01\30.rock.s01e01.pilot.avi".AsOsAgnostic(),
Size = 100
}))
.Build()
.ToList();
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
}
}
}

@ -80,5 +80,30 @@ 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_ignoring_case()
{
var files = new List<string>()
{
"c:\\file1.avi".AsOsAgnostic(),
"c:\\FILE2.avi".AsOsAgnostic(),
"c:\\file3.avi".AsOsAgnostic()
};
Mocker.GetMock<IMediaFileRepository>()
.Setup(c => c.GetFilesBySeries(It.IsAny<int>()))
.Returns(new List<EpisodeFile>
{
new EpisodeFile{Path = "c:\\file2.avi".AsOsAgnostic()}
});
Subject.FilterExistingFiles(files, 10).Should().HaveCount(2);
Subject.FilterExistingFiles(files, 10).Should().NotContain("c:\\file2.avi".AsOsAgnostic());
}
}
}

@ -1,9 +1,7 @@
using System;
using System.IO;
using System.Linq;
using NLog;
using NzbDrone.Common;
using NzbDrone.Core.Organizer;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications

@ -1,44 +0,0 @@
using System.IO;
using System.Linq;
using NLog;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
{
public class NotExistingFileSpecification : IImportDecisionEngineSpecification
{
private readonly IMediaFileService _mediaFileService;
private readonly Logger _logger;
public NotExistingFileSpecification(IMediaFileService mediaFileService, Logger logger)
{
_mediaFileService = mediaFileService;
_logger = logger;
}
public string RejectionReason { get { return "Existing File"; } }
public bool IsSatisfiedBy(LocalEpisode localEpisode)
{
if (_mediaFileService.Exists(localEpisode.Path))
{
_logger.Trace("File is a match for an existing episode file: {0}", localEpisode.Path);
return false;
}
var existingFiles = localEpisode.Episodes.Where(e => e.EpisodeFileId > 0).Select(e => e.EpisodeFile.Value);
foreach (var existingFile in existingFiles)
{
if (Path.GetFileName(existingFile.Path) == Path.GetFileName(localEpisode.Path) &&
existingFile.Size == localEpisode.Size)
{
_logger.Trace("File is a match for an existing episode file: {0}", localEpisode.Path);
return false;
}
}
return true;
}
}
}

@ -1,9 +1,7 @@
using System.IO;
using System.Linq;
using NLog;
using NzbDrone.Common;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
{

@ -4,6 +4,7 @@ using NLog;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Tv.Events;
using NzbDrone.Common;
namespace NzbDrone.Core.MediaFiles
{
@ -73,11 +74,11 @@ namespace NzbDrone.Core.MediaFiles
public List<string> FilterExistingFiles(List<string> files, int seriesId)
{
var seriesFiles = GetFilesBySeries(seriesId);
var seriesFiles = GetFilesBySeries(seriesId).Select(f => f.Path.CleanFilePath().ToLower()).ToList();
if (!seriesFiles.Any()) return files;
return files.Select(f => f.Normalize()).Except(seriesFiles.Select(c => c.Path)).ToList();
return files.Select(f => f.CleanFilePath().ToLower()).Except(seriesFiles).ToList();
}
public void HandleAsync(SeriesDeletedEvent message)

@ -89,8 +89,7 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Owin.Hosting.1.1.0-beta2\lib\net40\Microsoft.Owin.Hosting.dll</HintPath>
</Reference>
<Reference Include="Nancy, Version=0.18.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<Reference Include="Nancy">
<HintPath>..\packages\Nancy.0.18.0\lib\net40\Nancy.dll</HintPath>
</Reference>
<Reference Include="Nancy.Owin, Version=0.18.0.0, Culture=neutral, processorArchitecture=MSIL">

Loading…
Cancel
Save