summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfilesystemengine.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2016-07-19 15:44:58 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2016-07-20 12:35:30 +0000
commit494ced13292fa9d7b572f5310090f6b8fab36e26 (patch)
tree3116a6d8305b2631adfd5b66633598ae0cb7236e /src/corelib/io/qfilesystemengine.cpp
parent6e21c3fafdffdc238d9698c4cb58422d38d487d9 (diff)
Improve precision of reported file times on Unix-style platforms
Instead of reporting the file times in the precision of seconds, our API allows us to report it up to millisecond precision. Change-Id: I8bcc6a1fb4116e8c5421d650a68f6fb00482e551 Reviewed-by: Alex Trotsenko <alex1973tr@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qfilesystemengine.cpp')
-rw-r--r--src/corelib/io/qfilesystemengine.cpp27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/corelib/io/qfilesystemengine.cpp b/src/corelib/io/qfilesystemengine.cpp
index febfdbb9d4..6424012a9a 100644
--- a/src/corelib/io/qfilesystemengine.cpp
+++ b/src/corelib/io/qfilesystemengine.cpp
@@ -227,14 +227,27 @@ static void fillStat64fromStat32(struct stat64 *statBuf64, const struct stat &st
{
statBuf64->st_mode = statBuf32.st_mode;
statBuf64->st_size = statBuf32.st_size;
+#if _POSIX_VERSION >= 200809L
+ statBuf64->st_ctim = statBuf32.st_ctim;
+ statBuf64->st_mtim = statBuf32.st_mtim;
+ statBuf64->st_atim = statBuf32.st_atim;
+#else
statBuf64->st_ctime = statBuf32.st_ctime;
statBuf64->st_mtime = statBuf32.st_mtime;
statBuf64->st_atime = statBuf32.st_atime;
+#endif
statBuf64->st_uid = statBuf32.st_uid;
statBuf64->st_gid = statBuf32.st_gid;
}
#endif
+#if _POSIX_VERSION >= 200809L
+static qint64 timespecToMSecs(const timespec &spec)
+{
+ return (qint64(spec.tv_sec) * 1000) + (spec.tv_nsec / 1000000);
+}
+#endif
+
void QFileSystemMetaData::fillFromStatBuf(const QT_STATBUF &statBuffer)
{
// Permissions
@@ -278,9 +291,17 @@ void QFileSystemMetaData::fillFromStatBuf(const QT_STATBUF &statBuffer)
#endif
// Times
- creationTime_ = statBuffer.st_ctime ? statBuffer.st_ctime : statBuffer.st_mtime;
- modificationTime_ = statBuffer.st_mtime;
- accessTime_ = statBuffer.st_atime;
+#if _POSIX_VERSION >= 200809L
+ modificationTime_ = timespecToMSecs(statBuffer.st_mtim);
+ creationTime_ = timespecToMSecs(statBuffer.st_ctim);
+ if (!creationTime_)
+ creationTime_ = modificationTime_;
+ accessTime_ = timespecToMSecs(statBuffer.st_atim);
+#else
+ creationTime_ = qint64(statBuffer.st_ctime ? statBuffer.st_ctime : statBuffer.st_mtime) * 1000;
+ modificationTime_ = qint64(statBuffer.st_mtime) * 1000;
+ accessTime_ = qint64(statBuffer.st_atime) * 1000;
+#endif
userId_ = statBuffer.st_uid;
groupId_ = statBuffer.st_gid;
}