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) 2015 The Qt Company Ltd. | - | ||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||
5 | ** | - | ||||||
6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||
7 | ** | - | ||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||
15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||
25 | ** | - | ||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||
29 | ** | - | ||||||
30 | ** $QT_END_LICENSE$ | - | ||||||
31 | ** | - | ||||||
32 | ****************************************************************************/ | - | ||||||
33 | - | |||||||
34 | #include "qfilesystemwatcher_polling_p.h" | - | ||||||
35 | #include <QtCore/qtimer.h> | - | ||||||
36 | - | |||||||
37 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||
38 | - | |||||||
39 | QT_BEGIN_NAMESPACE | - | ||||||
40 | - | |||||||
41 | QPollingFileSystemWatcherEngine::QPollingFileSystemWatcherEngine(QObject *parent) | - | ||||||
42 | : QFileSystemWatcherEngine(parent), | - | ||||||
43 | timer(this) | - | ||||||
44 | { | - | ||||||
45 | connect(&timer, SIGNAL(timeout()), SLOT(timeout())); | - | ||||||
46 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||
47 | - | |||||||
48 | QStringList QPollingFileSystemWatcherEngine::addPaths(const QStringList &paths, | - | ||||||
49 | QStringList *files, | - | ||||||
50 | QStringList *directories) | - | ||||||
51 | { | - | ||||||
52 | QStringList p = paths; | - | ||||||
53 | QMutableListIterator<QString> it(p); | - | ||||||
54 | while (it.hasNext()) {
| 9 | ||||||
55 | QString path = it.next(); | - | ||||||
56 | QFileInfo fi(path); | - | ||||||
57 | if (!fi.exists())
| 0-9 | ||||||
58 | continue; never executed: continue; | 0 | ||||||
59 | if (fi.isDir()) {
| 4-5 | ||||||
60 | if (directories->contains(path))
| 0-4 | ||||||
61 | continue; never executed: continue; | 0 | ||||||
62 | directories->append(path); | - | ||||||
63 | if (!path.endsWith(QLatin1Char('/')))
| 0-4 | ||||||
64 | fi = QFileInfo(path + QLatin1Char('/')); executed 4 times by 1 test: fi = QFileInfo(path + QLatin1Char('/')); Executed by:
| 4 | ||||||
65 | this->directories.insert(path, fi); | - | ||||||
66 | } else { executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||
67 | if (files->contains(path))
| 0-5 | ||||||
68 | continue; never executed: continue; | 0 | ||||||
69 | files->append(path); | - | ||||||
70 | this->files.insert(path, fi); | - | ||||||
71 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||
72 | it.remove(); | - | ||||||
73 | } executed 9 times by 1 test: end of block Executed by:
| 9 | ||||||
74 | - | |||||||
75 | if ((!this->files.isEmpty() ||
| 4-5 | ||||||
76 | !this->directories.isEmpty()) &&
| 0-4 | ||||||
77 | !timer.isActive()) {
| 1-8 | ||||||
78 | timer.start(PollingInterval); | - | ||||||
79 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||
80 | - | |||||||
81 | return p; executed 9 times by 1 test: return p; Executed by:
| 9 | ||||||
82 | } | - | ||||||
83 | - | |||||||
84 | QStringList QPollingFileSystemWatcherEngine::removePaths(const QStringList &paths, | - | ||||||
85 | QStringList *files, | - | ||||||
86 | QStringList *directories) | - | ||||||
87 | { | - | ||||||
88 | QStringList p = paths; | - | ||||||
89 | QMutableListIterator<QString> it(p); | - | ||||||
90 | while (it.hasNext()) {
| 5 | ||||||
91 | QString path = it.next(); | - | ||||||
92 | if (this->directories.remove(path)) {
| 1-4 | ||||||
93 | directories->removeAll(path); | - | ||||||
94 | it.remove(); | - | ||||||
95 | } else if (this->files.remove(path)) { executed 1 time by 1 test: end of block Executed by:
| 1-3 | ||||||
96 | files->removeAll(path); | - | ||||||
97 | it.remove(); | - | ||||||
98 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||
99 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||
100 | - | |||||||
101 | if (this->files.isEmpty() &&
| 0-5 | ||||||
102 | this->directories.isEmpty()) {
| 1-4 | ||||||
103 | timer.stop(); | - | ||||||
104 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||
105 | - | |||||||
106 | return p; executed 5 times by 1 test: return p; Executed by:
| 5 | ||||||
107 | } | - | ||||||
108 | - | |||||||
109 | void QPollingFileSystemWatcherEngine::timeout() | - | ||||||
110 | { | - | ||||||
111 | QMutableHashIterator<QString, FileInfo> fit(files); | - | ||||||
112 | while (fit.hasNext()) {
| 12-38 | ||||||
113 | QHash<QString, FileInfo>::iterator x = fit.next(); | - | ||||||
114 | QString path = x.key(); | - | ||||||
115 | QFileInfo fi(path); | - | ||||||
116 | if (!fi.exists()) {
| 2-10 | ||||||
117 | fit.remove(); | - | ||||||
118 | emit fileChanged(path, true); | - | ||||||
119 | } else if (x.value() != fi) { executed 2 times by 1 test: end of block Executed by:
| 2-6 | ||||||
120 | x.value() = fi; | - | ||||||
121 | emit fileChanged(path, false); | - | ||||||
122 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||
123 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||
124 | QMutableHashIterator<QString, FileInfo> dit(directories); | - | ||||||
125 | while (dit.hasNext()) {
| 17-38 | ||||||
126 | QHash<QString, FileInfo>::iterator x = dit.next(); | - | ||||||
127 | QString path = x.key(); | - | ||||||
128 | QFileInfo fi(path); | - | ||||||
129 | if (!path.endsWith(QLatin1Char('/')))
| 0-17 | ||||||
130 | fi = QFileInfo(path + QLatin1Char('/')); executed 17 times by 1 test: fi = QFileInfo(path + QLatin1Char('/')); Executed by:
| 17 | ||||||
131 | if (!fi.exists()) {
| 2-15 | ||||||
132 | dit.remove(); | - | ||||||
133 | emit directoryChanged(path, true); | - | ||||||
134 | } else if (x.value() != fi) { executed 2 times by 1 test: end of block Executed by:
| 2-11 | ||||||
135 | fi.refresh(); | - | ||||||
136 | if (!fi.exists()) {
| 0-4 | ||||||
137 | dit.remove(); | - | ||||||
138 | emit directoryChanged(path, true); | - | ||||||
139 | } else { never executed: end of block | 0 | ||||||
140 | x.value() = fi; | - | ||||||
141 | emit directoryChanged(path, false); | - | ||||||
142 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||
143 | } | - | ||||||
144 | } executed 17 times by 1 test: end of block Executed by:
| 17 | ||||||
145 | } executed 38 times by 1 test: end of block Executed by:
| 38 | ||||||
146 | - | |||||||
147 | QT_END_NAMESPACE | - | ||||||
148 | #endif // !QT_NO_FILESYSTEMWATCHER | - | ||||||
Source code | Switch to Preprocessed file |