| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qfilesystemwatcher_polling.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||
| 2 | ** | - | ||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||
| 5 | ** | - | ||||||
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||
| 7 | ** | - | ||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||
| 9 | ** Commercial License Usage | - | ||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||
| 16 | ** | - | ||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||
| 24 | ** | - | ||||||
| 25 | ** GNU General Public License Usage | - | ||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||
| 35 | ** | - | ||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||
| 37 | ** | - | ||||||
| 38 | ****************************************************************************/ | - | ||||||
| 39 | - | |||||||
| 40 | #include "qfilesystemwatcher_polling_p.h" | - | ||||||
| 41 | #include <QtCore/qtimer.h> | - | ||||||
| 42 | - | |||||||
| 43 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||
| 44 | - | |||||||
| 45 | QT_BEGIN_NAMESPACE | - | ||||||
| 46 | - | |||||||
| 47 | QPollingFileSystemWatcherEngine::QPollingFileSystemWatcherEngine(QObject *parent) | - | ||||||
| 48 | : QFileSystemWatcherEngine(parent), | - | ||||||
| 49 | timer(this) | - | ||||||
| 50 | { | - | ||||||
| 51 | connect(&timer, SIGNAL(timeout()), SLOT(timeout())); | - | ||||||
| 52 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||
| 53 | - | |||||||
| 54 | QStringList QPollingFileSystemWatcherEngine::addPaths(const QStringList &paths, | - | ||||||
| 55 | QStringList *files, | - | ||||||
| 56 | QStringList *directories) | - | ||||||
| 57 | { | - | ||||||
| 58 | QStringList p = paths; | - | ||||||
| 59 | QMutableListIterator<QString> it(p); | - | ||||||
| 60 | while (it.hasNext()) {
| 9 | ||||||
| 61 | QString path = it.next(); | - | ||||||
| 62 | QFileInfo fi(path); | - | ||||||
| 63 | if (!fi.exists())
| 0-9 | ||||||
| 64 | continue; never executed: continue; | 0 | ||||||
| 65 | if (fi.isDir()) {
| 4-5 | ||||||
| 66 | if (directories->contains(path))
| 0-4 | ||||||
| 67 | continue; never executed: continue; | 0 | ||||||
| 68 | directories->append(path); | - | ||||||
| 69 | if (!path.endsWith(QLatin1Char('/')))
| 0-4 | ||||||
| 70 | fi = QFileInfo(path + QLatin1Char('/')); executed 4 times by 1 test: fi = QFileInfo(path + QLatin1Char('/'));Executed by:
| 4 | ||||||
| 71 | this->directories.insert(path, fi); | - | ||||||
| 72 | } else { executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||
| 73 | if (files->contains(path))
| 0-5 | ||||||
| 74 | continue; never executed: continue; | 0 | ||||||
| 75 | files->append(path); | - | ||||||
| 76 | this->files.insert(path, fi); | - | ||||||
| 77 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||
| 78 | it.remove(); | - | ||||||
| 79 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||
| 80 | - | |||||||
| 81 | if ((!this->files.isEmpty() ||
| 4-5 | ||||||
| 82 | !this->directories.isEmpty()) &&
| 0-4 | ||||||
| 83 | !timer.isActive()) {
| 1-8 | ||||||
| 84 | timer.start(PollingInterval); | - | ||||||
| 85 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||
| 86 | - | |||||||
| 87 | return p; executed 9 times by 1 test: return p;Executed by:
| 9 | ||||||
| 88 | } | - | ||||||
| 89 | - | |||||||
| 90 | QStringList QPollingFileSystemWatcherEngine::removePaths(const QStringList &paths, | - | ||||||
| 91 | QStringList *files, | - | ||||||
| 92 | QStringList *directories) | - | ||||||
| 93 | { | - | ||||||
| 94 | QStringList p = paths; | - | ||||||
| 95 | QMutableListIterator<QString> it(p); | - | ||||||
| 96 | while (it.hasNext()) {
| 5 | ||||||
| 97 | QString path = it.next(); | - | ||||||
| 98 | if (this->directories.remove(path)) {
| 1-4 | ||||||
| 99 | directories->removeAll(path); | - | ||||||
| 100 | it.remove(); | - | ||||||
| 101 | } else if (this->files.remove(path)) { executed 1 time by 1 test: end of blockExecuted by:
| 1-3 | ||||||
| 102 | files->removeAll(path); | - | ||||||
| 103 | it.remove(); | - | ||||||
| 104 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||
| 105 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||
| 106 | - | |||||||
| 107 | if (this->files.isEmpty() &&
| 0-5 | ||||||
| 108 | this->directories.isEmpty()) {
| 1-4 | ||||||
| 109 | timer.stop(); | - | ||||||
| 110 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||
| 111 | - | |||||||
| 112 | return p; executed 5 times by 1 test: return p;Executed by:
| 5 | ||||||
| 113 | } | - | ||||||
| 114 | - | |||||||
| 115 | void QPollingFileSystemWatcherEngine::timeout() | - | ||||||
| 116 | { | - | ||||||
| 117 | QMutableHashIterator<QString, FileInfo> fit(files); | - | ||||||
| 118 | while (fit.hasNext()) {
| 11-38 | ||||||
| 119 | QHash<QString, FileInfo>::iterator x = fit.next(); | - | ||||||
| 120 | QString path = x.key(); | - | ||||||
| 121 | QFileInfo fi(path); | - | ||||||
| 122 | if (!fi.exists()) {
| 2-9 | ||||||
| 123 | fit.remove(); | - | ||||||
| 124 | emit fileChanged(path, true); | - | ||||||
| 125 | } else if (x.value() != fi) { executed 2 times by 1 test: end of blockExecuted by:
| 2-5 | ||||||
| 126 | x.value() = fi; | - | ||||||
| 127 | emit fileChanged(path, false); | - | ||||||
| 128 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||
| 129 | } executed 11 times by 1 test: end of blockExecuted by:
| 11 | ||||||
| 130 | QMutableHashIterator<QString, FileInfo> dit(directories); | - | ||||||
| 131 | while (dit.hasNext()) {
| 18-38 | ||||||
| 132 | QHash<QString, FileInfo>::iterator x = dit.next(); | - | ||||||
| 133 | QString path = x.key(); | - | ||||||
| 134 | QFileInfo fi(path); | - | ||||||
| 135 | if (!path.endsWith(QLatin1Char('/')))
| 0-18 | ||||||
| 136 | fi = QFileInfo(path + QLatin1Char('/')); executed 18 times by 1 test: fi = QFileInfo(path + QLatin1Char('/'));Executed by:
| 18 | ||||||
| 137 | if (!fi.exists()) {
| 2-16 | ||||||
| 138 | dit.remove(); | - | ||||||
| 139 | emit directoryChanged(path, true); | - | ||||||
| 140 | } else if (x.value() != fi) { executed 2 times by 1 test: end of blockExecuted by:
| 2-12 | ||||||
| 141 | fi.refresh(); | - | ||||||
| 142 | if (!fi.exists()) {
| 0-4 | ||||||
| 143 | dit.remove(); | - | ||||||
| 144 | emit directoryChanged(path, true); | - | ||||||
| 145 | } else { never executed: end of block | 0 | ||||||
| 146 | x.value() = fi; | - | ||||||
| 147 | emit directoryChanged(path, false); | - | ||||||
| 148 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||
| 149 | } | - | ||||||
| 150 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||
| 151 | } executed 38 times by 1 test: end of blockExecuted by:
| 38 | ||||||
| 152 | - | |||||||
| 153 | QT_END_NAMESPACE | - | ||||||
| 154 | #endif // !QT_NO_FILESYSTEMWATCHER | - | ||||||
| Source code | Switch to Preprocessed file |