mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-28 04:51:45 +02:00
Do not import episodes when destination doesn't have enough disk space
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user