summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfilesystemmetadata_p.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-07-02 11:46:43 -0700
committerThiago Macieira <thiago.macieira@intel.com>2017-08-06 23:14:26 +0000
commit5a9b1425e187bc77122354cf7446bcf6bb322ff4 (patch)
treea9db6878473eec577a373127f9cd41d4aea7f517 /src/corelib/io/qfilesystemmetadata_p.h
parent04f4d87bda7e108817e80a7b16ba6fa9323ed3c4 (diff)
QFileSystemEngine/Unix: rework the getting of nsec-precision file times
It was working on Linux because _GNU_SOURCE gets us POSIX.1-2008 compatibility, but not on macOS or the BSDs. There, we were still stuck to full second precision. This commit uses the template trick introduced by the futimes code (which itself was inspired by commit 2fb42eb4af3444b11e7b1210323637937ef in QtNetwork). Also note how it adds support for birth time, if the system's stat struct has that information. Tested to work on MacOS and FreeBSD. The manual filetest produces: Name: . Path: . (/usr/home/tjmaciei/src/qt/qt5) Size: 1536 Type: Directory Attrs: readable writable executable hidden nativepath Mode: drwxr-xr-x Owner: tjmaciei (1001) Group: tjmaciei (1001) Access: 2017-07-13T20:03:47.916 Birth: 2017-07-13T20:03:47.916 Change: 2017-07-13T20:04:41.648 Modified: 2017-07-13T20:04:41.648 Linux will require support for statx(2). Change-Id: I8d96dea9955d4c749b99fffd14cd97d7a8c6d45d Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/io/qfilesystemmetadata_p.h')
-rw-r--r--src/corelib/io/qfilesystemmetadata_p.h9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/corelib/io/qfilesystemmetadata_p.h b/src/corelib/io/qfilesystemmetadata_p.h
index 3eeb26247f..c4e1312c1d 100644
--- a/src/corelib/io/qfilesystemmetadata_p.h
+++ b/src/corelib/io/qfilesystemmetadata_p.h
@@ -293,9 +293,12 @@ inline QDateTime QFileSystemMetaData::fileTime(QAbstractFileEngine::FileTime tim
#if defined(Q_OS_UNIX)
inline QDateTime QFileSystemMetaData::birthTime() const
{ return birthTime_ ? QDateTime::fromMSecsSinceEpoch(birthTime_) : QDateTime(); }
-inline QDateTime QFileSystemMetaData::metadataChangeTime() const { return QDateTime::fromMSecsSinceEpoch(metadataChangeTime_); }
-inline QDateTime QFileSystemMetaData::modificationTime() const { return QDateTime::fromMSecsSinceEpoch(modificationTime_); }
-inline QDateTime QFileSystemMetaData::accessTime() const { return QDateTime::fromMSecsSinceEpoch(accessTime_); }
+inline QDateTime QFileSystemMetaData::metadataChangeTime() const
+{ return metadataChangeTime_ ? QDateTime::fromMSecsSinceEpoch(metadataChangeTime_) : QDateTime(); }
+inline QDateTime QFileSystemMetaData::modificationTime() const
+{ return modificationTime_ ? QDateTime::fromMSecsSinceEpoch(modificationTime_) : QDateTime(); }
+inline QDateTime QFileSystemMetaData::accessTime() const
+{ return accessTime_ ? QDateTime::fromMSecsSinceEpoch(accessTime_) : QDateTime(); }
inline uint QFileSystemMetaData::userId() const { return userId_; }
inline uint QFileSystemMetaData::groupId() const { return groupId_; }