Proposal: Length is definitive, fallback to modified if no length

pull/864/head
ta264 5 years ago committed by Qstick
parent 2be52c22d6
commit 8e777025cb

@ -27,7 +27,7 @@ namespace NzbDrone.Core.Test.MediaCoverTests
}
[Test]
public void should_return_false_if_file_exists_but_diffrent_date()
public void should_return_false_if_file_exists_but_different_date()
{
GivenFileExistsOnDisk(DateTime.Now);
@ -35,7 +35,7 @@ namespace NzbDrone.Core.Test.MediaCoverTests
}
[Test]
public void should_return_ture_if_file_exists_and_same_date_but_no_length_header()
public void should_return_true_if_file_exists_and_same_date_but_no_length_header()
{
var givenDate = DateTime.Now;
@ -45,12 +45,31 @@ namespace NzbDrone.Core.Test.MediaCoverTests
}
[Test]
public void should_return_ture_if_file_exists_and_date_header_is_null_but_has_length_header()
public void should_return_false_if_file_exists_and_same_date_but_length_header_different()
{
var givenDate = DateTime.Now;
GivenFileExistsOnDisk(givenDate);
Subject.AlreadyExists(givenDate, 999, "c:\\file.exe").Should().BeFalse();
}
[Test]
public void should_return_true_if_file_exists_and_date_header_is_null_but_has_length_header()
{
GivenFileExistsOnDisk(DateTime.Now);
Subject.AlreadyExists(null, 1000, "c:\\file.exe").Should().BeTrue();
}
[Test]
public void should_return_true_if_file_exists_and_date_header_is_different_but_length_header_the_same()
{
GivenFileExistsOnDisk(DateTime.Now.AddDays(-1));
Subject.AlreadyExists(DateTime.Now, 1000, "c:\\file.exe").Should().BeTrue();
}
}
}

@ -1,6 +1,5 @@
using System;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Http;
namespace NzbDrone.Core.MediaCover
{
@ -25,18 +24,18 @@ namespace NzbDrone.Core.MediaCover
return false;
}
if (serverModifiedDate.HasValue)
if (serverContentLength.HasValue && serverContentLength.Value > 0)
{
DateTime? lastModifiedLocal = _diskProvider.FileGetLastWrite(localPath);
var fileSize = _diskProvider.GetFileSize(localPath);
return lastModifiedLocal.Value.ToUniversalTime() == serverModifiedDate.Value.ToUniversalTime();
return fileSize == serverContentLength;
}
if (serverContentLength.HasValue && serverContentLength.Value > 0)
if (serverModifiedDate.HasValue)
{
var fileSize = _diskProvider.GetFileSize(localPath);
DateTime? lastModifiedLocal = _diskProvider.FileGetLastWrite(localPath);
return fileSize == serverContentLength;
return lastModifiedLocal.Value.ToUniversalTime() == serverModifiedDate.Value.ToUniversalTime();
}
return false;

Loading…
Cancel
Save