io/qfilesystemwatcher_inotify.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
10 -
11 -
12QInotifyFileSystemWatcherEngine *QInotifyFileSystemWatcherEngine::create(QObject *parent) -
13{ -
14 register int fd = -1; -
15 -
16 fd = inotify_init1(IN_CLOEXEC); -
17 -
18 if (fd == -1) {
partially evaluated: fd == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:289
0-289
19 fd = inotify_init(); -
20 if (fd == -1)
never evaluated: fd == -1
0
21 return 0;
never executed: return 0;
0
22 }
never executed: }
0
23 return new QInotifyFileSystemWatcherEngine(fd, parent);
executed: return new QInotifyFileSystemWatcherEngine(fd, parent);
Execution Count:289
289
24} -
25 -
26QInotifyFileSystemWatcherEngine::QInotifyFileSystemWatcherEngine(int fd, QObject *parent) -
27 : QFileSystemWatcherEngine(parent), -
28 inotifyFd(fd), -
29 notifier(fd, QSocketNotifier::Read, this) -
30{ -
31 fcntl(inotifyFd, 2, 1); -
32 connect(&notifier, "2""activated(int)", "1""readFromInotify()"); -
33}
executed: }
Execution Count:289
289
34 -
35QInotifyFileSystemWatcherEngine::~QInotifyFileSystemWatcherEngine() -
36{ -
37 notifier.setEnabled(false); -
38 for (QForeachContainer<__typeof__(pathToID)> _container_(pathToID); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (int id = *_container_.i;; __extension__ ({--_container_.brk; break;})) -
39 inotify_rm_watch(inotifyFd, id < 0 ? -id : id);
executed: inotify_rm_watch(inotifyFd, id < 0 ? -id : id);
Execution Count:268
268
40 -
41 ::close(inotifyFd); -
42}
executed: }
Execution Count:289
289
43 -
44QStringList QInotifyFileSystemWatcherEngine::addPaths(const QStringList &paths, -
45 QStringList *files, -
46 QStringList *directories) -
47{ -
48 QStringList p = paths; -
49 QMutableListIterator<QString> it(p); -
50 while (it.hasNext()) {
evaluated: it.hasNext()
TRUEFALSE
yes
Evaluation Count:320
yes
Evaluation Count:318
318-320
51 QString path = it.next(); -
52 QFileInfo fi(path); -
53 bool isDir = fi.isDir(); -
54 if (isDir) {
evaluated: isDir
TRUEFALSE
yes
Evaluation Count:311
yes
Evaluation Count:9
9-311
55 if (directories->contains(path))
evaluated: directories->contains(path)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:310
1-310
56 continue;
executed: continue;
Execution Count:1
1
57 } else {
executed: }
Execution Count:310
310
58 if (files->contains(path))
partially evaluated: files->contains(path)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9
0-9
59 continue;
never executed: continue;
0
60 }
executed: }
Execution Count:9
9
61 -
62 int wd = inotify_add_watch(inotifyFd, -
63 QFile::encodeName(path), -
64 (isDir -
65 ? (0 -
66 | 0x00000004 -
67 | (0x00000040 | 0x00000080) -
68 | 0x00000100 -
69 | 0x00000200 -
70 | 0x00000400 -
71 ) -
72 : (0 -
73 | 0x00000004 -
74 | 0x00000002 -
75 | (0x00000040 | 0x00000080) -
76 | 0x00000800 -
77 | 0x00000400 -
78 ))); -
79 if (wd < 0) {
evaluated: wd < 0
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:317
2-317
80 perror("QInotifyFileSystemWatcherEngine::addPaths: inotify_add_watch failed"); -
81 continue;
executed: continue;
Execution Count:2
2
82 } -
83 -
84 it.remove(); -
85 -
86 int id = isDir ? -wd : wd;
evaluated: isDir
TRUEFALSE
yes
Evaluation Count:310
yes
Evaluation Count:7
7-310
87 if (id < 0) {
evaluated: id < 0
TRUEFALSE
yes
Evaluation Count:310
yes
Evaluation Count:7
7-310
88 directories->append(path); -
89 } else {
executed: }
Execution Count:310
310
90 files->append(path); -
91 }
executed: }
Execution Count:7
7
92 -
93 pathToID.insert(path, id); -
94 idToPath.insert(id, path); -
95 }
executed: }
Execution Count:317
317
96 -
97 return p;
executed: return p;
Execution Count:318
318
98} -
99 -
100QStringList QInotifyFileSystemWatcherEngine::removePaths(const QStringList &paths, -
101 QStringList *files, -
102 QStringList *directories) -
103{ -
104 QStringList p = paths; -
105 QMutableListIterator<QString> it(p); -
106 while (it.hasNext()) {
evaluated: it.hasNext()
TRUEFALSE
yes
Evaluation Count:67
yes
Evaluation Count:66
66-67
107 QString path = it.next(); -
108 int id = pathToID.take(path); -
109 QString x = idToPath.take(id); -
110 if (x.isEmpty() || x != path)
evaluated: x.isEmpty()
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:45
partially evaluated: x != path
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:45
0-45
111 continue;
executed: continue;
Execution Count:22
22
112 -
113 int wd = id < 0 ? -id : id;
evaluated: id < 0
TRUEFALSE
yes
Evaluation Count:41
yes
Evaluation Count:4
4-41
114 -
115 inotify_rm_watch(inotifyFd, wd); -
116 -
117 it.remove(); -
118 if (id < 0) {
evaluated: id < 0
TRUEFALSE
yes
Evaluation Count:41
yes
Evaluation Count:4
4-41
119 directories->removeAll(path); -
120 } else {
executed: }
Execution Count:41
41
121 files->removeAll(path); -
122 }
executed: }
Execution Count:4
4
123 } -
124 -
125 return p;
executed: return p;
Execution Count:66
66
126} -
127 -
128void QInotifyFileSystemWatcherEngine::readFromInotify() -
129{ -
130 -
131 -
132 int buffSize = 0; -
133 ioctl(inotifyFd, 0x541B, (char *) &buffSize); -
134 QVarLengthArray<char, 4096> buffer(buffSize); -
135 buffSize = read(inotifyFd, buffer.data(), buffSize); -
136 char *at = buffer.data(); -
137 char * const end = at + buffSize; -
138 -
139 QHash<int, inotify_event *> eventForId; -
140 while (at < end) {
evaluated: at < end
TRUEFALSE
yes
Evaluation Count:165
yes
Evaluation Count:80
80-165
141 inotify_event *event = reinterpret_cast<inotify_event *>(at); -
142 -
143 if (eventForId.contains(event->wd))
evaluated: eventForId.contains(event->wd)
TRUEFALSE
yes
Evaluation Count:81
yes
Evaluation Count:84
81-84
144 eventForId[event->wd]->mask |= event->mask;
executed: eventForId[event->wd]->mask |= event->mask;
Execution Count:81
81
145 else -
146 eventForId.insert(event->wd, event);
executed: eventForId.insert(event->wd, event);
Execution Count:84
84
147 -
148 at += sizeof(inotify_event) + event->len; -
149 }
executed: }
Execution Count:165
165
150 -
151 QHash<int, inotify_event *>::const_iterator it = eventForId.constBegin(); -
152 while (it != eventForId.constEnd()) {
evaluated: it != eventForId.constEnd()
TRUEFALSE
yes
Evaluation Count:84
yes
Evaluation Count:80
80-84
153 const inotify_event &event = **it; -
154 ++it; -
155 -
156 -
157 -
158 int id = event.wd; -
159 QString path = idToPath.value(id); -
160 if (path.isEmpty()) {
evaluated: path.isEmpty()
TRUEFALSE
yes
Evaluation Count:78
yes
Evaluation Count:6
6-78
161 -
162 id = -id; -
163 path = idToPath.value(id); -
164 if (path.isEmpty())
evaluated: path.isEmpty()
TRUEFALSE
yes
Evaluation Count:29
yes
Evaluation Count:49
29-49
165 continue;
executed: continue;
Execution Count:29
29
166 }
executed: }
Execution Count:49
49
167 -
168 -
169 -
170 if ((event.mask & (0x00000400 | 0x00000800 | 0x00002000)) != 0) {
evaluated: (event.mask & (0x00000400 | 0x00000800 | 0x00002000)) != 0
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:51
4-51
171 pathToID.remove(path); -
172 idToPath.remove(id); -
173 inotify_rm_watch(inotifyFd, event.wd); -
174 -
175 if (id < 0)
evaluated: id < 0
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
176 directoryChanged(path, true);
executed: directoryChanged(path, true);
Execution Count:2
2
177 else -
178 fileChanged(path, true);
executed: fileChanged(path, true);
Execution Count:2
2
179 } else { -
180 if (id < 0)
evaluated: id < 0
TRUEFALSE
yes
Evaluation Count:47
yes
Evaluation Count:4
4-47
181 directoryChanged(path, false);
executed: directoryChanged(path, false);
Execution Count:47
47
182 else -
183 fileChanged(path, false);
executed: fileChanged(path, false);
Execution Count:4
4
184 } -
185 } -
186}
executed: }
Execution Count:80
80
187 -
188 -
189 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial