| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qfilesystemwatcher_inotify.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||
| 3 | - | |||||||||||||||||||||||||
| 4 | - | |||||||||||||||||||||||||
| 5 | - | |||||||||||||||||||||||||
| 6 | - | |||||||||||||||||||||||||
| 7 | - | |||||||||||||||||||||||||
| 8 | - | |||||||||||||||||||||||||
| 9 | - | |||||||||||||||||||||||||
| 10 | - | |||||||||||||||||||||||||
| 11 | - | |||||||||||||||||||||||||
| 12 | QInotifyFileSystemWatcherEngine *QInotifyFileSystemWatcherEngine::create(QObject *parent) | - | ||||||||||||||||||||||||
| 13 | { | - | ||||||||||||||||||||||||
| 14 | int fd = -1; | - | ||||||||||||||||||||||||
| 15 | - | |||||||||||||||||||||||||
| 16 | fd = inotify_init1(IN_CLOEXEC); | - | ||||||||||||||||||||||||
| 17 | - | |||||||||||||||||||||||||
| 18 | if (fd == -1
| 0-355 | ||||||||||||||||||||||||
| 19 | fd = inotify_init(); | - | ||||||||||||||||||||||||
| 20 | if (fd == -1
| 0 | ||||||||||||||||||||||||
| 21 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||||||||
| 22 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 23 | return executed 355 times by 10 tests: new QInotifyFileSystemWatcherEngine(fd, parent);return new QInotifyFileSystemWatcherEngine(fd, parent);Executed by:
executed 355 times by 10 tests: return new QInotifyFileSystemWatcherEngine(fd, parent);Executed by:
| 355 | ||||||||||||||||||||||||
| 24 | } | - | ||||||||||||||||||||||||
| 25 | - | |||||||||||||||||||||||||
| 26 | QInotifyFileSystemWatcherEngine::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(¬ifier, qFlagLocation("2""activated(int)" "\0" __FILE__ ":" "249"), qFlagLocation("1""readFromInotify()" "\0" __FILE__ ":" "249")); | - | ||||||||||||||||||||||||
| 33 | } executed 355 times by 10 tests: end of blockExecuted by:
| 355 | ||||||||||||||||||||||||
| 34 | - | |||||||||||||||||||||||||
| 35 | QInotifyFileSystemWatcherEngine::~QInotifyFileSystemWatcherEngine() | - | ||||||||||||||||||||||||
| 36 | { | - | ||||||||||||||||||||||||
| 37 | notifier.setEnabled(false); | - | ||||||||||||||||||||||||
| 38 | for (int id : qAsConst(pathToID)) | - | ||||||||||||||||||||||||
| 39 | inotify_rm_watch(inotifyFd, id < 0 ? -id : id); executed 361 times by 9 tests: inotify_rm_watch(inotifyFd, id < 0 ? -id : id);Executed by:
| 361 | ||||||||||||||||||||||||
| 40 | - | |||||||||||||||||||||||||
| 41 | ::close(inotifyFd); | - | ||||||||||||||||||||||||
| 42 | } executed 354 times by 11 tests: end of blockExecuted by:
| 354 | ||||||||||||||||||||||||
| 43 | - | |||||||||||||||||||||||||
| 44 | QStringList 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()
| 476-478 | ||||||||||||||||||||||||
| 51 | QString path = it.next(); | - | ||||||||||||||||||||||||
| 52 | QFileInfo fi(path); | - | ||||||||||||||||||||||||
| 53 | bool isDir = fi.isDir(); | - | ||||||||||||||||||||||||
| 54 | if (isDir
| 36-442 | ||||||||||||||||||||||||
| 55 | if (directories->contains(path)
| 1-441 | ||||||||||||||||||||||||
| 56 | continue; executed 1 time by 1 test: continue;Executed by:
| 1 | ||||||||||||||||||||||||
| 57 | } executed 441 times by 8 tests: else {end of blockExecuted by:
| 441 | ||||||||||||||||||||||||
| 58 | if (files->contains(path)
| 0-36 | ||||||||||||||||||||||||
| 59 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 60 | } executed 36 times by 1 test: end of blockExecuted by:
| 36 | ||||||||||||||||||||||||
| 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
| 2-475 | ||||||||||||||||||||||||
| 80 | QMessageLogger(__FILE__, 297, __PRETTY_FUNCTION__).warning().nospace() << "inotify_add_watch(" << path << ") failed: " << QSystemError((*__errno_location ()), QSystemError::NativeError).toString(); | - | ||||||||||||||||||||||||
| 81 | continue; executed 2 times by 1 test: continue;Executed by:
| 2 | ||||||||||||||||||||||||
| 82 | } | - | ||||||||||||||||||||||||
| 83 | - | |||||||||||||||||||||||||
| 84 | it.remove(); | - | ||||||||||||||||||||||||
| 85 | - | |||||||||||||||||||||||||
| 86 | int id = isDir
| 34-441 | ||||||||||||||||||||||||
| 87 | if (id < 0
| 34-441 | ||||||||||||||||||||||||
| 88 | directories->append(path); | - | ||||||||||||||||||||||||
| 89 | } executed 441 times by 8 tests: else {end of blockExecuted by:
| 441 | ||||||||||||||||||||||||
| 90 | files->append(path); | - | ||||||||||||||||||||||||
| 91 | } executed 34 times by 1 test: end of blockExecuted by:
| 34 | ||||||||||||||||||||||||
| 92 | - | |||||||||||||||||||||||||
| 93 | pathToID.insert(path, id); | - | ||||||||||||||||||||||||
| 94 | idToPath.insert(id, path); | - | ||||||||||||||||||||||||
| 95 | } executed 475 times by 8 tests: end of blockExecuted by:
| 475 | ||||||||||||||||||||||||
| 96 | - | |||||||||||||||||||||||||
| 97 | return executed 476 times by 8 tests: p;return p;Executed by:
executed 476 times by 8 tests: return p;Executed by:
| 476 | ||||||||||||||||||||||||
| 98 | } | - | ||||||||||||||||||||||||
| 99 | - | |||||||||||||||||||||||||
| 100 | QStringList 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()
| 106-107 | ||||||||||||||||||||||||
| 107 | QString path = it.next(); | - | ||||||||||||||||||||||||
| 108 | int id = pathToID.take(path); | - | ||||||||||||||||||||||||
| 109 | QString x = idToPath.take(id); | - | ||||||||||||||||||||||||
| 110 | if (x.isEmpty()
| 0-95 | ||||||||||||||||||||||||
| 111 | continue; executed 12 times by 3 tests: continue;Executed by:
| 12 | ||||||||||||||||||||||||
| 112 | - | |||||||||||||||||||||||||
| 113 | int wd = id < 0
| 9-86 | ||||||||||||||||||||||||
| 114 | - | |||||||||||||||||||||||||
| 115 | inotify_rm_watch(inotifyFd, wd); | - | ||||||||||||||||||||||||
| 116 | - | |||||||||||||||||||||||||
| 117 | it.remove(); | - | ||||||||||||||||||||||||
| 118 | if (id < 0
| 9-86 | ||||||||||||||||||||||||
| 119 | directories->removeAll(path); | - | ||||||||||||||||||||||||
| 120 | } executed 86 times by 5 tests: else {end of blockExecuted by:
| 86 | ||||||||||||||||||||||||
| 121 | files->removeAll(path); | - | ||||||||||||||||||||||||
| 122 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||||||||
| 123 | } | - | ||||||||||||||||||||||||
| 124 | - | |||||||||||||||||||||||||
| 125 | return executed 106 times by 5 tests: p;return p;Executed by:
executed 106 times by 5 tests: return p;Executed by:
| 106 | ||||||||||||||||||||||||
| 126 | } | - | ||||||||||||||||||||||||
| 127 | - | |||||||||||||||||||||||||
| 128 | void 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
| 106-222 | ||||||||||||||||||||||||
| 141 | inotify_event *event = reinterpret_cast<inotify_event *>(at); | - | ||||||||||||||||||||||||
| 142 | - | |||||||||||||||||||||||||
| 143 | if (eventForId.contains(event->wd)
| 98-124 | ||||||||||||||||||||||||
| 144 | eventForId[event->wd]->mask |= event->mask; executed 98 times by 4 tests: eventForId[event->wd]->mask |= event->mask;Executed by:
| 98 | ||||||||||||||||||||||||
| 145 | else | - | ||||||||||||||||||||||||
| 146 | eventForId.insert(event->wd, event); executed 124 times by 6 tests: eventForId.insert(event->wd, event);Executed by:
| 124 | ||||||||||||||||||||||||
| 147 | - | |||||||||||||||||||||||||
| 148 | at += sizeof(inotify_event) + event->len; | - | ||||||||||||||||||||||||
| 149 | } executed 222 times by 6 tests: end of blockExecuted by:
| 222 | ||||||||||||||||||||||||
| 150 | - | |||||||||||||||||||||||||
| 151 | QHash<int, inotify_event *>::const_iterator it = eventForId.constBegin(); | - | ||||||||||||||||||||||||
| 152 | while (it != eventForId.constEnd()
| 106-124 | ||||||||||||||||||||||||
| 153 | const inotify_event &event = **it; | - | ||||||||||||||||||||||||
| 154 | ++it; | - | ||||||||||||||||||||||||
| 155 | - | |||||||||||||||||||||||||
| 156 | - | |||||||||||||||||||||||||
| 157 | - | |||||||||||||||||||||||||
| 158 | int id = event.wd; | - | ||||||||||||||||||||||||
| 159 | QString path = getPathFromID(id); | - | ||||||||||||||||||||||||
| 160 | if (path.isEmpty()
| 22-102 | ||||||||||||||||||||||||
| 161 | - | |||||||||||||||||||||||||
| 162 | id = -id; | - | ||||||||||||||||||||||||
| 163 | path = getPathFromID(id); | - | ||||||||||||||||||||||||
| 164 | if (path.isEmpty()
| 44-58 | ||||||||||||||||||||||||
| 165 | continue; executed 44 times by 4 tests: continue;Executed by:
| 44 | ||||||||||||||||||||||||
| 166 | } executed 58 times by 4 tests: end of blockExecuted by:
| 58 | ||||||||||||||||||||||||
| 167 | - | |||||||||||||||||||||||||
| 168 | - | |||||||||||||||||||||||||
| 169 | - | |||||||||||||||||||||||||
| 170 | if ((
| 18-62 | ||||||||||||||||||||||||
| 171 | pathToID.remove(path); | - | ||||||||||||||||||||||||
| 172 | idToPath.remove(id, getPathFromID(id)); | - | ||||||||||||||||||||||||
| 173 | if (!idToPath.contains(id)
| 9 | ||||||||||||||||||||||||
| 174 | inotify_rm_watch(inotifyFd, event.wd); executed 9 times by 1 test: inotify_rm_watch(inotifyFd, event.wd);Executed by:
| 9 | ||||||||||||||||||||||||
| 175 | - | |||||||||||||||||||||||||
| 176 | if (id < 0
| 4-14 | ||||||||||||||||||||||||
| 177 | directoryChanged(path, true); executed 4 times by 1 test: directoryChanged(path, true);Executed by:
| 4 | ||||||||||||||||||||||||
| 178 | else | - | ||||||||||||||||||||||||
| 179 | fileChanged(path, true); executed 14 times by 1 test: fileChanged(path, true);Executed by:
| 14 | ||||||||||||||||||||||||
| 180 | } else { | - | ||||||||||||||||||||||||
| 181 | if (id < 0
| 8-54 | ||||||||||||||||||||||||
| 182 | directoryChanged(path, false); executed 54 times by 4 tests: directoryChanged(path, false);Executed by:
| 54 | ||||||||||||||||||||||||
| 183 | else | - | ||||||||||||||||||||||||
| 184 | fileChanged(path, false); executed 8 times by 1 test: fileChanged(path, false);Executed by:
| 8 | ||||||||||||||||||||||||
| 185 | } | - | ||||||||||||||||||||||||
| 186 | } | - | ||||||||||||||||||||||||
| 187 | } executed 106 times by 6 tests: end of blockExecuted by:
| 106 | ||||||||||||||||||||||||
| 188 | - | |||||||||||||||||||||||||
| 189 | QString QInotifyFileSystemWatcherEngine::getPathFromID(int id) const | - | ||||||||||||||||||||||||
| 190 | { | - | ||||||||||||||||||||||||
| 191 | QHash<int, QString>::const_iterator i = idToPath.find(id); | - | ||||||||||||||||||||||||
| 192 | while (i != idToPath.constEnd()
| 0-146 | ||||||||||||||||||||||||
| 193 | if ((
| 18-76 | ||||||||||||||||||||||||
| 194 | return executed 98 times by 4 tests: i.value();return i.value();Executed by:
executed 98 times by 4 tests: return i.value();Executed by:
| 98 | ||||||||||||||||||||||||
| 195 | } | - | ||||||||||||||||||||||||
| 196 | ++i; | - | ||||||||||||||||||||||||
| 197 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||||||||
| 198 | return executed 146 times by 6 tests: QString();return QString();Executed by:
executed 146 times by 6 tests: return QString();Executed by:
| 146 | ||||||||||||||||||||||||
| 199 | } | - | ||||||||||||||||||||||||
| 200 | - | |||||||||||||||||||||||||
| 201 | - | |||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |