diff --git a/autotests/unit/file/kinotifytest.cpp b/autotests/unit/file/kinotifytest.cpp --- a/autotests/unit/file/kinotifytest.cpp +++ b/autotests/unit/file/kinotifytest.cpp @@ -44,6 +44,7 @@ void testMoveFile(); void testRenameFolder(); void testMoveFolder(); + void testMoveFromUnwatchedFolder(); void testMoveRootFolder(); void testFileClosedAfterWrite(); }; @@ -351,6 +352,34 @@ QCOMPARE(createdSpy.takeFirst().at(0).toString(), f4); } +void KInotifyTest::testMoveFromUnwatchedFolder() +{ + // create some test folders + QTemporaryDir dir; + const QString src(QStringLiteral("%1/randomJunk1").arg(dir.path())); + const QString dest(QStringLiteral("%1/randomJunk2").arg(dir.path())); + mkdir(src); + mkdir(dest); + + // Start watching only for destination + KInotify kn(nullptr); + kn.addWatch(dest, KInotify::EventAll); + QSignalSpy spy(&kn, &KInotify::created); + + // Create stuff inside src + mkdir(QStringLiteral("%1/sub").arg(src)); + touchFile(QStringLiteral("%1/sub/file1").arg(src)); + mkdir(QStringLiteral("%1/sub/sub1").arg(src)); + touchFile(QStringLiteral("%1/sub/sub1/file2").arg(src)); + + // Now move + QFile::rename(QStringLiteral("%1/sub").arg(src), + QStringLiteral("%1/sub").arg(dest)); + + QVERIFY(spy.wait()); + QCOMPARE(spy.count(), 4); +} + void KInotifyTest::testMoveRootFolder() { diff --git a/src/file/kinotify.cpp b/src/file/kinotify.cpp --- a/src/file/kinotify.cpp +++ b/src/file/kinotify.cpp @@ -421,7 +421,17 @@ Q_EMIT moved(QFile::decodeName(oldPath), QFile::decodeName(path)); } else { // qCDebug(BALOO) << "No cookie for move information of" << path << "simulating new file event"; - Q_EMIT created(QString::fromUtf8(path), event->mask & IN_ISDIR); + // The directory was moved from an unwatched place, and could contain files + // We should emit created() for all of them + if (event->mask & IN_ISDIR) { + Baloo::FilteredDirIterator it(d->config, QFile::decodeName(path)); + while (!it.next().isEmpty()) { + Q_EMIT created(it.filePath(), it.fileInfo().isDir()); + } + addWatch(QFile::decodeName(path), d->mode, d->flags); + } else { + Q_EMIT created(QFile::decodeName(path), event->mask & IN_ISDIR); + } } } if (event->mask & EventOpen) {