diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2017-02-23 14:53:27 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2017-03-01 05:19:56 +0000 |
commit | d83a20af1d05b5958d3559482b715777a57dea7a (patch) | |
tree | 9f93e75c7ec3d43fc97b86758111b37428a6fe0a /qmake | |
parent | 104408f3daf7e62dc33f6573282af9ccc2d1c440 (diff) |
Improve time stamp precision of qmake's touch function
On POSIX compliant platforms, the default precision we apply to
preserving time stamps is seconds. However we can do better and use
utimensat() - if available - to increase the precision to nanoseconds.
The values are provided by statbuf's st_mtim. This is guarded for
compatibility with older systems, similar to commit
494ced13292fa9d7b572f5310090f6b8fab36e26.
Change-Id: I6928660230d84f8511bf0f58e268906d2e575e04
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Diffstat (limited to 'qmake')
-rw-r--r-- | qmake/library/qmakebuiltins.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/qmake/library/qmakebuiltins.cpp b/qmake/library/qmakebuiltins.cpp index b30373b596..808bf53da4 100644 --- a/qmake/library/qmakebuiltins.cpp +++ b/qmake/library/qmakebuiltins.cpp @@ -58,6 +58,7 @@ #include <time.h> #include <utime.h> #include <errno.h> +#include <fcntl.h> #include <unistd.h> #include <signal.h> #include <sys/wait.h> @@ -1818,10 +1819,16 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional( evalError(fL1S("Cannot stat() reference file %1: %2.").arg(rfn, fL1S(strerror(errno)))); return ReturnFalse; } +#if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L + const struct timespec times[2] = { { 0, UTIME_NOW }, st.st_mtim }; + const bool utimeError = utimensat(AT_FDCWD, tfn.toLocal8Bit().constData(), times, 0) < 0; +#else struct utimbuf utb; utb.actime = time(0); utb.modtime = st.st_mtime; - if (utime(tfn.toLocal8Bit().constData(), &utb)) { + const bool utimeError = utime(tfn.toLocal8Bit().constData(), &utb) < 0; +#endif + if (utimeError) { evalError(fL1S("Cannot touch %1: %2.").arg(tfn, fL1S(strerror(errno)))); return ReturnFalse; } |