Q_ASSERT(_testNotificationPath.isEmpty());
_testNotificationPath = path;
+ // Don't do the local file modification immediately:
+ // wait for FolderWatchPrivate::_ready
+ startNotificationTestWhenReady();
+}
+
+void FolderWatcher::startNotificationTestWhenReady()
+{
+ if (!_d->_ready) {
+ QTimer::singleShot(1000, this, &FolderWatcher::startNotificationTestWhenReady);
+ return;
+ }
+
+ auto path = _testNotificationPath;
if (QFile::exists(path)) {
auto mtime = FileSystem::getModTime(path);
FileSystem::setModTime(path, mtime + 1);
f.open(QIODevice::WriteOnly | QIODevice::Append);
}
- QTimer::singleShot(5000, this, [&]() {
+ QTimer::singleShot(5000, this, [this]() {
if (!_testNotificationPath.isEmpty())
emit becameUnreliable(tr("The watcher did not receive a test notification."));
_testNotificationPath.clear();
});
}
+
int FolderWatcher::testLinuxWatchCount() const
{
#ifdef Q_OS_LINUX
void changeDetected(const QString &path);
void changeDetected(const QStringList &paths);
+private slots:
+ void startNotificationTestWhenReady();
+
protected:
QHash<QString, int> _pendingPathes;
int testWatchCount() const { return _pathToWatch.size(); }
+ /// On linux the watcher is ready when the ctor finished.
+ bool _ready = true;
+
protected slots:
void slotReceivedNotification(int fd);
void slotAddFolderRecursive(const QString &path);
QStringList addCoalescedPaths(const QStringList &) const;
void doNotifyParent(const QStringList &);
+ /// On OSX the watcher is ready when the ctor finished.
+ bool _ready = true;
+
private:
FolderWatcher *_parent;
break;
}
+ emit ready();
+
HANDLE handles[] = { _resultEvent, _stopEvent };
DWORD result = WaitForMultipleObjects(
2, handles,
_parent, SLOT(changeDetected(const QString &)));
connect(_thread, SIGNAL(lostChanges()),
_parent, SIGNAL(lostChanges()));
+ connect(_thread, &WatcherThread::ready,
+ this, [this]() { _ready = 1; });
_thread->start();
}
signals:
void changed(const QString &path);
void lostChanges();
+ void ready();
private:
QString _path;
FolderWatcherPrivate(FolderWatcher *p, const QString &path);
~FolderWatcherPrivate();
+ /// Set to non-zero once the WatcherThread is capturing events.
+ QAtomicInt _ready;
+
private:
FolderWatcher *_parent;
WatcherThread *_thread;