diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index b443bbfe2..f76cb2552 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -140,15 +140,15 @@ void FolderMan::registerFolderMonitor( Folder *folder ) fw->addIgnoreListFile( cfg.excludeFile(MirallConfigFile::SystemScope) ); fw->addIgnoreListFile( cfg.excludeFile(MirallConfigFile::UserScope) ); - // Connect the folderChanged signal, which comes with the changed path, + // Connect the pathChanged signal, which comes with the changed path, // to the signal mapper which maps to the folder alias. The changed path // is lost this way, but we do not need it for the current implementation. - connect(fw, SIGNAL(folderChanged(QString)), _folderWatcherSignalMapper, SLOT(map())); + connect(fw, SIGNAL(pathChanged(QString)), _folderWatcherSignalMapper, SLOT(map())); _folderWatcherSignalMapper->setMapping(fw, folder->alias()); _folderWatchers.insert(folder->alias(), fw); // This is at the moment only for the behaviour of the SocketApi. - connect(fw, SIGNAL(folderChanged(QString)), folder, SLOT(watcherSlot(QString))); + connect(fw, SIGNAL(pathChanged(QString)), folder, SLOT(watcherSlot(QString))); } // register the folder with the socket API diff --git a/src/gui/folderwatcher.cpp b/src/gui/folderwatcher.cpp index cb4a4209d..047ec8c09 100644 --- a/src/gui/folderwatcher.cpp +++ b/src/gui/folderwatcher.cpp @@ -130,7 +130,7 @@ void FolderWatcher::changeDetected( const QStringList& paths ) _lastPaths = pathsSet; _timer.restart(); - QSet changedFolders; + QSet changedPaths; // ------- handle ignores: for (int i = 0; i < paths.size(); ++i) { @@ -139,20 +139,15 @@ void FolderWatcher::changeDetected( const QStringList& paths ) continue; } - QFileInfo fi(path); - if (fi.isDir()) { - changedFolders.insert(path); - } else { - changedFolders.insert(fi.dir().path()); - } + changedPaths.insert(path); } - if (changedFolders.isEmpty()) { + if (changedPaths.isEmpty()) { return; } - qDebug() << "detected changes in folders:" << changedFolders; - foreach (const QString &path, changedFolders) { - emit folderChanged(path); + qDebug() << "detected changes in paths:" << changedPaths; + foreach (const QString &path, changedPaths) { + emit pathChanged(path); } } diff --git a/src/gui/folderwatcher.h b/src/gui/folderwatcher.h index bcdb5f0ee..e792ed626 100644 --- a/src/gui/folderwatcher.h +++ b/src/gui/folderwatcher.h @@ -34,7 +34,7 @@ class FolderWatcherPrivate; /* * Folder Watcher monitors a directory and its sub directories * for changes in the local file system. Changes are signalled - * through the folderChanged() signal. + * through the pathChanged() signal. * * Note that if new folders are created, this folderwatcher class * does not automatically adds them to the list of monitored @@ -74,8 +74,9 @@ public: bool pathIsIgnored( const QString& path ); signals: - /** Emitted when one of the paths is changed */ - void folderChanged(const QString &path); + /** Emitted when one of the watched directories or one + * of the contained files is changed. */ + void pathChanged(const QString &path); /** Emitted if an error occurs */ void error(const QString& error); diff --git a/src/gui/folderwatcher_linux.cpp b/src/gui/folderwatcher_linux.cpp index 61321f9d3..437de51b0 100644 --- a/src/gui/folderwatcher_linux.cpp +++ b/src/gui/folderwatcher_linux.cpp @@ -159,7 +159,6 @@ void FolderWatcherPrivate::slotReceivedNotification(int fd) while(i + sizeof(struct inotify_event) < static_cast(len)) { // cast an inotify_event event = (struct inotify_event*)&buffer[i]; - // with the help of watch descriptor, retrieve, corresponding INotify if (event == NULL) { qDebug() << "NULL event"; i += sizeof(struct inotify_event); diff --git a/test/testfolderwatcher.h b/test/testfolderwatcher.h index 6bbe48671..3d69ee543 100644 --- a/test/testfolderwatcher.h +++ b/test/testfolderwatcher.h @@ -73,7 +73,7 @@ private slots: Utility::writeRandomFile( _root+"/a1/movefile"); _watcher = new FolderWatcher(_root); - QObject::connect(_watcher, SIGNAL(folderChanged(QString)), this, SLOT(slotFolderChanged(QString))); + QObject::connect(_watcher, SIGNAL(pathChanged(QString)), this, SLOT(slotFolderChanged(QString))); _timer.singleShot(5000, this, SLOT(slotEnd())); } @@ -91,9 +91,10 @@ private slots: } void testACreate() { // create a new file + QString file(_root + "/foo.txt"); QString cmd; - _requiredNotifications.insert(_root); - cmd = QString("echo \"xyz\" > %1/foo.txt").arg(_root); + _requiredNotifications.insert(file); + cmd = QString("echo \"xyz\" > %1").arg(file); qDebug() << "Command: " << cmd; system(cmd.toLocal8Bit()); @@ -101,12 +102,13 @@ private slots: } void testATouch() { // touch an existing file. - _requiredNotifications.insert(_root+"/a1"); + QString file(_root + "/a1/random.bin"); + _requiredNotifications.insert(file); #ifdef Q_OS_WIN Utility::writeRandomFile(QString("%1/a1/random.bin").arg(_root)); #else QString cmd; - cmd = QString("/usr/bin/touch %1/a1/random.bin").arg(_root); + cmd = QString("/usr/bin/touch %1").arg(file); qDebug() << "Command: " << cmd; system(cmd.toLocal8Bit()); #endif @@ -115,47 +117,55 @@ private slots: } void testCreateADir() { - _requiredNotifications.insert(_root+"/a1/b1"); - _skipNotifications.insert(_root + "/a1/b1/new_dir"); + QString file(_root+"/a1/b1/new_dir"); + _requiredNotifications.insert(file); + //_skipNotifications.insert(_root + "/a1/b1/new_dir"); QDir dir; - dir.mkdir( _root + "/a1/b1/new_dir"); - QVERIFY(QFile::exists(_root + "/a1/b1/new_dir")); + dir.mkdir(file); + QVERIFY(QFile::exists(file)); checkNotifications(); } void testRemoveADir() { - _requiredNotifications.insert(_root+"/a1/b3"); + QString file(_root+"/a1/b3/c3"); + _requiredNotifications.insert(file); QDir dir; - QVERIFY(dir.rmdir(_root+"/a1/b3/c3")); + QVERIFY(dir.rmdir(file)); checkNotifications(); } void testRemoveAFile() { - _requiredNotifications.insert(_root+"/a1/b2"); - QVERIFY(QFile::exists(_root+"/a1/b2/todelete.bin")); - QFile::remove(_root+"/a1/b2/todelete.bin"); - QVERIFY(!QFile::exists(_root+"/a1/b2/todelete.bin")); + QString file(_root+"/a1/b2/todelete.bin"); + _requiredNotifications.insert(file); + QVERIFY(QFile::exists(file)); + QFile::remove(file); + QVERIFY(!QFile::exists(file)); checkNotifications(); } void testRenameAFile() { - _requiredNotifications.insert(_root+"/a2"); - QVERIFY(QFile::exists(_root+"/a2/renamefile")); - QFile::rename(_root+"/a2/renamefile", _root+"/a2/renamefile.renamed" ); - QVERIFY(QFile::exists(_root+"/a2/renamefile.renamed")); + QString file1(_root+"/a2/renamefile"); + QString file2(_root+"/a2/renamefile.renamed"); + _requiredNotifications.insert(file1); + _requiredNotifications.insert(file2); + QVERIFY(QFile::exists(file1)); + QFile::rename(file1, file2); + QVERIFY(QFile::exists(file2)); checkNotifications(); } void testMoveAFile() { - _requiredNotifications.insert(_root+"/a1"); - _requiredNotifications.insert(_root+"/a2"); - QVERIFY(QFile::exists(_root+"/a1/movefile")); - QFile::rename(_root+"/a1/movefile", _root+"/a2/movefile.renamed" ); - QVERIFY(QFile::exists(_root+"/a2/movefile.renamed")); + QString old_file(_root+"/a1/movefile"); + QString new_file(_root+"/a2/movefile.renamed"); + _requiredNotifications.insert(old_file); + _requiredNotifications.insert(new_file); + QVERIFY(QFile::exists(old_file)); + QFile::rename(old_file, new_file); + QVERIFY(QFile::exists(new_file)); checkNotifications(); }