diff options
Diffstat (limited to 'src/corelib/io/qfilesystemwatcher_polling.cpp')
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_polling.cpp | 76 |
1 files changed, 29 insertions, 47 deletions
diff --git a/src/corelib/io/qfilesystemwatcher_polling.cpp b/src/corelib/io/qfilesystemwatcher_polling.cpp index 6920eab258..d34c8c49e8 100644 --- a/src/corelib/io/qfilesystemwatcher_polling.cpp +++ b/src/corelib/io/qfilesystemwatcher_polling.cpp @@ -1,53 +1,25 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qfilesystemwatcher_polling_p.h" + +#include <QtCore/qlatin1stringview.h> #include <QtCore/qscopeguard.h> #include <QtCore/qtimer.h> +#include <chrono> + +using namespace std::chrono_literals; + QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + +static constexpr auto PollingInterval = 1s; + QPollingFileSystemWatcherEngine::QPollingFileSystemWatcherEngine(QObject *parent) - : QFileSystemWatcherEngine(parent), - timer(this) + : QFileSystemWatcherEngine(parent) { - connect(&timer, SIGNAL(timeout()), SLOT(timeout())); } QStringList QPollingFileSystemWatcherEngine::addPaths(const QStringList &paths, @@ -64,8 +36,8 @@ QStringList QPollingFileSystemWatcherEngine::addPaths(const QStringList &paths, if (directories->contains(path)) continue; directories->append(path); - if (!path.endsWith(QLatin1Char('/'))) - fi = QFileInfo(path + QLatin1Char('/')); + if (!path.endsWith(u'/')) + fi = QFileInfo(path + u'/'); this->directories.insert(path, fi); } else { if (files->contains(path)) @@ -76,10 +48,17 @@ QStringList QPollingFileSystemWatcherEngine::addPaths(const QStringList &paths, sg.dismiss(); } + std::chrono::milliseconds interval = PollingInterval; +#ifdef QT_BUILD_INTERNAL + if (Q_UNLIKELY(parent()->objectName().startsWith("_qt_autotest_force_engine_"_L1))) { + interval = 10ms; // Special case to speed up the unittests + } +#endif + if ((!this->files.isEmpty() || !this->directories.isEmpty()) && !timer.isActive()) { - timer.start(PollingInterval); + timer.start(interval, this); } return unhandled; @@ -108,8 +87,11 @@ QStringList QPollingFileSystemWatcherEngine::removePaths(const QStringList &path return unhandled; } -void QPollingFileSystemWatcherEngine::timeout() +void QPollingFileSystemWatcherEngine::timerEvent(QTimerEvent *e) { + if (e->timerId() != timer.timerId()) + return QFileSystemWatcherEngine::timerEvent(e); + for (auto it = files.begin(), end = files.end(); it != end; /*erasing*/) { QString path = it.key(); QFileInfo fi(path); @@ -127,8 +109,8 @@ void QPollingFileSystemWatcherEngine::timeout() for (auto it = directories.begin(), end = directories.end(); it != end; /*erasing*/) { QString path = it.key(); QFileInfo fi(path); - if (!path.endsWith(QLatin1Char('/'))) - fi = QFileInfo(path + QLatin1Char('/')); + if (!path.endsWith(u'/')) + fi = QFileInfo(path + u'/'); if (!fi.exists()) { it = directories.erase(it); emit directoryChanged(path, true); |