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:
parent
a68c882032
commit
ead5f37921
|
@ -1,5 +1,6 @@
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
|
@ -151,6 +152,29 @@ namespace NzbDrone.Common.Test
|
||||||
DiskProvider.PathEquals(first, second).Should().BeFalse();
|
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()
|
private void VerifyCopy()
|
||||||
{
|
{
|
||||||
BinFolder.Refresh();
|
BinFolder.Refresh();
|
||||||
|
|
|
@ -31,7 +31,15 @@ namespace NzbDrone.Common
|
||||||
throw new DirectoryNotFoundException("Directory doesn't exist. " + path);
|
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)
|
public virtual bool FolderExists(string path)
|
||||||
|
|
|
@ -20,10 +20,26 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class ProcessDownloadProviderFixture : CoreTest
|
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]
|
[Test]
|
||||||
public void should_skip_if_folder_is_tagged_and_too_fresh()
|
public void should_skip_if_folder_is_tagged_and_too_fresh()
|
||||||
{
|
{
|
||||||
WithStrictMocker();
|
WithStrictMocker();
|
||||||
|
WithRecentWrite();
|
||||||
|
|
||||||
var droppedFolder = new DirectoryInfo(TempFolder + "\\_test\\");
|
var droppedFolder = new DirectoryInfo(TempFolder + "\\_test\\");
|
||||||
droppedFolder.Create();
|
droppedFolder.Create();
|
||||||
|
@ -34,11 +50,11 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
||||||
[Test]
|
[Test]
|
||||||
public void should_continue_processing_if_folder_is_tagged_and_not_fresh()
|
public void should_continue_processing_if_folder_is_tagged_and_not_fresh()
|
||||||
{
|
{
|
||||||
|
WithOldWrite();
|
||||||
|
|
||||||
var droppedFolder = new DirectoryInfo(TempFolder + "\\_test\\");
|
var droppedFolder = new DirectoryInfo(TempFolder + "\\_test\\");
|
||||||
droppedFolder.Create();
|
droppedFolder.Create();
|
||||||
|
|
||||||
droppedFolder.LastWriteTime = DateTime.Now.AddMinutes(-2);
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries(It.IsAny<String>())).Returns<Series>(null).Verifiable();
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries(It.IsAny<String>())).Returns<Series>(null).Verifiable();
|
||||||
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
||||||
|
@ -52,6 +68,8 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
||||||
[Test]
|
[Test]
|
||||||
public void should_search_for_series_using_title_without_status()
|
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");
|
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();
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("office")).Returns<Series>(null).Verifiable();
|
||||||
|
@ -70,6 +88,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
||||||
{
|
{
|
||||||
//Setup
|
//Setup
|
||||||
WithStrictMocker();
|
WithStrictMocker();
|
||||||
|
WithOldWrite();
|
||||||
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - S01E01 - Episode Title");
|
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";
|
var taggedFolder = @"C:\Test\Unsorted TV\_UnknownSeries_The Office - S01E01 - Episode Title";
|
||||||
|
@ -91,6 +110,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
||||||
{
|
{
|
||||||
//Setup
|
//Setup
|
||||||
WithStrictMocker();
|
WithStrictMocker();
|
||||||
|
WithOldWrite();
|
||||||
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - S01E01 - Episode Title");
|
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";
|
var taggedFolder = @"C:\Test\Unsorted TV\_ParseError_The Office - S01E01 - Episode Title";
|
||||||
|
@ -120,6 +140,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
||||||
{
|
{
|
||||||
//Setup
|
//Setup
|
||||||
WithStrictMocker();
|
WithStrictMocker();
|
||||||
|
WithOldWrite();
|
||||||
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - Season 01");
|
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - Season 01");
|
||||||
|
|
||||||
var taggedFolder = PostDownloadProvider.GetTaggedFolderName(droppedFolder, PostDownloadStatusType.Unknown);
|
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)
|
public void folder_shouldnt_be_tagged_with_same_tag_again(string path)
|
||||||
{
|
{
|
||||||
//Setup
|
//Setup
|
||||||
|
|
||||||
var droppedFolder = new DirectoryInfo(TempFolder + path);
|
var droppedFolder = new DirectoryInfo(TempFolder + path);
|
||||||
droppedFolder.Create();
|
droppedFolder.Create();
|
||||||
droppedFolder.LastWriteTime = DateTime.Now.AddHours(-1);
|
WithOldWrite();
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries(It.IsAny<String>())).Returns<Series>(null);
|
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()
|
public void folder_should_not_be_tagged_if_existing_tag_is_diffrent()
|
||||||
{
|
{
|
||||||
//Setup
|
//Setup
|
||||||
|
WithOldWrite();
|
||||||
var droppedFolder = new DirectoryInfo(TempFolder + @"\_UnknownEpisode_The Office - S01E01 - Episode Title");
|
var droppedFolder = new DirectoryInfo(TempFolder + @"\_UnknownEpisode_The Office - S01E01 - Episode Title");
|
||||||
droppedFolder.Create();
|
droppedFolder.Create();
|
||||||
droppedFolder.LastWriteTime = DateTime.Now.AddHours(-1);
|
droppedFolder.LastWriteTime = DateTime.Now.AddHours(-1);
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace NzbDrone.Core.Providers
|
||||||
|
|
||||||
public virtual void ProcessDownload(DirectoryInfo subfolderInfo)
|
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);
|
Logger.Trace("[{0}] is too fresh. skipping", subfolderInfo.Name);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue