qfilesystemwatcher_polling.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qfilesystemwatcher_polling.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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-
45QT_BEGIN_NAMESPACE-
46-
47QPollingFileSystemWatcherEngine::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 block
Executed by:
  • tst_QFileSystemWatcher
4
53-
54QStringList 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()) {
it.hasNext()Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
FALSEevaluated 9 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
9
61 QString path = it.next();-
62 QFileInfo fi(path);-
63 if (!fi.exists())
!fi.exists()Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
0-9
64 continue;
never executed: continue;
0
65 if (fi.isDir()) {
fi.isDir()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
FALSEevaluated 5 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
4-5
66 if (directories->contains(path))
directories->contains(path)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
0-4
67 continue;
never executed: continue;
0
68 directories->append(path);-
69 if (!path.endsWith(QLatin1Char('/')))
!path.endsWith...tin1Char('/'))Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
FALSEnever evaluated
0-4
70 fi = QFileInfo(path + QLatin1Char('/'));
executed 4 times by 1 test: fi = QFileInfo(path + QLatin1Char('/'));
Executed by:
  • tst_QFileSystemWatcher
4
71 this->directories.insert(path, fi);-
72 } else {
executed 4 times by 1 test: end of block
Executed by:
  • tst_QFileSystemWatcher
4
73 if (files->contains(path))
files->contains(path)Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
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 block
Executed by:
  • tst_QFileSystemWatcher
5
78 it.remove();-
79 }
executed 9 times by 1 test: end of block
Executed by:
  • tst_QFileSystemWatcher
9
80-
81 if ((!this->files.isEmpty() ||
!this->files.isEmpty()Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
4-5
82 !this->directories.isEmpty()) &&
!this->directories.isEmpty()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
FALSEnever evaluated
0-4
83 !timer.isActive()) {
!timer.isActive()Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
1-8
84 timer.start(PollingInterval);-
85 }
executed 8 times by 1 test: end of block
Executed by:
  • tst_QFileSystemWatcher
8
86-
87 return p;
executed 9 times by 1 test: return p;
Executed by:
  • tst_QFileSystemWatcher
9
88}-
89-
90QStringList 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()) {
it.hasNext()Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
FALSEevaluated 5 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
5
97 QString path = it.next();-
98 if (this->directories.remove(path)) {
this->directories.remove(path)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
1-4
99 directories->removeAll(path);-
100 it.remove();-
101 } else if (this->files.remove(path)) {
executed 1 time by 1 test: end of block
Executed by:
  • tst_QFileSystemWatcher
this->files.remove(path)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
1-3
102 files->removeAll(path);-
103 it.remove();-
104 }
executed 3 times by 1 test: end of block
Executed by:
  • tst_QFileSystemWatcher
3
105 }
executed 5 times by 1 test: end of block
Executed by:
  • tst_QFileSystemWatcher
5
106-
107 if (this->files.isEmpty() &&
this->files.isEmpty()Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
FALSEnever evaluated
0-5
108 this->directories.isEmpty()) {
this->directories.isEmpty()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
1-4
109 timer.stop();-
110 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_QFileSystemWatcher
4
111-
112 return p;
executed 5 times by 1 test: return p;
Executed by:
  • tst_QFileSystemWatcher
5
113}-
114-
115void QPollingFileSystemWatcherEngine::timeout()-
116{-
117 QMutableHashIterator<QString, FileInfo> fit(files);-
118 while (fit.hasNext()) {
fit.hasNext()Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
FALSEevaluated 38 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
11-38
119 QHash<QString, FileInfo>::iterator x = fit.next();-
120 QString path = x.key();-
121 QFileInfo fi(path);-
122 if (!fi.exists()) {
!fi.exists()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
FALSEevaluated 9 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
2-9
123 fit.remove();-
124 emit fileChanged(path, true);-
125 } else if (x.value() != fi) {
executed 2 times by 1 test: end of block
Executed by:
  • tst_QFileSystemWatcher
x.value() != fiDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
FALSEevaluated 5 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
2-5
126 x.value() = fi;-
127 emit fileChanged(path, false);-
128 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_QFileSystemWatcher
4
129 }
executed 11 times by 1 test: end of block
Executed by:
  • tst_QFileSystemWatcher
11
130 QMutableHashIterator<QString, FileInfo> dit(directories);-
131 while (dit.hasNext()) {
dit.hasNext()Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
FALSEevaluated 38 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
18-38
132 QHash<QString, FileInfo>::iterator x = dit.next();-
133 QString path = x.key();-
134 QFileInfo fi(path);-
135 if (!path.endsWith(QLatin1Char('/')))
!path.endsWith...tin1Char('/'))Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
FALSEnever evaluated
0-18
136 fi = QFileInfo(path + QLatin1Char('/'));
executed 18 times by 1 test: fi = QFileInfo(path + QLatin1Char('/'));
Executed by:
  • tst_QFileSystemWatcher
18
137 if (!fi.exists()) {
!fi.exists()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
FALSEevaluated 16 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
2-16
138 dit.remove();-
139 emit directoryChanged(path, true);-
140 } else if (x.value() != fi) {
executed 2 times by 1 test: end of block
Executed by:
  • tst_QFileSystemWatcher
x.value() != fiDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
2-12
141 fi.refresh();-
142 if (!fi.exists()) {
!fi.exists()Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFileSystemWatcher
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 block
Executed by:
  • tst_QFileSystemWatcher
4
149 }-
150 }
executed 18 times by 1 test: end of block
Executed by:
  • tst_QFileSystemWatcher
18
151}
executed 38 times by 1 test: end of block
Executed by:
  • tst_QFileSystemWatcher
38
152-
153QT_END_NAMESPACE-
154#endif // !QT_NO_FILESYSTEMWATCHER-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9