1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Do not import episodes when destination doesn't have enough disk space

This commit is contained in:
Mark McDowall 2013-08-08 08:52:22 -07:00
parent 157e299698
commit fca4d20046
4 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,75 @@
using System;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.MediaFileTests.EpisodeImportTests
{
[TestFixture]
public class FreeSpaceSpecificationFixture : CoreTest<FreeSpaceSpecification>
{
private Series _series;
private LocalEpisode _localEpisode;
[SetUp]
public void Setup()
{
_series = Builder<Series>.CreateNew()
.With(s => s.SeriesType = SeriesTypes.Standard)
.Build();
var episodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.SeasonNumber = 1)
.Build()
.ToList();
_localEpisode = new LocalEpisode
{
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi",
Episodes = episodes,
Series = _series
};
}
private void GivenFileSize(long size)
{
_localEpisode.Size = size;
}
private void GivenFreeSpace(long size)
{
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetAvilableSpace(It.IsAny<String>()))
.Returns(size);
}
[Test]
public void should_reject_when_there_isnt_enough_disk_space()
{
GivenFileSize(100.Megabytes());
GivenFreeSpace(80.Megabytes());
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
ExceptionVerification.ExpectedWarns(1);
}
[Test]
public void should_accept_when_there_is_enough_disk_space()
{
GivenFileSize(100.Megabytes());
GivenFreeSpace(1.Gigabytes());
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
}
}

View File

@ -129,6 +129,7 @@
<Compile Include="JobTests\TestJobs.cs" /> <Compile Include="JobTests\TestJobs.cs" />
<Compile Include="MediaCoverTests\CoverExistsSpecificationFixture.cs" /> <Compile Include="MediaCoverTests\CoverExistsSpecificationFixture.cs" />
<Compile Include="MediaCoverTests\MediaCoverServiceFixture.cs" /> <Compile Include="MediaCoverTests\MediaCoverServiceFixture.cs" />
<Compile Include="MediaFileTests\EpisodeImportTests\FreeSpaceSpecificationFixture.cs" />
<Compile Include="MediaFileTests\RenameEpisodeFileServiceFixture.cs" /> <Compile Include="MediaFileTests\RenameEpisodeFileServiceFixture.cs" />
<Compile Include="MediaFileTests\UpgradeMediaFileServiceFixture.cs" /> <Compile Include="MediaFileTests\UpgradeMediaFileServiceFixture.cs" />
<Compile Include="MediaFileTests\EpisodeImportTests\NotExistingFileSpecificationFixture.cs" /> <Compile Include="MediaFileTests\EpisodeImportTests\NotExistingFileSpecificationFixture.cs" />

View File

@ -0,0 +1,41 @@
using System.IO;
using System.Linq;
using NLog;
using NzbDrone.Common;
using NzbDrone.Core.Organizer;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
{
public class FreeSpaceSpecification : IImportDecisionEngineSpecification
{
private readonly IBuildFileNames _buildFileNames;
private readonly IDiskProvider _diskProvider;
private readonly Logger _logger;
public FreeSpaceSpecification(IBuildFileNames buildFileNames, IDiskProvider diskProvider, Logger logger)
{
_buildFileNames = buildFileNames;
_diskProvider = diskProvider;
_logger = logger;
}
public string RejectionReason { get { return "Not enough free space"; } }
public bool IsSatisfiedBy(LocalEpisode localEpisode)
{
var newFileName = Path.GetFileNameWithoutExtension(localEpisode.Path);
var destinationFilename = _buildFileNames.BuildFilePath(localEpisode.Series, localEpisode.SeasonNumber, newFileName, Path.GetExtension(localEpisode.Path));
var freeSpace = _diskProvider.GetAvilableSpace(destinationFilename);
if (freeSpace < localEpisode.Size)
{
_logger.Warn("Not enough free space to import: {0}", localEpisode);
return false;
}
return true;
}
}
}

View File

@ -224,6 +224,7 @@
<Compile Include="MediaFiles\EpisodeImport\IImportDecisionEngineSpecification.cs" /> <Compile Include="MediaFiles\EpisodeImport\IImportDecisionEngineSpecification.cs" />
<Compile Include="MediaFiles\EpisodeImport\ImportDecisionMaker.cs" /> <Compile Include="MediaFiles\EpisodeImport\ImportDecisionMaker.cs" />
<Compile Include="MediaFiles\EpisodeImport\ImportApprovedEpisodes.cs" /> <Compile Include="MediaFiles\EpisodeImport\ImportApprovedEpisodes.cs" />
<Compile Include="MediaFiles\EpisodeImport\Specifications\FreeSpaceSpecification.cs" />
<Compile Include="MediaFiles\EpisodeImport\Specifications\NotExistingFileSpecification.cs" /> <Compile Include="MediaFiles\EpisodeImport\Specifications\NotExistingFileSpecification.cs" />
<Compile Include="MediaFiles\EpisodeImport\Specifications\UpgradeSpecification.cs" /> <Compile Include="MediaFiles\EpisodeImport\Specifications\UpgradeSpecification.cs" />
<Compile Include="MediaFiles\EpisodeImport\Specifications\NotSampleSpecification.cs" /> <Compile Include="MediaFiles\EpisodeImport\Specifications\NotSampleSpecification.cs" />