2013-08-08 15:52:22 +00:00
|
|
|
|
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 IDiskProvider _diskProvider;
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
2013-08-09 01:40:24 +00:00
|
|
|
|
public FreeSpaceSpecification(IDiskProvider diskProvider, Logger logger)
|
2013-08-08 15:52:22 +00:00
|
|
|
|
{
|
|
|
|
|
_diskProvider = diskProvider;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string RejectionReason { get { return "Not enough free space"; } }
|
|
|
|
|
|
|
|
|
|
public bool IsSatisfiedBy(LocalEpisode localEpisode)
|
2013-08-12 15:29:01 +00:00
|
|
|
|
{
|
|
|
|
|
var path = Directory.GetParent(localEpisode.Series.Path);
|
|
|
|
|
var freeSpace = _diskProvider.GetAvilableSpace(path.FullName);
|
2013-08-08 15:52:22 +00:00
|
|
|
|
|
2013-08-08 16:24:23 +00:00
|
|
|
|
if (freeSpace < localEpisode.Size + 100.Megabytes())
|
2013-08-08 15:52:22 +00:00
|
|
|
|
{
|
|
|
|
|
_logger.Warn("Not enough free space to import: {0}", localEpisode);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|