From a2779192eec649a15b909cd9becade7eb0bda34e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sun, 7 Jul 2024 23:53:54 +0200 Subject: [PATCH] qmake: Use utimensat on macOS when propagating mtime during install macOS only claims to conform to POSIX.1-2001, but has had utimensat since macOS 10.13. By enabling the utimensat code path, using stat.st_mtimespec as input, we get nanosecond precision when qmake installs files. Without this the tst_qmake::install_files tests fails due to the source file having a sub second timestamp -- 2023-07-31 15:58:12.468 -- while the installed does not: 2023-07-31 15:58:12.000. The reason this test passes in the CI right now is probably because the source file archive we use to pass test sources to the test machines does not support the same level of precision. Pick-to: 6.8 Change-Id: I6ca7a2a2f9e71981814cbf496aa55717b3a3f74f Reviewed-by: Thiago Macieira --- qmake/library/ioutils.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/qmake/library/ioutils.cpp b/qmake/library/ioutils.cpp index 38bb2463410..27120542422 100644 --- a/qmake/library/ioutils.cpp +++ b/qmake/library/ioutils.cpp @@ -221,15 +221,21 @@ bool IoUtils::touchFile(const QString &targetFileName, const QString &referenceF *errorString = fL1S("Cannot stat() reference file %1: %2.").arg(referenceFileName, fL1S(strerror(errno))); return false; } -# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L - const struct timespec times[2] = { { 0, UTIME_NOW }, st.st_mtim }; +# if (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L) || defined(Q_OS_DARWIN) + const struct timespec times[2] = { { 0, UTIME_NOW }, +# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L + st.st_mtim // POSIX.1-2008 +# else + st.st_mtimespec // Darwin +# endif + }; const bool utimeError = utimensat(AT_FDCWD, targetFileName.toLocal8Bit().constData(), times, 0) < 0; # else struct utimbuf utb; utb.actime = time(0); utb.modtime = st.st_mtime; const bool utimeError= utime(targetFileName.toLocal8Bit().constData(), &utb) < 0; -# endif +# endif // (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L) || defined(Q_OS_DARWIN) if (utimeError) { *errorString = fL1S("Cannot touch %1: %2.").arg(targetFileName, fL1S(strerror(errno))); return false; @@ -256,7 +262,7 @@ bool IoUtils::touchFile(const QString &targetFileName, const QString &referenceF } SetFileTime(wHand, NULL, NULL, &ft); CloseHandle(wHand); -# endif +# endif // Q_OS_UNIX return true; }