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
494ced1329.

Change-Id: I6928660230d84f8511bf0f58e268906d2e575e04
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
This commit is contained in:
Simon Hausmann 2017-02-23 14:53:27 +01:00
parent 104408f3da
commit d83a20af1d

View File

@ -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;
}