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,42 @@ 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); + + // Checking if watches are installed + QSignalSpy spy1(&kn, &KInotify::deleted); + QDir dstdir(QStringLiteral("%1/sub").arg(dest)); + dstdir.removeRecursively(); + + QVERIFY(spy1.wait()); + QCOMPARE(spy1.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,20 @@ 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); + Q_EMIT created(QFile::decodeName(path), event->mask & IN_ISDIR); + if (event->mask & IN_ISDIR) { + Baloo::FilteredDirIterator it(d->config, QFile::decodeName(path)); + // First entry is the directory itself (if not excluded) + if (!it.next().isEmpty()) { + d->addWatch(it.filePath()); + } + while (!it.next().isEmpty()) { + Q_EMIT created(it.filePath(), it.fileInfo().isDir()); + if (it.fileInfo().isDir()) { + d->addWatch(it.filePath()); + } + } + } } } if (event->mask & EventOpen) {