| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qfilesystemwatcher_inotify.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.h" | - | ||||||||||||
| 35 | #include "qfilesystemwatcher_inotify_p.h" | - | ||||||||||||
| 36 | - | |||||||||||||
| 37 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||
| 38 | - | |||||||||||||
| 39 | #include "private/qcore_unix_p.h" | - | ||||||||||||
| 40 | - | |||||||||||||
| 41 | #include <qdebug.h> | - | ||||||||||||
| 42 | #include <qfile.h> | - | ||||||||||||
| 43 | #include <qfileinfo.h> | - | ||||||||||||
| 44 | #include <qsocketnotifier.h> | - | ||||||||||||
| 45 | #include <qvarlengtharray.h> | - | ||||||||||||
| 46 | - | |||||||||||||
| 47 | #if defined(Q_OS_LINUX) | - | ||||||||||||
| 48 | #include <sys/syscall.h> | - | ||||||||||||
| 49 | #include <sys/ioctl.h> | - | ||||||||||||
| 50 | #include <unistd.h> | - | ||||||||||||
| 51 | #include <fcntl.h> | - | ||||||||||||
| 52 | #endif | - | ||||||||||||
| 53 | - | |||||||||||||
| 54 | #if defined(QT_NO_INOTIFY) | - | ||||||||||||
| 55 | - | |||||||||||||
| 56 | #if defined(Q_OS_QNX) | - | ||||||||||||
| 57 | // These files should only be compiled on QNX if the inotify headers are found | - | ||||||||||||
| 58 | #error "Should not get here." | - | ||||||||||||
| 59 | #endif | - | ||||||||||||
| 60 | - | |||||||||||||
| 61 | #include <linux/types.h> | - | ||||||||||||
| 62 | - | |||||||||||||
| 63 | #if defined(__i386__) | - | ||||||||||||
| 64 | # define __NR_inotify_init 291 | - | ||||||||||||
| 65 | # define __NR_inotify_add_watch 292 | - | ||||||||||||
| 66 | # define __NR_inotify_rm_watch 293 | - | ||||||||||||
| 67 | # define __NR_inotify_init1 332 | - | ||||||||||||
| 68 | #elif defined(__x86_64__) | - | ||||||||||||
| 69 | # define __NR_inotify_init 253 | - | ||||||||||||
| 70 | # define __NR_inotify_add_watch 254 | - | ||||||||||||
| 71 | # define __NR_inotify_rm_watch 255 | - | ||||||||||||
| 72 | # define __NR_inotify_init1 294 | - | ||||||||||||
| 73 | #elif defined(__powerpc__) || defined(__powerpc64__) | - | ||||||||||||
| 74 | # define __NR_inotify_init 275 | - | ||||||||||||
| 75 | # define __NR_inotify_add_watch 276 | - | ||||||||||||
| 76 | # define __NR_inotify_rm_watch 277 | - | ||||||||||||
| 77 | # define __NR_inotify_init1 318 | - | ||||||||||||
| 78 | #elif defined (__ia64__) | - | ||||||||||||
| 79 | # define __NR_inotify_init 1277 | - | ||||||||||||
| 80 | # define __NR_inotify_add_watch 1278 | - | ||||||||||||
| 81 | # define __NR_inotify_rm_watch 1279 | - | ||||||||||||
| 82 | # define __NR_inotify_init1 1318 | - | ||||||||||||
| 83 | #elif defined (__s390__) || defined (__s390x__) | - | ||||||||||||
| 84 | # define __NR_inotify_init 284 | - | ||||||||||||
| 85 | # define __NR_inotify_add_watch 285 | - | ||||||||||||
| 86 | # define __NR_inotify_rm_watch 286 | - | ||||||||||||
| 87 | # define __NR_inotify_init1 324 | - | ||||||||||||
| 88 | #elif defined (__alpha__) | - | ||||||||||||
| 89 | # define __NR_inotify_init 444 | - | ||||||||||||
| 90 | # define __NR_inotify_add_watch 445 | - | ||||||||||||
| 91 | # define __NR_inotify_rm_watch 446 | - | ||||||||||||
| 92 | // no inotify_init1 for the Alpha | - | ||||||||||||
| 93 | #elif defined (__sparc__) || defined (__sparc64__) | - | ||||||||||||
| 94 | # define __NR_inotify_init 151 | - | ||||||||||||
| 95 | # define __NR_inotify_add_watch 152 | - | ||||||||||||
| 96 | # define __NR_inotify_rm_watch 156 | - | ||||||||||||
| 97 | # define __NR_inotify_init1 322 | - | ||||||||||||
| 98 | #elif defined (__arm__) | - | ||||||||||||
| 99 | # define __NR_inotify_init 316 | - | ||||||||||||
| 100 | # define __NR_inotify_add_watch 317 | - | ||||||||||||
| 101 | # define __NR_inotify_rm_watch 318 | - | ||||||||||||
| 102 | # define __NR_inotify_init1 360 | - | ||||||||||||
| 103 | #elif defined (__sh__) | - | ||||||||||||
| 104 | # define __NR_inotify_init 290 | - | ||||||||||||
| 105 | # define __NR_inotify_add_watch 291 | - | ||||||||||||
| 106 | # define __NR_inotify_rm_watch 292 | - | ||||||||||||
| 107 | # define __NR_inotify_init1 332 | - | ||||||||||||
| 108 | #elif defined (__sh64__) | - | ||||||||||||
| 109 | # define __NR_inotify_init 318 | - | ||||||||||||
| 110 | # define __NR_inotify_add_watch 319 | - | ||||||||||||
| 111 | # define __NR_inotify_rm_watch 320 | - | ||||||||||||
| 112 | # define __NR_inotify_init1 360 | - | ||||||||||||
| 113 | #elif defined (__mips__) | - | ||||||||||||
| 114 | # define __NR_inotify_init 284 | - | ||||||||||||
| 115 | # define __NR_inotify_add_watch 285 | - | ||||||||||||
| 116 | # define __NR_inotify_rm_watch 286 | - | ||||||||||||
| 117 | # define __NR_inotify_init1 329 | - | ||||||||||||
| 118 | #elif defined (__hppa__) | - | ||||||||||||
| 119 | # define __NR_inotify_init 269 | - | ||||||||||||
| 120 | # define __NR_inotify_add_watch 270 | - | ||||||||||||
| 121 | # define __NR_inotify_rm_watch 271 | - | ||||||||||||
| 122 | # define __NR_inotify_init1 314 | - | ||||||||||||
| 123 | #elif defined (__avr32__) | - | ||||||||||||
| 124 | # define __NR_inotify_init 240 | - | ||||||||||||
| 125 | # define __NR_inotify_add_watch 241 | - | ||||||||||||
| 126 | # define __NR_inotify_rm_watch 242 | - | ||||||||||||
| 127 | // no inotify_init1 for AVR32 | - | ||||||||||||
| 128 | #elif defined (__mc68000__) | - | ||||||||||||
| 129 | # define __NR_inotify_init 284 | - | ||||||||||||
| 130 | # define __NR_inotify_add_watch 285 | - | ||||||||||||
| 131 | # define __NR_inotify_rm_watch 286 | - | ||||||||||||
| 132 | # define __NR_inotify_init1 328 | - | ||||||||||||
| 133 | #elif defined (__aarch64__) | - | ||||||||||||
| 134 | # define __NR_inotify_init1 26 | - | ||||||||||||
| 135 | # define __NR_inotify_add_watch 27 | - | ||||||||||||
| 136 | # define __NR_inotify_rm_watch 28 | - | ||||||||||||
| 137 | // no inotify_init for aarch64 | - | ||||||||||||
| 138 | #else | - | ||||||||||||
| 139 | # error "This architecture is not supported. Please see http://www.qt-project.org/" | - | ||||||||||||
| 140 | #endif | - | ||||||||||||
| 141 | - | |||||||||||||
| 142 | #if !defined(IN_CLOEXEC) && defined(O_CLOEXEC) && defined(__NR_inotify_init1) | - | ||||||||||||
| 143 | # define IN_CLOEXEC O_CLOEXEC | - | ||||||||||||
| 144 | #endif | - | ||||||||||||
| 145 | - | |||||||||||||
| 146 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 147 | - | |||||||||||||
| 148 | #ifdef QT_LINUXBASE | - | ||||||||||||
| 149 | // ### the LSB doesn't standardize syscall, need to wait until glib2.4 is standardized | - | ||||||||||||
| 150 | static inline int syscall(...) { return -1; } | - | ||||||||||||
| 151 | #endif | - | ||||||||||||
| 152 | - | |||||||||||||
| 153 | static inline int inotify_init() | - | ||||||||||||
| 154 | { | - | ||||||||||||
| 155 | #ifdef __NR_inotify_init | - | ||||||||||||
| 156 | return syscall(__NR_inotify_init); | - | ||||||||||||
| 157 | #else | - | ||||||||||||
| 158 | return syscall(__NR_inotify_init1, 0); | - | ||||||||||||
| 159 | #endif | - | ||||||||||||
| 160 | } | - | ||||||||||||
| 161 | - | |||||||||||||
| 162 | static inline int inotify_add_watch(int fd, const char *name, __u32 mask) | - | ||||||||||||
| 163 | { | - | ||||||||||||
| 164 | return syscall(__NR_inotify_add_watch, fd, name, mask); | - | ||||||||||||
| 165 | } | - | ||||||||||||
| 166 | - | |||||||||||||
| 167 | static inline int inotify_rm_watch(int fd, __u32 wd) | - | ||||||||||||
| 168 | { | - | ||||||||||||
| 169 | return syscall(__NR_inotify_rm_watch, fd, wd); | - | ||||||||||||
| 170 | } | - | ||||||||||||
| 171 | - | |||||||||||||
| 172 | #ifdef IN_CLOEXEC | - | ||||||||||||
| 173 | static inline int inotify_init1(int flags) | - | ||||||||||||
| 174 | { | - | ||||||||||||
| 175 | return syscall(__NR_inotify_init1, flags); | - | ||||||||||||
| 176 | } | - | ||||||||||||
| 177 | #endif | - | ||||||||||||
| 178 | - | |||||||||||||
| 179 | // the following struct and values are documented in linux/inotify.h | - | ||||||||||||
| 180 | extern "C" { | - | ||||||||||||
| 181 | - | |||||||||||||
| 182 | struct inotify_event { | - | ||||||||||||
| 183 | __s32 wd; | - | ||||||||||||
| 184 | __u32 mask; | - | ||||||||||||
| 185 | __u32 cookie; | - | ||||||||||||
| 186 | __u32 len; | - | ||||||||||||
| 187 | char name[0]; | - | ||||||||||||
| 188 | }; | - | ||||||||||||
| 189 | - | |||||||||||||
| 190 | #define IN_ACCESS 0x00000001 | - | ||||||||||||
| 191 | #define IN_MODIFY 0x00000002 | - | ||||||||||||
| 192 | #define IN_ATTRIB 0x00000004 | - | ||||||||||||
| 193 | #define IN_CLOSE_WRITE 0x00000008 | - | ||||||||||||
| 194 | #define IN_CLOSE_NOWRITE 0x00000010 | - | ||||||||||||
| 195 | #define IN_OPEN 0x00000020 | - | ||||||||||||
| 196 | #define IN_MOVED_FROM 0x00000040 | - | ||||||||||||
| 197 | #define IN_MOVED_TO 0x00000080 | - | ||||||||||||
| 198 | #define IN_CREATE 0x00000100 | - | ||||||||||||
| 199 | #define IN_DELETE 0x00000200 | - | ||||||||||||
| 200 | #define IN_DELETE_SELF 0x00000400 | - | ||||||||||||
| 201 | #define IN_MOVE_SELF 0x00000800 | - | ||||||||||||
| 202 | #define IN_UNMOUNT 0x00002000 | - | ||||||||||||
| 203 | #define IN_Q_OVERFLOW 0x00004000 | - | ||||||||||||
| 204 | #define IN_IGNORED 0x00008000 | - | ||||||||||||
| 205 | - | |||||||||||||
| 206 | #define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) | - | ||||||||||||
| 207 | #define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) | - | ||||||||||||
| 208 | } | - | ||||||||||||
| 209 | - | |||||||||||||
| 210 | QT_END_NAMESPACE | - | ||||||||||||
| 211 | - | |||||||||||||
| 212 | // --------- inotify.h end ---------- | - | ||||||||||||
| 213 | - | |||||||||||||
| 214 | #else /* QT_NO_INOTIFY */ | - | ||||||||||||
| 215 | - | |||||||||||||
| 216 | #include <sys/inotify.h> | - | ||||||||||||
| 217 | - | |||||||||||||
| 218 | #endif | - | ||||||||||||
| 219 | - | |||||||||||||
| 220 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 221 | - | |||||||||||||
| 222 | QInotifyFileSystemWatcherEngine *QInotifyFileSystemWatcherEngine::create(QObject *parent) | - | ||||||||||||
| 223 | { | - | ||||||||||||
| 224 | int fd = -1; | - | ||||||||||||
| 225 | #ifdef IN_CLOEXEC | - | ||||||||||||
| 226 | fd = inotify_init1(IN_CLOEXEC); | - | ||||||||||||
| 227 | #endif | - | ||||||||||||
| 228 | if (fd == -1) {
| 0-354 | ||||||||||||
| 229 | fd = inotify_init(); | - | ||||||||||||
| 230 | if (fd == -1)
| 0 | ||||||||||||
| 231 | return 0; never executed: return 0; | 0 | ||||||||||||
| 232 | } never executed: end of block | 0 | ||||||||||||
| 233 | return new QInotifyFileSystemWatcherEngine(fd, parent); executed 354 times by 10 tests: return new QInotifyFileSystemWatcherEngine(fd, parent);Executed by:
| 354 | ||||||||||||
| 234 | } | - | ||||||||||||
| 235 | - | |||||||||||||
| 236 | QInotifyFileSystemWatcherEngine::QInotifyFileSystemWatcherEngine(int fd, QObject *parent) | - | ||||||||||||
| 237 | : QFileSystemWatcherEngine(parent), | - | ||||||||||||
| 238 | inotifyFd(fd), | - | ||||||||||||
| 239 | notifier(fd, QSocketNotifier::Read, this) | - | ||||||||||||
| 240 | { | - | ||||||||||||
| 241 | fcntl(inotifyFd, F_SETFD, FD_CLOEXEC); | - | ||||||||||||
| 242 | connect(¬ifier, SIGNAL(activated(int)), SLOT(readFromInotify())); | - | ||||||||||||
| 243 | } executed 354 times by 10 tests: end of blockExecuted by:
| 354 | ||||||||||||
| 244 | - | |||||||||||||
| 245 | QInotifyFileSystemWatcherEngine::~QInotifyFileSystemWatcherEngine() | - | ||||||||||||
| 246 | { | - | ||||||||||||
| 247 | notifier.setEnabled(false); | - | ||||||||||||
| 248 | foreach (int id, pathToID) | - | ||||||||||||
| 249 | inotify_rm_watch(inotifyFd, id < 0 ? -id : id); executed 360 times by 9 tests: inotify_rm_watch(inotifyFd, id < 0 ? -id : id);Executed by:
| 360 | ||||||||||||
| 250 | - | |||||||||||||
| 251 | ::close(inotifyFd); | - | ||||||||||||
| 252 | } executed 353 times by 11 tests: end of blockExecuted by:
| 353 | ||||||||||||
| 253 | - | |||||||||||||
| 254 | QStringList QInotifyFileSystemWatcherEngine::addPaths(const QStringList &paths, | - | ||||||||||||
| 255 | QStringList *files, | - | ||||||||||||
| 256 | QStringList *directories) | - | ||||||||||||
| 257 | { | - | ||||||||||||
| 258 | QStringList p = paths; | - | ||||||||||||
| 259 | QMutableListIterator<QString> it(p); | - | ||||||||||||
| 260 | while (it.hasNext()) {
| 475-477 | ||||||||||||
| 261 | QString path = it.next(); | - | ||||||||||||
| 262 | QFileInfo fi(path); | - | ||||||||||||
| 263 | bool isDir = fi.isDir(); | - | ||||||||||||
| 264 | if (isDir) {
| 36-441 | ||||||||||||
| 265 | if (directories->contains(path))
| 1-440 | ||||||||||||
| 266 | continue; executed 1 time by 1 test: continue;Executed by:
| 1 | ||||||||||||
| 267 | } else { executed 440 times by 8 tests: end of blockExecuted by:
| 440 | ||||||||||||
| 268 | if (files->contains(path))
| 0-36 | ||||||||||||
| 269 | continue; never executed: continue; | 0 | ||||||||||||
| 270 | } executed 36 times by 1 test: end of blockExecuted by:
| 36 | ||||||||||||
| 271 | - | |||||||||||||
| 272 | int wd = inotify_add_watch(inotifyFd, | - | ||||||||||||
| 273 | QFile::encodeName(path), | - | ||||||||||||
| 274 | (isDir | - | ||||||||||||
| 275 | ? (0 | - | ||||||||||||
| 276 | | IN_ATTRIB | - | ||||||||||||
| 277 | | IN_MOVE | - | ||||||||||||
| 278 | | IN_CREATE | - | ||||||||||||
| 279 | | IN_DELETE | - | ||||||||||||
| 280 | | IN_DELETE_SELF | - | ||||||||||||
| 281 | ) | - | ||||||||||||
| 282 | : (0 | - | ||||||||||||
| 283 | | IN_ATTRIB | - | ||||||||||||
| 284 | | IN_MODIFY | - | ||||||||||||
| 285 | | IN_MOVE | - | ||||||||||||
| 286 | | IN_MOVE_SELF | - | ||||||||||||
| 287 | | IN_DELETE_SELF | - | ||||||||||||
| 288 | ))); | - | ||||||||||||
| 289 | if (wd < 0) {
| 2-474 | ||||||||||||
| 290 | perror("QInotifyFileSystemWatcherEngine::addPaths: inotify_add_watch failed"); | - | ||||||||||||
| 291 | continue; executed 2 times by 1 test: continue;Executed by:
| 2 | ||||||||||||
| 292 | } | - | ||||||||||||
| 293 | - | |||||||||||||
| 294 | it.remove(); | - | ||||||||||||
| 295 | - | |||||||||||||
| 296 | int id = isDir ? -wd : wd;
| 34-440 | ||||||||||||
| 297 | if (id < 0) {
| 34-440 | ||||||||||||
| 298 | directories->append(path); | - | ||||||||||||
| 299 | } else { executed 440 times by 8 tests: end of blockExecuted by:
| 440 | ||||||||||||
| 300 | files->append(path); | - | ||||||||||||
| 301 | } executed 34 times by 1 test: end of blockExecuted by:
| 34 | ||||||||||||
| 302 | - | |||||||||||||
| 303 | pathToID.insert(path, id); | - | ||||||||||||
| 304 | idToPath.insert(id, path); | - | ||||||||||||
| 305 | } executed 474 times by 8 tests: end of blockExecuted by:
| 474 | ||||||||||||
| 306 | - | |||||||||||||
| 307 | return p; executed 475 times by 8 tests: return p;Executed by:
| 475 | ||||||||||||
| 308 | } | - | ||||||||||||
| 309 | - | |||||||||||||
| 310 | QStringList QInotifyFileSystemWatcherEngine::removePaths(const QStringList &paths, | - | ||||||||||||
| 311 | QStringList *files, | - | ||||||||||||
| 312 | QStringList *directories) | - | ||||||||||||
| 313 | { | - | ||||||||||||
| 314 | QStringList p = paths; | - | ||||||||||||
| 315 | QMutableListIterator<QString> it(p); | - | ||||||||||||
| 316 | while (it.hasNext()) {
| 106-107 | ||||||||||||
| 317 | QString path = it.next(); | - | ||||||||||||
| 318 | int id = pathToID.take(path); | - | ||||||||||||
| 319 | QString x = idToPath.take(id); | - | ||||||||||||
| 320 | if (x.isEmpty() || x != path)
| 0-95 | ||||||||||||
| 321 | continue; executed 12 times by 3 tests: continue;Executed by:
| 12 | ||||||||||||
| 322 | - | |||||||||||||
| 323 | int wd = id < 0 ? -id : id;
| 9-86 | ||||||||||||
| 324 | // qDebug() << "removing watch for path" << path << "wd" << wd; | - | ||||||||||||
| 325 | inotify_rm_watch(inotifyFd, wd); | - | ||||||||||||
| 326 | - | |||||||||||||
| 327 | it.remove(); | - | ||||||||||||
| 328 | if (id < 0) {
| 9-86 | ||||||||||||
| 329 | directories->removeAll(path); | - | ||||||||||||
| 330 | } else { executed 86 times by 5 tests: end of blockExecuted by:
| 86 | ||||||||||||
| 331 | files->removeAll(path); | - | ||||||||||||
| 332 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||
| 333 | } | - | ||||||||||||
| 334 | - | |||||||||||||
| 335 | return p; executed 106 times by 5 tests: return p;Executed by:
| 106 | ||||||||||||
| 336 | } | - | ||||||||||||
| 337 | - | |||||||||||||
| 338 | void QInotifyFileSystemWatcherEngine::readFromInotify() | - | ||||||||||||
| 339 | { | - | ||||||||||||
| 340 | // qDebug() << "QInotifyFileSystemWatcherEngine::readFromInotify"; | - | ||||||||||||
| 341 | - | |||||||||||||
| 342 | int buffSize = 0; | - | ||||||||||||
| 343 | ioctl(inotifyFd, FIONREAD, (char *) &buffSize); | - | ||||||||||||
| 344 | QVarLengthArray<char, 4096> buffer(buffSize); | - | ||||||||||||
| 345 | buffSize = read(inotifyFd, buffer.data(), buffSize); | - | ||||||||||||
| 346 | char *at = buffer.data(); | - | ||||||||||||
| 347 | char * const end = at + buffSize; | - | ||||||||||||
| 348 | - | |||||||||||||
| 349 | QHash<int, inotify_event *> eventForId; | - | ||||||||||||
| 350 | while (at < end) {
| 106-222 | ||||||||||||
| 351 | inotify_event *event = reinterpret_cast<inotify_event *>(at); | - | ||||||||||||
| 352 | - | |||||||||||||
| 353 | if (eventForId.contains(event->wd))
| 98-124 | ||||||||||||
| 354 | eventForId[event->wd]->mask |= event->mask; executed 98 times by 4 tests: eventForId[event->wd]->mask |= event->mask;Executed by:
| 98 | ||||||||||||
| 355 | else | - | ||||||||||||
| 356 | eventForId.insert(event->wd, event); executed 124 times by 6 tests: eventForId.insert(event->wd, event);Executed by:
| 124 | ||||||||||||
| 357 | - | |||||||||||||
| 358 | at += sizeof(inotify_event) + event->len; | - | ||||||||||||
| 359 | } executed 222 times by 6 tests: end of blockExecuted by:
| 222 | ||||||||||||
| 360 | - | |||||||||||||
| 361 | QHash<int, inotify_event *>::const_iterator it = eventForId.constBegin(); | - | ||||||||||||
| 362 | while (it != eventForId.constEnd()) {
| 106-124 | ||||||||||||
| 363 | const inotify_event &event = **it; | - | ||||||||||||
| 364 | ++it; | - | ||||||||||||
| 365 | - | |||||||||||||
| 366 | // qDebug() << "inotify event, wd" << event.wd << "mask" << hex << event.mask; | - | ||||||||||||
| 367 | - | |||||||||||||
| 368 | int id = event.wd; | - | ||||||||||||
| 369 | QString path = getPathFromID(id); | - | ||||||||||||
| 370 | if (path.isEmpty()) {
| 22-102 | ||||||||||||
| 371 | // perhaps a directory? | - | ||||||||||||
| 372 | id = -id; | - | ||||||||||||
| 373 | path = getPathFromID(id); | - | ||||||||||||
| 374 | if (path.isEmpty())
| 44-58 | ||||||||||||
| 375 | continue; executed 44 times by 4 tests: continue;Executed by:
| 44 | ||||||||||||
| 376 | } executed 58 times by 4 tests: end of blockExecuted by:
| 58 | ||||||||||||
| 377 | - | |||||||||||||
| 378 | // qDebug() << "event for path" << path; | - | ||||||||||||
| 379 | - | |||||||||||||
| 380 | if ((event.mask & (IN_DELETE_SELF | IN_MOVE_SELF | IN_UNMOUNT)) != 0) {
| 18-62 | ||||||||||||
| 381 | pathToID.remove(path); | - | ||||||||||||
| 382 | idToPath.remove(id, getPathFromID(id)); | - | ||||||||||||
| 383 | if (!idToPath.contains(id))
| 9 | ||||||||||||
| 384 | inotify_rm_watch(inotifyFd, event.wd); executed 9 times by 1 test: inotify_rm_watch(inotifyFd, event.wd);Executed by:
| 9 | ||||||||||||
| 385 | - | |||||||||||||
| 386 | if (id < 0)
| 4-14 | ||||||||||||
| 387 | emit directoryChanged(path, true); executed 4 times by 1 test: directoryChanged(path, true);Executed by:
| 4 | ||||||||||||
| 388 | else | - | ||||||||||||
| 389 | emit fileChanged(path, true); executed 14 times by 1 test: fileChanged(path, true);Executed by:
| 14 | ||||||||||||
| 390 | } else { | - | ||||||||||||
| 391 | if (id < 0)
| 8-54 | ||||||||||||
| 392 | emit directoryChanged(path, false); executed 54 times by 4 tests: directoryChanged(path, false);Executed by:
| 54 | ||||||||||||
| 393 | else | - | ||||||||||||
| 394 | emit fileChanged(path, false); executed 8 times by 1 test: fileChanged(path, false);Executed by:
| 8 | ||||||||||||
| 395 | } | - | ||||||||||||
| 396 | } | - | ||||||||||||
| 397 | } executed 106 times by 6 tests: end of blockExecuted by:
| 106 | ||||||||||||
| 398 | - | |||||||||||||
| 399 | QString QInotifyFileSystemWatcherEngine::getPathFromID(int id) const | - | ||||||||||||
| 400 | { | - | ||||||||||||
| 401 | QHash<int, QString>::const_iterator i = idToPath.find(id); | - | ||||||||||||
| 402 | while (i != idToPath.constEnd() && i.key() == id) {
| 0-146 | ||||||||||||
| 403 | if ((i + 1) == idToPath.constEnd() || (i + 1).key() != id) {
| 18-74 | ||||||||||||
| 404 | return i.value(); executed 98 times by 4 tests: return i.value();Executed by:
| 98 | ||||||||||||
| 405 | } | - | ||||||||||||
| 406 | ++i; | - | ||||||||||||
| 407 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||
| 408 | return QString(); executed 146 times by 6 tests: return QString();Executed by:
| 146 | ||||||||||||
| 409 | } | - | ||||||||||||
| 410 | - | |||||||||||||
| 411 | QT_END_NAMESPACE | - | ||||||||||||
| 412 | - | |||||||||||||
| 413 | #endif // QT_NO_FILESYSTEMWATCHER | - | ||||||||||||
| Source code | Switch to Preprocessed file |