FreeSpaceSpec will return true is free space check returns null

This commit is contained in:
Mark McDowall 2013-09-13 17:41:14 -07:00
parent 89d603d71c
commit d4096f8786
7 changed files with 34 additions and 12 deletions

View File

@ -123,14 +123,24 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
[Test]
public void should_skip_check_for_files_under_series_folder()
{
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.IsParent(It.IsAny<String>(), It.IsAny<String>()))
.Returns(true);
_localEpisode.ExistingFile = true;
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
Mocker.GetMock<IDiskProvider>()
.Verify(s => s.GetAvailableSpace(It.IsAny<String>()), Times.Never());
}
[Test]
public void should_return_true_if_free_space_is_null()
{
long? freeSpace = null;
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetAvailableSpace(It.IsAny<String>()))
.Returns(freeSpace);
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
}
}

View File

@ -29,9 +29,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
private void GivenChildOfSeries()
{
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.IsParent(_localEpisode.Series.Path, _localEpisode.Path))
.Returns(true);
_localEpisode.ExistingFile = true;
}
private void GivenNewFile()

View File

@ -23,7 +23,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
{
try
{
if (_diskProvider.IsParent(localEpisode.Series.Path, localEpisode.Path))
if (localEpisode.ExistingFile)
{
_logger.Trace("Skipping free space check for existing episode");
return true;
@ -32,6 +32,12 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
var path = Directory.GetParent(localEpisode.Series.Path);
var freeSpace = _diskProvider.GetAvailableSpace(path.FullName);
if (!freeSpace.HasValue)
{
_logger.Trace("Free space check returned an invalid result for: {0}", path);
return true;
}
if (freeSpace < localEpisode.Size + 100.Megabytes())
{
_logger.Warn("Not enough free space to import: {0}", localEpisode);

View File

@ -19,7 +19,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
public bool IsSatisfiedBy(LocalEpisode localEpisode)
{
if (_diskProvider.IsParent(localEpisode.Series.Path, localEpisode.Path))
if (localEpisode.ExistingFile)
{
_logger.Trace("{0} is in series folder, skipping in use check", localEpisode.Path);
return true;

View File

@ -24,7 +24,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
public bool IsSatisfiedBy(LocalEpisode localEpisode)
{
if (_diskProvider.IsParent(localEpisode.Series.Path, localEpisode.Path))
if (localEpisode.ExistingFile)
{
_logger.Trace("{0} is in series folder, unpacking check", localEpisode.Path);
return true;

View File

@ -7,12 +7,13 @@ namespace NzbDrone.Core.Parser.Model
{
public class LocalEpisode
{
public string Path { get; set; }
public String Path { get; set; }
public Int64 Size { get; set; }
public ParsedEpisodeInfo ParsedEpisodeInfo { get; set; }
public Series Series { get; set; }
public List<Episode> Episodes { get; set; }
public QualityModel Quality { get; set; }
public Boolean ExistingFile { get; set; }
public int SeasonNumber
{

View File

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Common;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Tv;
@ -18,12 +19,17 @@ namespace NzbDrone.Core.Parser
{
private readonly IEpisodeService _episodeService;
private readonly ISeriesService _seriesService;
private readonly IDiskProvider _diskProvider;
private readonly Logger _logger;
public ParsingService(IEpisodeService episodeService, ISeriesService seriesService, Logger logger)
public ParsingService(IEpisodeService episodeService,
ISeriesService seriesService,
IDiskProvider diskProvider,
Logger logger)
{
_episodeService = episodeService;
_seriesService = seriesService;
_diskProvider = diskProvider;
_logger = logger;
}
@ -54,7 +60,8 @@ namespace NzbDrone.Core.Parser
Quality = parsedEpisodeInfo.Quality,
Episodes = episodes,
Path = filename,
ParsedEpisodeInfo = parsedEpisodeInfo
ParsedEpisodeInfo = parsedEpisodeInfo,
ExistingFile = _diskProvider.IsParent(series.Path, filename)
};
}