diff --git a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/SameFileSpecificationFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/SameFileSpecificationFixture.cs new file mode 100644 index 000000000..41b36d971 --- /dev/null +++ b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/SameFileSpecificationFixture.cs @@ -0,0 +1,67 @@ +using System.Linq; +using FizzWare.NBuilder; +using FluentAssertions; +using Marr.Data; +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; + +namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications +{ + [TestFixture] + public class SameFileSpecificationFixture : CoreTest + { + private LocalMovie _localMovie; + + [SetUp] + public void Setup() + { + _localMovie = Builder.CreateNew() + .With(l => l.Size = 150.Megabytes()) + .Build(); + } + + [Test] + public void should_be_accepted_if_no_existing_file() + { + _localMovie.Movie = Builder.CreateNew() + .With(e => e.MovieFileId = 0) + .Build(); + + Subject.IsSatisfiedBy(_localMovie, null).Accepted.Should().BeTrue(); + } + + [Test] + public void should_be_accepted_if_file_size_is_different() + { + _localMovie.Movie = Builder.CreateNew() + .With(e => e.MovieFileId = 1) + .With(e => e.MovieFile = new LazyLoaded( + new MovieFile + { + Size = _localMovie.Size + 100.Megabytes() + })) + .Build(); + + Subject.IsSatisfiedBy(_localMovie, null).Accepted.Should().BeTrue(); + } + + [Test] + public void should_be_reject_if_file_size_is_the_same() + { + _localMovie.Movie = Builder.CreateNew() + .With(e => e.MovieFileId = 1) + .With(e => e.MovieFile = new LazyLoaded( + new MovieFile + { + Size = _localMovie.Size + })) + .Build(); + + Subject.IsSatisfiedBy(_localMovie, null).Accepted.Should().BeFalse(); + } + } +} diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 3dd29e30a..df5b4d375 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -282,6 +282,7 @@ + diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/SameFileSpecification.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/SameFileSpecification.cs new file mode 100644 index 000000000..7eeb93684 --- /dev/null +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/SameFileSpecification.cs @@ -0,0 +1,42 @@ +using System.Linq; +using NLog; +using NzbDrone.Core.DecisionEngine; +using NzbDrone.Core.Download; +using NzbDrone.Core.Parser.Model; + +namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications +{ + public class SameFileSpecification : IImportDecisionEngineSpecification + { + private readonly Logger _logger; + + public SameFileSpecification(Logger logger) + { + _logger = logger; + } + + public Decision IsSatisfiedBy(LocalEpisode localEpisode) + { + return Decision.Accept(); + } + + public Decision IsSatisfiedBy(LocalMovie localMovie, DownloadClientItem downloadClientItem) + { + var movieFile = localMovie.Movie.MovieFile; + + if (localMovie.Movie.MovieFileId == 0) + { + _logger.Debug("No existing movie file, skipping"); + return Decision.Accept(); + } + + if (movieFile.Size == localMovie.Size) + { + _logger.Debug("'{0}' Has the same filesize as existing file", localMovie.Path); + return Decision.Reject("Has the same filesize as existing file"); + } + + return Decision.Accept(); + } + } +} diff --git a/src/NzbDrone.Core/MediaFiles/UpdateMovieFileService.cs b/src/NzbDrone.Core/MediaFiles/UpdateMovieFileService.cs index 4c40f6b1e..a75679a31 100644 --- a/src/NzbDrone.Core/MediaFiles/UpdateMovieFileService.cs +++ b/src/NzbDrone.Core/MediaFiles/UpdateMovieFileService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -79,21 +79,24 @@ namespace NzbDrone.Core.MediaFiles private bool ChangeFileDate(string filePath, DateTime date) { - DateTime oldDateTime = _diskProvider.FileGetLastWrite(filePath); + DateTime oldDateTime; - if (!DateTime.Equals(date, oldDateTime)) + if (DateTime.TryParse(_diskProvider.FileGetLastWrite(filePath).ToLongDateString(), out oldDateTime)) { - try + if (!DateTime.Equals(date, oldDateTime)) { - _diskProvider.FileSetLastWriteTime(filePath, date); - _logger.Debug("Date of file [{0}] changed from '{1}' to '{2}'", filePath, oldDateTime, date); + try + { + _diskProvider.FileSetLastWriteTime(filePath, date); + _logger.Debug("Date of file [{0}] changed from '{1}' to '{2}'", filePath, oldDateTime, date); - return true; - } + return true; + } - catch (Exception ex) - { - _logger.Warn(ex, "Unable to set date of file [" + filePath + "]"); + catch (Exception ex) + { + _logger.Warn(ex, "Unable to set date of file [" + filePath + "]"); + } } } diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index dd036ede6..f733517e7 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -130,6 +130,7 @@ + diff --git a/src/UI/Content/form.less b/src/UI/Content/form.less index 4632e40f2..58c80d190 100644 --- a/src/UI/Content/form.less +++ b/src/UI/Content/form.less @@ -41,6 +41,7 @@ .help-inline { display : inline-block; + margin-top : 8px; padding-left : 0px; @media (max-width: @screen-xs-max) {