59QStringList QKqueueFileSystemWatcherEngine::addPaths(
const QStringList &paths,
61 QStringList *directories)
63 QStringList unhandled;
64 for (
const QString &path : paths) {
65 auto sg = qScopeGuard([&]{unhandled.push_back(path);});
68 fd = qt_safe_open(QFile::encodeName(path), O_EVTONLY);
70 fd = qt_safe_open(QFile::encodeName(path), O_RDONLY);
73 perror(
"QKqueueFileSystemWatcherEngine::addPaths: open");
76 if (fd >= (
int)FD_SETSIZE / 2 && fd < (
int)FD_SETSIZE) {
77 int fddup = qt_safe_dup(fd, FD_SETSIZE);
85 if (QT_FSTAT(fd, &st) == -1) {
86 perror(
"QKqueueFileSystemWatcherEngine::addPaths: fstat");
90 int id = (S_ISDIR(st.st_mode)) ? -fd : fd;
92 if (directories->contains(path)) {
97 if (files->contains(path)) {
107 EV_ADD | EV_ENABLE | EV_CLEAR,
108 NOTE_DELETE | NOTE_WRITE | NOTE_EXTEND | NOTE_ATTRIB | NOTE_RENAME | NOTE_REVOKE,
111 if (kevent(kqfd, &kev, 1, 0, 0, 0) == -1) {
112 perror(
"QKqueueFileSystemWatcherEngine::addPaths: kevent");
120 DEBUG() <<
"QKqueueFileSystemWatcherEngine: added directory path" << path;
121 directories->append(path);
123 DEBUG() <<
"QKqueueFileSystemWatcherEngine: added file path" << path;
127 pathToID.insert(path, id);
128 idToPath.insert(id, path);
134QStringList QKqueueFileSystemWatcherEngine::removePaths(
const QStringList &paths,
136 QStringList *directories)
138 if (pathToID.isEmpty())
141 QStringList unhandled;
142 for (
const QString &path : paths) {
143 auto sg = qScopeGuard([&]{unhandled.push_back(path);});
144 int id = pathToID.take(path);
145 QString x = idToPath.take(id);
146 if (x.isEmpty() || x != path)
149 ::close(id < 0 ? -id : id);
154 directories->removeAll(path);
156 files->removeAll(path);
169 QT_EINTR_LOOP(r, kevent(kqfd, 0, 0, &kev, 1, &ts));