From 41867c25f8438eb34dddba9d058e32c73638b4f5 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Sat, 17 Dec 2022 13:09:33 +0200 Subject: Use QFileInfo's file times in UTC for file timestamps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is inherently faster than getting it in UTC from the underlying native API stat call, then converting it to the Local Time Zone just to compare them. The same goes for any use-case where you get a QDateTime then the first thing you do is call t.to{Msec,Secs}SinceEpoch(). Change-Id: Ic13bcfd99b937c9f10f102ea7741832950a553c6 Reviewed-by: Thiago Macieira Reviewed-by: Kai Köhne --- src/corelib/io/qfilesystemwatcher_polling_p.h | 4 ++-- src/corelib/io/qlockfile.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qfilesystemwatcher_polling_p.h b/src/corelib/io/qfilesystemwatcher_polling_p.h index a12ff4b540..2d7423b39d 100644 --- a/src/corelib/io/qfilesystemwatcher_polling_p.h +++ b/src/corelib/io/qfilesystemwatcher_polling_p.h @@ -46,7 +46,7 @@ class QPollingFileSystemWatcherEngine : public QFileSystemWatcherEngine : ownerId(fileInfo.ownerId()), groupId(fileInfo.groupId()), permissions(fileInfo.permissions()), - lastModified(fileInfo.lastModified()) + lastModified(fileInfo.lastModified(QTimeZone::UTC)) { if (fileInfo.isDir()) { entries = fileInfo.absoluteDir().entryList(QDir::AllEntries); @@ -65,7 +65,7 @@ class QPollingFileSystemWatcherEngine : public QFileSystemWatcherEngine return (ownerId != fileInfo.ownerId() || groupId != fileInfo.groupId() || permissions != fileInfo.permissions() - || lastModified != fileInfo.lastModified()); + || lastModified != fileInfo.lastModified(QTimeZone::UTC)); } }; diff --git a/src/corelib/io/qlockfile.cpp b/src/corelib/io/qlockfile.cpp index 522bb081ee..5a452226e0 100644 --- a/src/corelib/io/qlockfile.cpp +++ b/src/corelib/io/qlockfile.cpp @@ -255,7 +255,7 @@ bool QLockFile::tryLock(int timeout) return false; case LockFailedError: if (!d->isLocked && d->isApparentlyStale()) { - if (Q_UNLIKELY(QFileInfo(d->fileName).lastModified() > QDateTime::currentDateTimeUtc())) + if (Q_UNLIKELY(QFileInfo(d->fileName).lastModified(QTimeZone::UTC) > QDateTime::currentDateTimeUtc())) qInfo("QLockFile: Lock file '%ls' has a modification time in the future", qUtf16Printable(d->fileName)); // Stale lock from another thread/process // Ensure two processes don't remove it at the same time @@ -413,7 +413,7 @@ bool QLockFilePrivate::isApparentlyStale() const } } - const qint64 age = QFileInfo(fileName).lastModified().msecsTo(QDateTime::currentDateTimeUtc()); + const qint64 age = QFileInfo(fileName).lastModified(QTimeZone::UTC).msecsTo(QDateTime::currentDateTimeUtc()); return staleLockTime > 0 && qAbs(age) > staleLockTime; } -- cgit v1.2.3