1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-24 08:42:19 +02:00

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

Closes #7228
This commit is contained in:
Mark McDowall 2024-09-19 20:03:40 -07:00 committed by Mark McDowall
parent 75fae9262c
commit c199fd05d3
2 changed files with 11 additions and 6 deletions

View File

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

View File

@ -84,7 +84,7 @@ private bool ChangeFileDateToLocalAirDate(string filePath, string fileDate, stri
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 @@ private bool ChangeFileDateToLocalAirDate(string filePath, string fileDate, stri
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 @@ private bool ChangeFileDateToUtcAirDate(string filePath, DateTime airDateUtc)
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;