skip episode folder if drop folder doesn't exist.
This commit is contained in:
parent
3e0140f263
commit
9835608ff0
|
@ -1,4 +1,3 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using FizzWare.NBuilder;
|
using FizzWare.NBuilder;
|
||||||
|
@ -7,11 +6,11 @@ using NUnit.Framework;
|
||||||
using NzbDrone.Common;
|
using NzbDrone.Common;
|
||||||
using NzbDrone.Core.Configuration;
|
using NzbDrone.Core.Configuration;
|
||||||
using NzbDrone.Core.MediaFiles;
|
using NzbDrone.Core.MediaFiles;
|
||||||
|
using NzbDrone.Core.MediaFiles.Commands;
|
||||||
using NzbDrone.Core.MediaFiles.EpisodeImport;
|
using NzbDrone.Core.MediaFiles.EpisodeImport;
|
||||||
using NzbDrone.Core.MediaFiles.Events;
|
|
||||||
using NzbDrone.Core.Parser;
|
using NzbDrone.Core.Parser;
|
||||||
using NzbDrone.Core.Tv;
|
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.MediaFileTests
|
namespace NzbDrone.Core.Test.MediaFileTests
|
||||||
{
|
{
|
||||||
|
@ -34,14 +33,20 @@ namespace NzbDrone.Core.Test.MediaFileTests
|
||||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.GetDirectories(It.IsAny<string>()))
|
Mocker.GetMock<IDiskProvider>().Setup(c => c.GetDirectories(It.IsAny<string>()))
|
||||||
.Returns(_subFolders);
|
.Returns(_subFolders);
|
||||||
|
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(It.IsAny<string>()))
|
||||||
|
.Returns(true);
|
||||||
|
|
||||||
Mocker.GetMock<IConfigService>().SetupGet(c => c.DownloadedEpisodesFolder)
|
Mocker.GetMock<IConfigService>().SetupGet(c => c.DownloadedEpisodesFolder)
|
||||||
.Returns("c:\\drop\\");
|
.Returns("c:\\drop\\");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_import_file()
|
public void should_import_file()
|
||||||
{
|
{
|
||||||
Subject.ProcessDownloadedEpisodesFolder();
|
Subject.Execute(new DownloadedEpisodesScanCommand());
|
||||||
|
|
||||||
VerifyImport();
|
VerifyImport();
|
||||||
}
|
}
|
||||||
|
@ -49,18 +54,33 @@ namespace NzbDrone.Core.Test.MediaFileTests
|
||||||
[Test]
|
[Test]
|
||||||
public void should_search_for_series_using_folder_name()
|
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());
|
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]
|
[Test]
|
||||||
public void should_skip_if_file_is_in_use_by_another_process()
|
public void should_skip_if_file_is_in_use_by_another_process()
|
||||||
{
|
{
|
||||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.IsFileLocked(It.IsAny<FileInfo>()))
|
Mocker.GetMock<IDiskProvider>().Setup(c => c.IsFileLocked(It.IsAny<FileInfo>()))
|
||||||
.Returns(true);
|
.Returns(true);
|
||||||
|
|
||||||
Subject.ProcessDownloadedEpisodesFolder();
|
Subject.Execute(new DownloadedEpisodesScanCommand());
|
||||||
|
|
||||||
VerifyNoImport();
|
VerifyNoImport();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
private readonly IDiskProvider _diskProvider;
|
private readonly IDiskProvider _diskProvider;
|
||||||
private readonly IDiskScanService _diskScanService;
|
private readonly IDiskScanService _diskScanService;
|
||||||
private readonly ISeriesService _seriesService;
|
private readonly ISeriesService _seriesService;
|
||||||
private readonly IMoveEpisodeFiles _episodeFileMover;
|
|
||||||
private readonly IParsingService _parsingService;
|
private readonly IParsingService _parsingService;
|
||||||
private readonly IConfigService _configService;
|
private readonly IConfigService _configService;
|
||||||
private readonly IMakeImportDecision _importDecisionMaker;
|
private readonly IMakeImportDecision _importDecisionMaker;
|
||||||
|
@ -28,7 +27,6 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
public DownloadedEpisodesImportService(IDiskProvider diskProvider,
|
public DownloadedEpisodesImportService(IDiskProvider diskProvider,
|
||||||
IDiskScanService diskScanService,
|
IDiskScanService diskScanService,
|
||||||
ISeriesService seriesService,
|
ISeriesService seriesService,
|
||||||
IMoveEpisodeFiles episodeFileMover,
|
|
||||||
IParsingService parsingService,
|
IParsingService parsingService,
|
||||||
IConfigService configService,
|
IConfigService configService,
|
||||||
IMakeImportDecision importDecisionMaker,
|
IMakeImportDecision importDecisionMaker,
|
||||||
|
@ -38,7 +36,6 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
_diskScanService = diskScanService;
|
_diskScanService = diskScanService;
|
||||||
_seriesService = seriesService;
|
_seriesService = seriesService;
|
||||||
_episodeFileMover = episodeFileMover;
|
|
||||||
_parsingService = parsingService;
|
_parsingService = parsingService;
|
||||||
_configService = configService;
|
_configService = configService;
|
||||||
_importDecisionMaker = importDecisionMaker;
|
_importDecisionMaker = importDecisionMaker;
|
||||||
|
@ -46,7 +43,7 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ProcessDownloadedEpisodesFolder()
|
private void ProcessDownloadedEpisodesFolder()
|
||||||
{
|
{
|
||||||
//TODO: We should also process the download client's category folder
|
//TODO: We should also process the download client's category folder
|
||||||
var downloadedEpisodesFolder = _configService.DownloadedEpisodesFolder;
|
var downloadedEpisodesFolder = _configService.DownloadedEpisodesFolder;
|
||||||
|
@ -57,24 +54,30 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
return;
|
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
|
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
|
//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)
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +124,7 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessFiles(new [] { videoFile }, series);
|
ProcessFiles(new[] { videoFile }, series);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessFiles(IEnumerable<string> videoFiles, Series series)
|
private void ProcessFiles(IEnumerable<string> videoFiles, Series series)
|
||||||
|
|
Loading…
Reference in New Issue