2013-08-19 18:19:39 +03:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
2013-08-08 18:52:22 +03:00
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Common;
|
|
|
|
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 04:40:24 +03:00
|
|
|
public FreeSpaceSpecification(IDiskProvider diskProvider, Logger logger)
|
2013-08-08 18:52:22 +03:00
|
|
|
{
|
|
|
|
_diskProvider = diskProvider;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string RejectionReason { get { return "Not enough free space"; } }
|
|
|
|
|
|
|
|
public bool IsSatisfiedBy(LocalEpisode localEpisode)
|
2013-08-12 18:29:01 +03:00
|
|
|
{
|
2013-08-19 18:19:39 +03:00
|
|
|
try
|
|
|
|
{
|
|
|
|
var path = Directory.GetParent(localEpisode.Series.Path);
|
2013-09-01 07:38:06 +03:00
|
|
|
var freeSpace = _diskProvider.GetAvailableSpace(path.FullName);
|
2013-08-19 18:19:39 +03:00
|
|
|
|
|
|
|
if (freeSpace < localEpisode.Size + 100.Megabytes())
|
|
|
|
{
|
|
|
|
_logger.Warn("Not enough free space to import: {0}", localEpisode);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
2013-08-08 18:52:22 +03:00
|
|
|
{
|
2013-08-19 18:19:39 +03:00
|
|
|
_logger.ErrorException("Unable to check free disk space while importing: " + localEpisode.Path, ex);
|
2013-08-08 18:52:22 +03:00
|
|
|
}
|
2013-09-10 18:31:58 +03:00
|
|
|
|
|
|
|
return true;
|
2013-08-08 18:52:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|