QFileInfo: make stat method public

Forcing the reading of all file system attributes is generally useful in
multi-threaded applications, and has at least one more use case in Qt.

Using it in QFileSystemWatcher on Windows avoids several file system
accesses.

Task-number: QTBUG-41373
Change-Id: Ib3c3243fd083142393ad46d62f49cb4f7bfda17c
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Volker Hilsheimer 2020-07-29 20:12:26 +02:00
parent 7b3a2f5e3d
commit 3657405fe7
3 changed files with 4 additions and 4 deletions

View File

@ -308,6 +308,8 @@ QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request)
refreshes the file information: refresh(). If you want to switch
off a QFileInfo's caching and force it to access the file system
every time you request information from it call setCaching(false).
If you want to make sure that all information is read from the
file system, use stat().
\sa QDir, QFile
*/
@ -1509,8 +1511,6 @@ void QFileInfo::setCaching(bool enable)
}
/*!
\internal
Reads all attributes from the file system.
This is useful when information about the file system is collected in a

View File

@ -175,13 +175,12 @@ public:
bool caching() const;
void setCaching(bool on);
void stat();
protected:
QSharedDataPointer<QFileInfoPrivate> d_ptr;
private:
friend class QFileInfoGatherer;
void stat();
QFileInfoPrivate* d_func();
inline const QFileInfoPrivate* d_func() const
{

View File

@ -372,6 +372,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths,
normalPath.chop(1);
}
QFileInfo fileInfo(normalPath);
fileInfo.stat();
if (!fileInfo.exists())
continue;