Fixed: Don't set last write time on episode files if difference is within the same second

Closes #7228
pull/7241/head
Mark McDowall 5 months ago committed by Mark McDowall
parent 75fae9262c
commit c199fd05d3

@ -1,4 +1,4 @@
using System;
using System;
namespace NzbDrone.Common.Extensions
{
@ -38,5 +38,10 @@ namespace NzbDrone.Common.Extensions
{
return dateTime >= afterDateTime && dateTime <= beforeDateTime;
}
public static DateTime WithoutTicks(this DateTime dateTime)
{
return dateTime.AddTicks(-(dateTime.Ticks % TimeSpan.TicksPerSecond));
}
}
}

@ -84,7 +84,7 @@ namespace NzbDrone.Core.MediaFiles
if (DateTime.TryParse(fileDate + ' ' + fileTime, out var airDate))
{
// avoiding false +ve checks and set date skewing by not using UTC (Windows)
var oldDateTime = _diskProvider.FileGetLastWrite(filePath);
var oldLastWrite = _diskProvider.FileGetLastWrite(filePath);
if (OsInfo.IsNotWindows && airDate < EpochTime)
{
@ -92,12 +92,12 @@ namespace NzbDrone.Core.MediaFiles
airDate = EpochTime;
}
if (!DateTime.Equals(airDate, oldDateTime))
if (!DateTime.Equals(airDate.WithoutTicks(), oldLastWrite.WithoutTicks()))
{
try
{
_diskProvider.FileSetLastWriteTime(filePath, airDate);
_logger.Debug("Date of file [{0}] changed from '{1}' to '{2}'", filePath, oldDateTime, airDate);
_logger.Debug("Date of file [{0}] changed from '{1}' to '{2}'", filePath, oldLastWrite, airDate);
return true;
}
@ -125,11 +125,11 @@ namespace NzbDrone.Core.MediaFiles
airDateUtc = EpochTime;
}
if (!DateTime.Equals(airDateUtc, oldLastWrite))
if (!DateTime.Equals(airDateUtc.WithoutTicks(), oldLastWrite.WithoutTicks()))
{
try
{
_diskProvider.FileSetLastWriteTime(filePath, airDateUtc);
_diskProvider.FileSetLastWriteTime(filePath, airDateUtc.AddMilliseconds(oldLastWrite.Millisecond));
_logger.Debug("Date of file [{0}] changed from '{1}' to '{2}'", filePath, oldLastWrite, airDateUtc);
return true;

Loading…
Cancel
Save