skip episode folder if drop folder doesn't exist.

This commit is contained in:
Keivan Beigi 2013-07-16 10:55:11 -07:00
parent 3e0140f263
commit 9835608ff0
2 changed files with 40 additions and 17 deletions

View File

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.IO;
using FizzWare.NBuilder;
@ -7,11 +6,11 @@ using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.Commands;
using NzbDrone.Core.MediaFiles.EpisodeImport;
using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.MediaFileTests
{
@ -34,14 +33,20 @@ namespace NzbDrone.Core.Test.MediaFileTests
Mocker.GetMock<IDiskProvider>().Setup(c => c.GetDirectories(It.IsAny<string>()))
.Returns(_subFolders);
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(It.IsAny<string>()))
.Returns(true);
Mocker.GetMock<IConfigService>().SetupGet(c => c.DownloadedEpisodesFolder)
.Returns("c:\\drop\\");
}
[Test]
public void should_import_file()
{
Subject.ProcessDownloadedEpisodesFolder();
Subject.Execute(new DownloadedEpisodesScanCommand());
VerifyImport();
}
@ -49,18 +54,33 @@ namespace NzbDrone.Core.Test.MediaFileTests
[Test]
public void should_search_for_series_using_folder_name()
{
Subject.ProcessDownloadedEpisodesFolder();
Subject.Execute(new DownloadedEpisodesScanCommand());
Mocker.GetMock<IParsingService>().Verify(c => c.GetSeries("foldername"), Times.Once());
}
[Test]
public void should_skip_import_if_dropfolder_doesnt_exist()
{
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(It.IsAny<string>())).Returns(false);
Subject.Execute(new DownloadedEpisodesScanCommand());
Mocker.GetMock<IDiskProvider>().Verify(c => c.GetDirectories(It.IsAny<string>()), Times.Never());
Mocker.GetMock<IDiskProvider>().Verify(c => c.GetFiles(It.IsAny<string>(), It.IsAny<SearchOption>()), Times.Never());
ExceptionVerification.ExpectedWarns(1);
}
[Test]
public void should_skip_if_file_is_in_use_by_another_process()
{
Mocker.GetMock<IDiskProvider>().Setup(c => c.IsFileLocked(It.IsAny<FileInfo>()))
.Returns(true);
Subject.ProcessDownloadedEpisodesFolder();
Subject.Execute(new DownloadedEpisodesScanCommand());
VerifyNoImport();
}

View File

@ -18,7 +18,6 @@ namespace NzbDrone.Core.MediaFiles
private readonly IDiskProvider _diskProvider;
private readonly IDiskScanService _diskScanService;
private readonly ISeriesService _seriesService;
private readonly IMoveEpisodeFiles _episodeFileMover;
private readonly IParsingService _parsingService;
private readonly IConfigService _configService;
private readonly IMakeImportDecision _importDecisionMaker;
@ -28,7 +27,6 @@ namespace NzbDrone.Core.MediaFiles
public DownloadedEpisodesImportService(IDiskProvider diskProvider,
IDiskScanService diskScanService,
ISeriesService seriesService,
IMoveEpisodeFiles episodeFileMover,
IParsingService parsingService,
IConfigService configService,
IMakeImportDecision importDecisionMaker,
@ -38,7 +36,6 @@ namespace NzbDrone.Core.MediaFiles
_diskProvider = diskProvider;
_diskScanService = diskScanService;
_seriesService = seriesService;
_episodeFileMover = episodeFileMover;
_parsingService = parsingService;
_configService = configService;
_importDecisionMaker = importDecisionMaker;
@ -46,7 +43,7 @@ namespace NzbDrone.Core.MediaFiles
_logger = logger;
}
public void ProcessDownloadedEpisodesFolder()
private void ProcessDownloadedEpisodesFolder()
{
//TODO: We should also process the download client's category folder
var downloadedEpisodesFolder = _configService.DownloadedEpisodesFolder;
@ -57,24 +54,30 @@ namespace NzbDrone.Core.MediaFiles
return;
}
foreach (var subfolder in _diskProvider.GetDirectories(downloadedEpisodesFolder))
if (!_diskProvider.FolderExists(downloadedEpisodesFolder))
{
_logger.Warn("Downloaded Episodes Folder [{0}] doesn't exist.", downloadedEpisodesFolder);
return;
}
foreach (var subFolder in _diskProvider.GetDirectories(downloadedEpisodesFolder))
{
try
{
if (!_seriesService.SeriesPathExists(subfolder))
if (!_seriesService.SeriesPathExists(subFolder))
{
ProcessSubFolder(new DirectoryInfo(subfolder));
ProcessSubFolder(new DirectoryInfo(subFolder));
//Todo: We should make sure the file(s) are actually imported
if (_diskProvider.GetFolderSize(subfolder) < NotSampleSpecification.SampleSizeLimit)
if (_diskProvider.GetFolderSize(subFolder) < NotSampleSpecification.SampleSizeLimit)
{
_diskProvider.DeleteFolder(subfolder, true);
_diskProvider.DeleteFolder(subFolder, true);
}
}
}
catch (Exception e)
{
_logger.ErrorException("An error has occurred while importing folder: " + subfolder, e);
_logger.ErrorException("An error has occurred while importing folder: " + subFolder, e);
}
}