sonarr-repo-only/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/FreeSpaceSpecification.cs

42 lines
1.4 KiB
C#
Raw Normal View History

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);
2013-08-08 16:24:23 +00:00
if (freeSpace < localEpisode.Size + 100.Megabytes())
{
_logger.Warn("Not enough free space to import: {0}", localEpisode);
return false;
}
return true;
}
}
}