connect(_folderWatcher.data(), &FolderWatcher::becameUnreliable,
this, &Folder::slotWatcherUnreliable);
_folderWatcher->init(path());
+ _folderWatcher->startNotificatonTest(path() + QLatin1String(".owncloudsync.log"));
}
void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction dir, bool *cancel)
#endif
#include "folder.h"
+#include "filesystem.h"
namespace OCC {
}
}
+void FolderWatcher::startNotificatonTest(const QString &path)
+{
+ Q_ASSERT(_testNotificationPath.isEmpty());
+ _testNotificationPath = path;
+
+ if (QFile::exists(path)) {
+ auto mtime = FileSystem::getModTime(path);
+ FileSystem::setModTime(path, mtime + 1);
+ } else {
+ QFile f(path);
+ f.open(QIODevice::WriteOnly | QIODevice::Append);
+ }
+
+ QTimer::singleShot(5000, 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
// ------- handle ignores:
for (int i = 0; i < paths.size(); ++i) {
QString path = paths[i];
+ if (!_testNotificationPath.isEmpty()
+ && Utility::fileNamesEqual(path, _testNotificationPath)) {
+ _testNotificationPath.clear();
+ }
if (pathIsIgnored(path)) {
continue;
}
*/
bool isReliable() const;
+ /**
+ * Triggers a change in the path and verifies a notification arrives.
+ *
+ * If no notification is seen, the folderwatcher marks itself as unreliable.
+ * The path must be ignored by the watcher.
+ */
+ void startNotificatonTest(const QString &path);
+
/// For testing linux behavior only
int testLinuxWatchCount() const;
void appendSubPaths(QDir dir, QStringList& subPaths);
+ /** Path of the expected test notification */
+ QString _testNotificationPath;
+
friend class FolderWatcherPrivate;
};
}
if (event->len == 0 || event->wd <= -1)
continue;
QByteArray fileName(event->name);
+ // Filter out journal changes - redundant with filtering in
+ // FolderWatcher::pathIsIgnored.
if (fileName.startsWith("._sync_")
|| fileName.startsWith(".csync_journal.db")
- || fileName.startsWith(".owncloudsync.log")
|| fileName.startsWith(".sync_")) {
continue;
}