2017-08-31 02:42:40 +00:00
|
|
|
using System;
|
2013-08-22 15:34:51 +00:00
|
|
|
using System.IO;
|
|
|
|
using NLog;
|
2014-01-06 06:20:08 +00:00
|
|
|
using NzbDrone.Common.Disk;
|
2013-10-23 00:42:43 +00:00
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2013-08-22 15:34:51 +00:00
|
|
|
using NzbDrone.Core.Configuration;
|
2015-01-27 05:57:07 +00:00
|
|
|
using NzbDrone.Core.DecisionEngine;
|
2020-02-09 19:11:58 +00:00
|
|
|
using NzbDrone.Core.Download;
|
2013-08-22 15:34:51 +00:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
|
2017-08-31 02:42:40 +00:00
|
|
|
namespace NzbDrone.Core.MediaFiles.TrackImport.Specifications
|
2013-08-22 15:34:51 +00:00
|
|
|
{
|
2019-02-16 14:49:24 +00:00
|
|
|
public class NotUnpackingSpecification : IImportDecisionEngineSpecification<LocalTrack>
|
2013-08-22 15:34:51 +00:00
|
|
|
{
|
|
|
|
private readonly IDiskProvider _diskProvider;
|
|
|
|
private readonly IConfigService _configService;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
public NotUnpackingSpecification(IDiskProvider diskProvider, IConfigService configService, Logger logger)
|
|
|
|
{
|
|
|
|
_diskProvider = diskProvider;
|
|
|
|
_configService = configService;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2020-02-09 19:11:58 +00:00
|
|
|
public Decision IsSatisfiedBy(LocalTrack item, DownloadClientItem downloadClientItem)
|
2013-08-22 15:34:51 +00:00
|
|
|
{
|
2020-02-09 19:11:58 +00:00
|
|
|
if (item.ExistingFile)
|
2013-08-22 15:34:51 +00:00
|
|
|
{
|
2020-02-09 19:11:58 +00:00
|
|
|
_logger.Debug("{0} is in artist folder, skipping unpacking check", item.Path);
|
2015-01-27 05:57:07 +00:00
|
|
|
return Decision.Accept();
|
2013-08-22 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var workingFolder in _configService.DownloadClientWorkingFolders.Split('|'))
|
|
|
|
{
|
2023-05-23 10:52:39 +00:00
|
|
|
var parent = Directory.GetParent(item.Path);
|
2014-05-30 17:38:52 +00:00
|
|
|
while (parent != null)
|
2013-08-22 15:34:51 +00:00
|
|
|
{
|
2014-05-30 17:38:52 +00:00
|
|
|
if (parent.Name.StartsWith(workingFolder))
|
2013-10-23 00:42:43 +00:00
|
|
|
{
|
2014-12-07 20:54:07 +00:00
|
|
|
if (OsInfo.IsNotWindows)
|
2014-05-30 17:38:52 +00:00
|
|
|
{
|
2020-02-09 19:11:58 +00:00
|
|
|
_logger.Debug("{0} is still being unpacked", item.Path);
|
2015-01-27 05:57:07 +00:00
|
|
|
return Decision.Reject("File is still being unpacked");
|
2014-05-30 17:38:52 +00:00
|
|
|
}
|
2013-10-23 00:42:43 +00:00
|
|
|
|
2020-02-09 19:11:58 +00:00
|
|
|
if (_diskProvider.FileGetLastWrite(item.Path) > DateTime.UtcNow.AddMinutes(-5))
|
2014-05-30 17:38:52 +00:00
|
|
|
{
|
2020-02-09 19:11:58 +00:00
|
|
|
_logger.Debug("{0} appears to be unpacking still", item.Path);
|
2015-01-27 05:57:07 +00:00
|
|
|
return Decision.Reject("File is still being unpacked");
|
2014-05-30 17:38:52 +00:00
|
|
|
}
|
2013-08-22 15:34:51 +00:00
|
|
|
}
|
2014-05-30 17:38:52 +00:00
|
|
|
|
|
|
|
parent = parent.Parent;
|
2013-08-22 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 05:57:07 +00:00
|
|
|
return Decision.Accept();
|
2013-08-22 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|