Ensure proper locking in QFileInfoGatherer

The mutex is used to protect the QFileSystemWatcher instance created by
QFileInfoGatherer, except when calling getFileInfos(). Add a locker
before using QFileSystemWatcher in this function.

Note: it appears that QFileInfoGatherer is misusing QFileSystemWatcher
by calling it from multiple threads. QFileSystemWatcher is an event
driven class, and as such, not thread-safe. So far, no problems have
been reported related to this, so I've left the code as-is.

Change-Id: Ib1429d9399e37120acf8e8d3b989b83c4ce24203
Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
This commit is contained in:
Bradley T. Hughes 2012-01-11 12:47:07 +01:00 committed by Qt by Nokia
parent 93a466c6fc
commit b409a81da5

View File

@ -280,9 +280,10 @@ void QFileInfoGatherer::getFileInfos(const QString &path, const QStringList &fil
{ {
#ifndef QT_NO_FILESYSTEMWATCHER #ifndef QT_NO_FILESYSTEMWATCHER
if (files.isEmpty() if (files.isEmpty()
&& !watcher->directories().contains(path)
&& !path.isEmpty() && !path.isEmpty()
&& !path.startsWith(QLatin1String("//")) /*don't watch UNC path*/) { && !path.startsWith(QLatin1String("//")) /*don't watch UNC path*/) {
QMutexLocker locker(&mutex);
if (!watcher->directories().contains(path))
watcher->addPath(path); watcher->addPath(path);
} }
#endif #endif