You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/src/NzbDrone.Core/MediaCover/CoverAlreadyExistsSpecifica...

45 lines
1.3 KiB

using System;
using NzbDrone.Common.Disk;
namespace NzbDrone.Core.MediaCover
{
public interface ICoverExistsSpecification
{
bool AlreadyExists(DateTime? serverModifiedDate, long? serverContentLength, string localPath);
}
public class CoverAlreadyExistsSpecification : ICoverExistsSpecification
{
private readonly IDiskProvider _diskProvider;
public CoverAlreadyExistsSpecification(IDiskProvider diskProvider)
{
_diskProvider = diskProvider;
}
public bool AlreadyExists(DateTime? serverModifiedDate, long? serverContentLength, string localPath)
{
if (!_diskProvider.FileExists(localPath))
{
return false;
}
if (serverContentLength.HasValue && serverContentLength.Value > 0)
{
var fileSize = _diskProvider.GetFileSize(localPath);
return fileSize == serverContentLength;
}
if (serverModifiedDate.HasValue)
{
DateTime? lastModifiedLocal = _diskProvider.FileGetLastWrite(localPath);
return lastModifiedLocal.Value.ToUniversalTime() == serverModifiedDate.Value.ToUniversalTime();
}
return false;
}
}
}