1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-26 04:33:01 +01:00

Directory write time is now calculated based on the most recent file write to any file inside of that directory.

This commit is contained in:
kay.one 2012-01-22 20:59:23 -08:00
parent a68c882032
commit ead5f37921
4 changed files with 60 additions and 7 deletions

View File

@ -1,5 +1,6 @@
// ReSharper disable InconsistentNaming
using System;
using System.IO;
using System.Linq;
using FluentAssertions;
@ -151,6 +152,29 @@ namespace NzbDrone.Common.Test
DiskProvider.PathEquals(first, second).Should().BeFalse();
}
[Test]
public void empty_folder_should_return_folder_modified_date()
{
var tempfolder = new DirectoryInfo(TempFolder);
Mocker.Resolve<DiskProvider>().GetLastDirectoryWrite(TempFolder).Should().Be(tempfolder.LastWriteTimeUtc);
}
[Test]
public void folder_should_return_correct_value_for_last_write()
{
var appPath = new EnviromentProvider().ApplicationPath;
Mocker.Resolve<DiskProvider>().GetLastDirectoryWrite(appPath).Should().BeOnOrAfter(DateTime.UtcNow.AddMinutes(-10));
Mocker.Resolve<DiskProvider>().GetLastDirectoryWrite(appPath).Should().BeBefore(DateTime.UtcNow);
}
[Test]
[Explicit]
public void check_last_write()
{
Console.WriteLine(Mocker.Resolve<DiskProvider>().GetLastDirectoryWrite(@"C:\DRIVERS"));
Console.WriteLine(new DirectoryInfo(@"C:\DRIVERS").LastWriteTimeUtc);
}
private void VerifyCopy()
{
BinFolder.Refresh();

View File

@ -31,7 +31,15 @@ namespace NzbDrone.Common
throw new DirectoryNotFoundException("Directory doesn't exist. " + path);
}
GetFiles(path, SearchOption.AllDirectories);
var dirFiles = GetFiles(path, SearchOption.AllDirectories).ToList();
if (!dirFiles.Any())
{
return new DirectoryInfo(path).LastWriteTimeUtc;
}
return dirFiles.Select(f => new FileInfo(f))
.Max(c => c.LastWriteTimeUtc);
}
public virtual bool FolderExists(string path)

View File

@ -20,10 +20,26 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
[TestFixture]
public class ProcessDownloadProviderFixture : CoreTest
{
private void WithOldWrite()
{
Mocker.GetMock<DiskProvider>()
.Setup(c => c.GetLastDirectoryWrite(It.IsAny<String>()))
.Returns(DateTime.Now.AddDays(-5));
}
private void WithRecentWrite()
{
Mocker.GetMock<DiskProvider>()
.Setup(c => c.GetLastDirectoryWrite(It.IsAny<String>()))
.Returns(DateTime.UtcNow);
}
[Test]
public void should_skip_if_folder_is_tagged_and_too_fresh()
{
WithStrictMocker();
WithRecentWrite();
var droppedFolder = new DirectoryInfo(TempFolder + "\\_test\\");
droppedFolder.Create();
@ -34,11 +50,11 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
[Test]
public void should_continue_processing_if_folder_is_tagged_and_not_fresh()
{
WithOldWrite();
var droppedFolder = new DirectoryInfo(TempFolder + "\\_test\\");
droppedFolder.Create();
droppedFolder.LastWriteTime = DateTime.Now.AddMinutes(-2);
//Act
Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries(It.IsAny<String>())).Returns<Series>(null).Verifiable();
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
@ -52,6 +68,8 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
[Test]
public void should_search_for_series_using_title_without_status()
{
WithOldWrite();
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\_unpack_The Office - S01E01 - Episode Title");
Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("office")).Returns<Series>(null).Verifiable();
@ -70,6 +88,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
{
//Setup
WithStrictMocker();
WithOldWrite();
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - S01E01 - Episode Title");
var taggedFolder = @"C:\Test\Unsorted TV\_UnknownSeries_The Office - S01E01 - Episode Title";
@ -91,6 +110,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
{
//Setup
WithStrictMocker();
WithOldWrite();
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - S01E01 - Episode Title");
var taggedFolder = @"C:\Test\Unsorted TV\_ParseError_The Office - S01E01 - Episode Title";
@ -120,6 +140,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
{
//Setup
WithStrictMocker();
WithOldWrite();
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - Season 01");
var taggedFolder = PostDownloadProvider.GetTaggedFolderName(droppedFolder, PostDownloadStatusType.Unknown);
@ -154,10 +175,10 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
public void folder_shouldnt_be_tagged_with_same_tag_again(string path)
{
//Setup
var droppedFolder = new DirectoryInfo(TempFolder + path);
droppedFolder.Create();
droppedFolder.LastWriteTime = DateTime.Now.AddHours(-1);
WithOldWrite();
//Act
Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries(It.IsAny<String>())).Returns<Series>(null);
@ -172,7 +193,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
public void folder_should_not_be_tagged_if_existing_tag_is_diffrent()
{
//Setup
WithOldWrite();
var droppedFolder = new DirectoryInfo(TempFolder + @"\_UnknownEpisode_The Office - S01E01 - Episode Title");
droppedFolder.Create();
droppedFolder.LastWriteTime = DateTime.Now.AddHours(-1);

View File

@ -50,7 +50,7 @@ namespace NzbDrone.Core.Providers
public virtual void ProcessDownload(DirectoryInfo subfolderInfo)
{
if (subfolderInfo.Name.StartsWith("_") && subfolderInfo.LastWriteTimeUtc.AddMinutes(1) > DateTime.UtcNow)
if (subfolderInfo.Name.StartsWith("_") && _diskProvider.GetLastDirectoryWrite(subfolderInfo.FullName).AddMinutes(2) > DateTime.UtcNow)
{
Logger.Trace("[{0}] is too fresh. skipping", subfolderInfo.Name);
return;