diff options
author | Ćukasz Matysiak <lukasz.matysiak@qt.io> | 2024-05-14 18:09:07 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-05-16 13:54:50 +0000 |
commit | 4be9c76f1cdccc0dc2d868827d9a0e788399cdc4 (patch) | |
tree | 7088530153d909e932c432dd27dc9861b14d5853 | |
parent | 44565ed793297ff9911c993e2046a559b9d40400 (diff) |
Make tst_QFileInfo::setFileTimes more robust
There are some systems that do not support millisecond resolution in
timestamps.
An example of such system is VxWorks.
POSIX2008 demands that `stat` contains an `st_mtim` field of type `timespec`.
That field holds modification time with a nanosecond resolution.
VxWorks reports _POSIX_VERSION as 200112.
The `stat` struct does not contain `st_mtim`, but rather an `st_mtime` which
holds a `time_t` which contains seconds.
This leads to setFileTimes failing, because the test tries to
save the current datetime as the modification time of a file, but the ms
part is cut off.
Fix the problem by checking if the timestamp read back from the
filesystem contains milliseconds and only check it if it's not zero.
Task-number: QTBUG-115777
Change-Id: I8c8a3b1c8e97955f13f059bcebf66d1b5af174fe
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 88cb405514270a320d2993e8fb1c7b7b62646112)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index f202ad3a2f..9ae596973c 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -1210,9 +1210,16 @@ void tst_QFileInfo::setFileTimes() QCOMPARE(file.write(data), data.size()); QCOMPARE(file.size(), data.size()); - const QDateTime before = QDateTime::currentDateTimeUtc().addMSecs(-5000); + QDateTime before = QDateTime::currentDateTimeUtc().addMSecs(-5000); + QVERIFY(file.setFileTime(before, QFile::FileModificationTime)); const QDateTime mtime = file.fileTime(QFile::FileModificationTime).toUTC(); + if (mtime.time().msec() == 0) + { + const QTime beforeTime = before.time(); + const QTime beforeTimeWithMSCutOff{beforeTime.hour(), beforeTime.minute(), beforeTime.second(), 0}; + before.setTime(beforeTimeWithMSCutOff); + } QCOMPARE(mtime, before); } |