Fixed: Do not remove directories when they contain a RAR file over 10MB

pull/6/head
Mark McDowall 10 years ago
parent fea906d45d
commit 6711ba2549

@ -77,7 +77,6 @@ namespace NzbDrone.Core.Test.Download
}); });
} }
[TestCase(DownloadItemStatus.Downloading)] [TestCase(DownloadItemStatus.Downloading)]
[TestCase(DownloadItemStatus.Failed)] [TestCase(DownloadItemStatus.Failed)]
[TestCase(DownloadItemStatus.Queued)] [TestCase(DownloadItemStatus.Queued)]
@ -92,7 +91,6 @@ namespace NzbDrone.Core.Test.Download
AssertNoAttemptedImport(); AssertNoAttemptedImport();
} }
[Test] [Test]
public void should_not_process_if_matching_history_is_not_found_and_no_category_specified() public void should_not_process_if_matching_history_is_not_found_and_no_category_specified()
{ {
@ -116,8 +114,6 @@ namespace NzbDrone.Core.Test.Download
AssertCompletedDownload(); AssertCompletedDownload();
} }
[Test] [Test]
public void should_not_process_if_storage_directory_in_drone_factory() public void should_not_process_if_storage_directory_in_drone_factory()
{ {
@ -132,7 +128,6 @@ namespace NzbDrone.Core.Test.Download
AssertNoAttemptedImport(); AssertNoAttemptedImport();
} }
[Test] [Test]
public void should_not_process_if_output_path_is_empty() public void should_not_process_if_output_path_is_empty()
{ {
@ -143,7 +138,6 @@ namespace NzbDrone.Core.Test.Download
AssertNoAttemptedImport(); AssertNoAttemptedImport();
} }
[Test] [Test]
public void should_not_mark_as_imported_if_all_files_were_rejected() public void should_not_mark_as_imported_if_all_files_were_rejected()
{ {

@ -210,6 +210,48 @@ namespace NzbDrone.Core.Test.MediaFiles
result.First().Result.Should().Be(ImportResultType.Rejected); result.First().Result.Should().Be(ImportResultType.Rejected);
} }
[Test]
public void should_not_delete_if_there_is_large_rar_file()
{
GivenValidSeries();
var localEpisode = new LocalEpisode();
var imported = new List<ImportDecision>();
imported.Add(new ImportDecision(localEpisode));
Mocker.GetMock<IMakeImportDecision>()
.Setup(s => s.GetImportDecisions(It.IsAny<List<String>>(), It.IsAny<Series>(), true, null))
.Returns(imported);
Mocker.GetMock<IImportApprovedEpisodes>()
.Setup(s => s.Import(It.IsAny<List<ImportDecision>>(), true, null))
.Returns(imported.Select(i => new ImportResult(i)).ToList());
Mocker.GetMock<ISampleService>()
.Setup(s => s.IsSample(It.IsAny<Series>(),
It.IsAny<QualityModel>(),
It.IsAny<String>(),
It.IsAny<Int64>(),
It.IsAny<Int32>()))
.Returns(true);
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetFiles(It.IsAny<string>(), SearchOption.AllDirectories))
.Returns(new []{ _videoFiles.First().Replace(".ext", ".rar") });
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetFileSize(It.IsAny<string>()))
.Returns(15.Megabytes());
Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory));
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(It.IsAny<String>(), true), Times.Never());
ExceptionVerification.ExpectedWarns(1);
}
private void VerifyNoImport() private void VerifyNoImport()
{ {
Mocker.GetMock<IImportApprovedEpisodes>().Verify(c => c.Import(It.IsAny<List<ImportDecision>>(), true, null), Mocker.GetMock<IImportApprovedEpisodes>().Verify(c => c.Import(It.IsAny<List<ImportDecision>>(), true, null),

@ -48,8 +48,6 @@ namespace NzbDrone.Core.MediaFiles
return _downloadedEpisodesImportService.ProcessRootFolder(new DirectoryInfo(downloadedEpisodesFolder)); return _downloadedEpisodesImportService.ProcessRootFolder(new DirectoryInfo(downloadedEpisodesFolder));
} }
public void Execute(DownloadedEpisodesScanCommand message) public void Execute(DownloadedEpisodesScanCommand message)
{ {
var importResults = ProcessDroneFactoryFolder(); var importResults = ProcessDroneFactoryFolder();

@ -183,6 +183,7 @@ namespace NzbDrone.Core.MediaFiles
private bool ShouldDeleteFolder(DirectoryInfo directoryInfo, Series series) private bool ShouldDeleteFolder(DirectoryInfo directoryInfo, Series series)
{ {
var videoFiles = _diskScanService.GetVideoFiles(directoryInfo.FullName); var videoFiles = _diskScanService.GetVideoFiles(directoryInfo.FullName);
var rarFiles = _diskProvider.GetFiles(directoryInfo.FullName, SearchOption.AllDirectories).Where(f => Path.GetExtension(f) == ".rar");
foreach (var videoFile in videoFiles) foreach (var videoFile in videoFiles)
{ {
@ -205,6 +206,12 @@ namespace NzbDrone.Core.MediaFiles
} }
} }
if (rarFiles.Any(f => _diskProvider.GetFileSize(f) > 10.Megabytes()))
{
_logger.Warn("RAR file detected, will require manual cleanup");
return false;
}
return true; return true;
} }

Loading…
Cancel
Save