diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/integration/querytest.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/integration/querytest.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/integration/querytest.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/integration/querytest.cpp 2020-05-10 14:18:38.000000000 +0000 @@ -118,7 +118,6 @@ TermGenerator tg(doc); tg.indexText(text); tg.indexFileNameText(fileName); - tg.indexFileNameText(fileName, QByteArrayLiteral("F")); doc.setId(id); doc.setMTime(1); doc.setCTime(2); @@ -132,7 +131,6 @@ TermGenerator tg(doc); tg.indexFileNameText(newName); - tg.indexFileNameText(newName, QByteArrayLiteral("F")); doc.setId(id); tr->replaceDocument(doc, FileNameTerms); @@ -239,27 +237,36 @@ void QueryTest::testTermPhrase_data() { QTest::addColumn("phrase"); - QTest::addColumn>("matchIds"); + QTest::addColumn>("contentMatches"); + QTest::addColumn>("filenameMatches"); QTest::addColumn("failReason"); auto addRow = [](const char* name, const QByteArrayList& phrase, - const QVector matchIds, const QString& failureReason) - { QTest::addRow("%s", name) << phrase << matchIds << failureReason; }; - - addRow("Crazy dog", {"crazy", "dog"}, SortedIdVector{ m_id1 }, ""); - addRow("Lazy dog", {"lazy", "dog"}, SortedIdVector{ m_id7 }, ""); - addRow("Brown fox", {"brown", "fox"}, SortedIdVector{ m_id1, m_id7, m_id8 }, ""); - addRow("Crazy dog file 1", {"file1"}, SortedIdVector{ m_id1 }, ""); - addRow("Crazy dog file 2", {"file1", "txt"}, SortedIdVector{ m_id1 }, ""); - addRow("Lazy dog file 1", {"file7"}, SortedIdVector{ m_id7 }, ""); - addRow("Lazy dog file 2", {"file7", "lazy"}, SortedIdVector{ m_id7 }, "Content shadows filename"); - addRow("Lazy dog file 3", {"dog"}, SortedIdVector{ m_id1, m_id7, m_id8 }, "Filename shadows content"); + const QVector contentMatches, + const QVector filenameMatches, + const QString& failureReason) + { QTest::addRow("%s", name) << phrase << contentMatches << filenameMatches << failureReason; }; + + // Content matches + addRow("Crazy dog", {"crazy", "dog"}, SortedIdVector{ m_id1 }, {}, ""); + addRow("Lazy dog", {"lazy", "dog"}, SortedIdVector{ m_id7 }, {}, ""); + addRow("Brown fox", {"brown", "fox"}, SortedIdVector{ m_id1, m_id7, m_id8 }, {}, ""); + addRow("Dog", {"dog"}, SortedIdVector{ m_id1, m_id7, m_id8 }, {}, ""); + // Filename matches + addRow("Crazy dog file 1", {"file1"}, {}, SortedIdVector{ m_id1 }, ""); + addRow("Crazy dog file 2", {"file1", "txt"}, {}, SortedIdVector{ m_id1 }, ""); + addRow("Lazy dog file 1", {"file7"}, {}, SortedIdVector{ m_id7 }, ""); + addRow("Lazy dog file 2", {"file7", "lazy"}, {}, SortedIdVector{ m_id7 }, ""); + // Matches content and filename + addRow("Lazy both", {"lazy"}, { m_id7 }, { m_id7 }, ""); + addRow("Easy both", {"easy"}, { m_id8 }, { m_id8 }, ""); } void QueryTest::testTermPhrase() { QFETCH(QByteArrayList, phrase); - QFETCH(QVector, matchIds); + QFETCH(QVector, contentMatches); + QFETCH(QVector, filenameMatches); QFETCH(QString, failReason); QVector queries; @@ -272,7 +279,16 @@ if (!failReason.isEmpty()) { QEXPECT_FAIL("", qPrintable(failReason), Continue); } - QCOMPARE(tr.exec(q), matchIds); + QCOMPARE(tr.exec(q), contentMatches); + + queries.clear(); + const QByteArray fPrefix = QByteArrayLiteral("F"); + for (QByteArray term : phrase) { + term = fPrefix + term; + queries << EngineQuery(term); + } + EngineQuery qf(queries, EngineQuery::Phrase); + QCOMPARE(tr.exec(qf), filenameMatches); } void QueryTest::testTagTermAnd_data() diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/unit/file/basicindexingqueuetest.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/unit/file/basicindexingqueuetest.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/unit/file/basicindexingqueuetest.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/unit/file/basicindexingqueuetest.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,447 +0,0 @@ -/* - * Copyright (C) 2014 Vishesh Handa - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include "fileindexerconfigutils.h" - -#include "../fileindexerconfig.h" -#include "../basicindexingqueue.h" -#include "../database.h" -#include "../../lib/autotests/xattrdetector.h" -#include "baloo_xattr_p.h" - -#include -#include -#include - -using namespace Baloo; - -class BasicIndexingQueueTest : public QObject -{ - Q_OBJECT -private Q_SLOTS: - void testSimpleDirectoryStructure(); - void textExtendedAttributeIndexing(); - void textNormalAndThenExtendedAttributeIndexing(); - void testExtendedAttributeIndexingWhenEmpty(); - void testFileModifications(); -}; - -Q_DECLARE_METATYPE(Xapian::Document) - -void BasicIndexingQueueTest::testSimpleDirectoryStructure() -{ - qRegisterMetaType("Xapian::Document"); - - QStringList dirs; - dirs << QLatin1String("home/"); - dirs << QLatin1String("home/1"); - dirs << QLatin1String("home/2"); - dirs << QLatin1String("home/kde/"); - dirs << QLatin1String("home/kde/1"); - dirs << QLatin1String("home/docs/"); - dirs << QLatin1String("home/docs/1"); - - QScopedPointer dir(Test::createTmpFilesAndFolders(dirs)); - - QStringList includeFolders; - includeFolders << dir->path() + QLatin1String("/home"); - - QStringList excludeFolders; - excludeFolders << dir->path() + QLatin1String("/home/kde"); - - Test::writeIndexerConfig(includeFolders, excludeFolders); - - QTemporaryDir dbDir; - Database db; - db.setPath(dbDir.path()); - db.init(); - - FileIndexerConfig config; - BasicIndexingQueue queue(&db, &config); - QCOMPARE(queue.isSuspended(), false); - - QSignalSpy spy(&queue, SIGNAL(newDocument(quint64,Xapian::Document))); - QSignalSpy spyStarted(&queue, SIGNAL(startedIndexing())); - QSignalSpy spyFinished(&queue, SIGNAL(finishedIndexing())); - - queue.enqueue(FileMapping(dir->path() + QLatin1String("/home"))); - - QEventLoop loop; - connect(&queue, &BasicIndexingQueue::finishedIndexing, &loop, &QEventLoop::quit); - loop.exec(); - - // kde and kde/1 are not indexed - QCOMPARE(spy.count(), 5); - QCOMPARE(spyStarted.count(), 1); - QCOMPARE(spyFinished.count(), 1); - - QStringList urls; - for (int i = 0; i < spy.count(); i++) { - QVariantList args = spy.at(i); - QCOMPARE(args.size(), 2); - - Xapian::Document doc = args[1].value(); - urls << QString::fromUtf8(doc.get_value(3).c_str()); - } - - QString home = dir->path() + QLatin1String("/home"); - - QStringList expectedUrls; - expectedUrls << home << home + QLatin1String("/1") << home + QLatin1String("/2") << home + QLatin1String("/docs") - << home + QLatin1String("/docs/1"); - - // Based on the locale the default sorting order could be different. - // Plus, we don't care about the order. We just want the same files - // to be indexed - QCOMPARE(expectedUrls.size(), urls.size()); - for (const QString& url : qAsConst(expectedUrls)) { - QVERIFY(urls.count(url) == 1); - } -} - - -void BasicIndexingQueueTest::textExtendedAttributeIndexing() -{ - qRegisterMetaType("Xapian::Document"); - - QStringList dirs; - dirs << QLatin1String("home/"); - dirs << QLatin1String("home/1"); - - QScopedPointer dir(Test::createTmpFilesAndFolders(dirs)); - - QStringList includeFolders; - includeFolders << dir->path() + QLatin1String("/home"); - - QStringList excludeFolders; - Test::writeIndexerConfig(includeFolders, excludeFolders); - - QTemporaryDir dbDir; - Database db; - db.setPath(dbDir.path()); - db.init(); - - FileIndexerConfig config; - BasicIndexingQueue queue(&db, &config); - - // Index the file once - // Write xattr stuff - XattrDetector detector; - if (!detector.isSupported(dbDir.path())) { - qWarning() << "Xattr not supported on this filesystem"; - return; - } - - const QString fileName = dir->path() + QStringLiteral("/home/1"); - QString rat = QString::number(4); - QVERIFY(baloo_setxattr(fileName, QLatin1String("user.baloo.rating"), rat) != -1); - - QStringList tags; - tags << QLatin1String("TagA") << QLatin1String("TagB") << QLatin1String("Tag C") << QLatin1String("Tag/D"); - - QString tagStr = tags.join(QLatin1Char(',')); - QVERIFY(baloo_setxattr(fileName, QLatin1String("user.xdg.tags"), tagStr) != -1); - - const QString userComment(QLatin1String("UserComment")); - QVERIFY(baloo_setxattr(fileName, QLatin1String("user.xdg.comment"), userComment) != -1); - - QSignalSpy spy(&queue, SIGNAL(newDocument(quint64,Xapian::Document))); - - queue.enqueue(FileMapping(fileName), Baloo::ExtendedAttributesOnly); - - QEventLoop loop; - connect(&queue, &BasicIndexingQueue::finishedIndexing, &loop, &QEventLoop::quit); - loop.exec(); - - QCOMPARE(spy.size(), 1); - int id = spy.first().at(0).toInt(); - Xapian::Document doc = spy.first().at(1).value(); - spy.clear(); - - Xapian::TermIterator iter = doc.termlist_begin(); - QCOMPARE(*iter, std::string("Cusercomment")); - ++iter; - QCOMPARE(*iter, std::string("R4")); - ++iter; - QCOMPARE(*iter, std::string("TAG-TagA")); - ++iter; - QCOMPARE(*iter, std::string("TAG-TagB")); - ++iter; - QCOMPARE(*iter, std::string("TAG-Tag C")); - ++iter; - QCOMPARE(*iter, std::string("TAG-Tag/D")); - ++iter; - QCOMPARE(*iter, std::string("TAtaga")); - ++iter; - QCOMPARE(*iter, std::string("TAtagb")); - ++iter; - QCOMPARE(*iter, std::string("TAtag")); - ++iter; - QCOMPARE(*iter, std::string("TAc")); - ++iter; - QCOMPARE(*iter, std::string("TAd")); - ++iter; - QCOMPARE(iter, doc.termlist_end()); - - db.xapianDatabase()->replaceDocument(id, doc); - db.xapianDatabase()->commit(); - - QVERIFY(baloo_setxattr(fileName, QLatin1String("user.xdg.comment"), QStringLiteral("noob")) != -1); - - queue.enqueue(FileMapping(fileName), Baloo::ExtendedAttributesOnly); - loop.exec(); - - { - QCOMPARE(spy.size(), 1); - Xapian::Document doc = spy.first().at(1).value(); - spy.clear(); - - iter = doc.termlist_begin(); - QCOMPARE(*iter, std::string("Cnoob")); - ++iter; - QCOMPARE(*iter, std::string("R4")); - ++iter; - QCOMPARE(*iter, std::string("TAG-TagA")); - ++iter; - QCOMPARE(*iter, std::string("TAG-TagB")); - ++iter; - QCOMPARE(*iter, std::string("TAG-Tag C")); - ++iter; - QCOMPARE(*iter, std::string("TAG-Tag/D")); - ++iter; - QCOMPARE(*iter, std::string("TAtaga")); - ++iter; - QCOMPARE(*iter, std::string("TAtagb")); - ++iter; - QCOMPARE(*iter, std::string("TAtag")); - ++iter; - QCOMPARE(*iter, std::string("TAc")); - ++iter; - QCOMPARE(*iter, std::string("TAd")); - ++iter; - QCOMPARE(iter, doc.termlist_end()); - } -} - -void BasicIndexingQueueTest::textNormalAndThenExtendedAttributeIndexing() -{ - qRegisterMetaType("Xapian::Document"); - - QStringList dirs; - dirs << QLatin1String("home/"); - dirs << QLatin1String("home/1"); - - QScopedPointer dir(Test::createTmpFilesAndFolders(dirs)); - - QStringList includeFolders; - includeFolders << dir->path() + QLatin1String("/home"); - - QStringList excludeFolders; - Test::writeIndexerConfig(includeFolders, excludeFolders); - - QTemporaryDir dbDir; - Database db; - db.setPath(dbDir.path()); - db.init(); - - FileIndexerConfig config; - BasicIndexingQueue queue(&db, &config); - - // Index the file once - // Write xattr stuff - XattrDetector detector; - if (!detector.isSupported(dbDir.path())) { - qWarning() << "Xattr not supported on this filesystem"; - return; - } - - const QString fileName = dir->path() + QStringLiteral("/home/1"); - QString rat = QString::number(4); - QVERIFY(baloo_setxattr(fileName, QLatin1String("user.baloo.rating"), rat) != -1); - - QStringList tags; - tags << QLatin1String("TagA") << QLatin1String("TagB") << QLatin1String("Tag C") << QLatin1String("Tag/D"); - - QString tagStr = tags.join(QLatin1Char(',')); - QVERIFY(baloo_setxattr(fileName, QLatin1String("user.xdg.tags"), tagStr) != -1); - - const QString userComment(QLatin1String("UserComment")); - QVERIFY(baloo_setxattr(fileName, QLatin1String("user.xdg.comment"), userComment) != -1); - - QSignalSpy spy(&queue, SIGNAL(newDocument(quint64,Xapian::Document))); - - queue.enqueue(FileMapping(fileName)); - - QEventLoop loop; - connect(&queue, &BasicIndexingQueue::finishedIndexing, &loop, &QEventLoop::quit); - loop.exec(); - - QCOMPARE(spy.size(), 1); - int id = spy.first().at(0).toInt(); - Xapian::Document doc = spy.first().at(1).value(); - spy.clear(); - - Xapian::TermIterator iter = doc.termlist_begin(); - iter.skip_to("C"); - QCOMPARE(*iter, std::string("Cusercomment")); - iter.skip_to("R"); - QCOMPARE(*iter, std::string("R4")); - ++iter; - QCOMPARE(*iter, std::string("TAG-TagA")); - ++iter; - QCOMPARE(*iter, std::string("TAG-TagB")); - ++iter; - QCOMPARE(*iter, std::string("TAG-Tag C")); - ++iter; - QCOMPARE(*iter, std::string("TAG-Tag/D")); - ++iter; - QCOMPARE(*iter, std::string("TAtaga")); - ++iter; - QCOMPARE(*iter, std::string("TAtagb")); - ++iter; - QCOMPARE(*iter, std::string("TAtag")); - ++iter; - QCOMPARE(*iter, std::string("TAc")); - ++iter; - QCOMPARE(*iter, std::string("TAd")); - - db.xapianDatabase()->replaceDocument(id, doc); - db.xapianDatabase()->commit(); - - QVERIFY(baloo_setxattr(fileName, QLatin1String("user.xdg.comment"), QStringLiteral("noob")) != -1); - - queue.enqueue(FileMapping(fileName), Baloo::ExtendedAttributesOnly); - loop.exec(); - - { - QCOMPARE(spy.size(), 1); - Xapian::Document doc = spy.first().at(1).value(); - spy.clear(); - - iter = doc.termlist_begin(); - QCOMPARE(*iter, std::string("Cnoob")); - ++iter; - QCOMPARE(*iter, std::string("R4")); - ++iter; - QCOMPARE(*iter, std::string("TAG-TagA")); - ++iter; - QCOMPARE(*iter, std::string("TAG-TagB")); - ++iter; - QCOMPARE(*iter, std::string("TAG-Tag C")); - ++iter; - QCOMPARE(*iter, std::string("TAG-Tag/D")); - ++iter; - QCOMPARE(*iter, std::string("TAtaga")); - ++iter; - QCOMPARE(*iter, std::string("TAtagb")); - ++iter; - QCOMPARE(*iter, std::string("TAtag")); - ++iter; - QCOMPARE(*iter, std::string("TAc")); - ++iter; - QCOMPARE(*iter, std::string("TAd")); - ++iter; - QCOMPARE(iter, doc.termlist_end()); - } - -} - -void BasicIndexingQueueTest::testExtendedAttributeIndexingWhenEmpty() -{ - qRegisterMetaType("Xapian::Document"); - - QStringList dirs; - dirs << QLatin1String("home/"); - dirs << QLatin1String("home/1"); - - QScopedPointer dir(Test::createTmpFilesAndFolders(dirs)); - - QStringList includeFolders; - includeFolders << dir->path() + QLatin1String("/home"); - - QStringList excludeFolders; - Test::writeIndexerConfig(includeFolders, excludeFolders); - - QTemporaryDir dbDir; - Database db; - db.setPath(dbDir.path()); - db.init(); - - FileIndexerConfig config; - BasicIndexingQueue queue(&db, &config); - - const QString fileName = dir->path() + QStringLiteral("/home/1"); - - QSignalSpy spy(&queue, SIGNAL(newDocument(quint64,Xapian::Document))); - queue.enqueue(FileMapping(fileName), Baloo::ExtendedAttributesOnly); - - QEventLoop loop; - connect(&queue, &BasicIndexingQueue::finishedIndexing, &loop, &QEventLoop::quit); - loop.exec(); - - QCOMPARE(spy.size(), 0); -} - -void BasicIndexingQueueTest::testFileModifications() -{ - qRegisterMetaType("Xapian::Document"); - - QStringList dirs; - dirs << QLatin1String("home/"); - dirs << QLatin1String("home/1"); - - QScopedPointer dir(Test::createTmpFilesAndFolders(dirs)); - - QStringList includeFolders; - includeFolders << dir->path() + QLatin1String("/home"); - - QStringList excludeFolders; - Test::writeIndexerConfig(includeFolders, excludeFolders); - - QTemporaryDir dbDir; - Database db; - db.setPath(dbDir.path()); - db.init(); - - FileIndexerConfig config; - BasicIndexingQueue queue(&db, &config); - - const QString fileName = dir->path() + QStringLiteral("/home/1"); - - QSignalSpy spy(&queue, SIGNAL(newDocument(quint64,Xapian::Document))); - queue.enqueue(FileMapping(fileName), Baloo::AutoUpdateFolder); - - QEventLoop loop; - connect(&queue, &BasicIndexingQueue::finishedIndexing, &loop, &QEventLoop::quit); - loop.exec(); - - QCOMPARE(spy.size(), 1); - spy.takeFirst(); - - // Again - queue.enqueue(FileMapping(fileName), Baloo::AutoUpdateFolder); - loop.exec(); - - QCOMPARE(spy.size(), 1); -} - - -QTEST_MAIN(BasicIndexingQueueTest) - -#include "basicindexingqueuetest.moc" diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/unit/file/CMakeLists.txt baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/unit/file/CMakeLists.txt --- baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/unit/file/CMakeLists.txt 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/unit/file/CMakeLists.txt 2020-05-10 14:18:38.000000000 +0000 @@ -5,16 +5,6 @@ ) endif() -set (metadatamovertest_SOURCES - metadatamovertest.cpp -) - -qt5_add_dbus_adaptor(metadatamovertest_SOURCES - ${CMAKE_SOURCE_DIR}/src/file/org.kde.BalooWatcherApplication.xml - metadatamovertest.h MetadataMoverTestDBusSpy) - -ecm_add_test(${metadatamovertest_SOURCES} TEST_NAME metadatamovertest LINK_LIBRARIES Qt5::Test baloofilecommon KF5::Baloo) - MACRO(BALOO_FILE_AUTO_TESTS) FOREACH(_testname ${ARGN}) ecm_add_test(${_testname}.cpp TEST_NAME ${_testname} LINK_LIBRARIES Qt5::Test baloofilecommon KF5::Baloo) @@ -28,6 +18,7 @@ regularexpcachebenchmark filtereddiriteratortest unindexedfileiteratortest + metadatamovertest fileinfotest ) @@ -35,10 +26,10 @@ # # File Watch # -set(fileWatch_SRC filewatchtest.cpp ../lib/xattrdetector.cpp) +set(fileWatch_SRC filewatchtest.cpp) ecm_add_test(${fileWatch_SRC} TEST_NAME "filewatchtest" - LINK_LIBRARIES Qt5::Test Qt5::DBus KF5::Baloo baloofilecommon + LINK_LIBRARIES Qt5::Test Qt5::DBus KF5::Baloo KF5::FileMetaData baloofilecommon ) # diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/unit/file/filewatchtest.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/unit/file/filewatchtest.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/unit/file/filewatchtest.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/unit/file/filewatchtest.cpp 2020-05-10 14:18:38.000000000 +0000 @@ -23,13 +23,11 @@ #include "database.h" #include "fileindexerconfig.h" #include "pendingfilequeue.h" -#include "mainhub.h" -#include "../lib/xattrdetector.h" -#include "../lib/baloo_xattr_p.h" #include #include #include +#include namespace Baloo { @@ -38,37 +36,8 @@ Q_OBJECT private Q_SLOTS: - void init() - { - m_tempDir = new QTemporaryDir(); - m_db = new Database(m_tempDir->path()); - m_db->open(Database::CreateDatabase); - m_dbusInterface = new MainHub(m_db, &m_config, false); - } - void testFileCreation(); - - void cleanupTestCase() - { - delete m_dbusInterface; - m_dbusInterface = nullptr; - - delete m_db; - m_db = nullptr; - - delete m_tempDir; - m_tempDir = nullptr; - } - -private: - - FileIndexerConfig m_config; - - Database* m_db; - - QTemporaryDir* m_tempDir; - - Baloo::MainHub *m_dbusInterface; + void testConfigChange(); }; } @@ -108,7 +77,7 @@ FileIndexerConfig config; - FileWatch fileWatch(&db, &config, m_dbusInterface); + FileWatch fileWatch(&db, &config); fileWatch.m_pendingFileQueue->setMaximumTimeout(0); fileWatch.m_pendingFileQueue->setMinimumTimeout(0); fileWatch.m_pendingFileQueue->setTrackingTime(0); @@ -116,7 +85,7 @@ QSignalSpy spy(&fileWatch, SIGNAL(installedWatches())); QVERIFY(spy.isValid()); - fileWatch.watchIndexedFolders(); + fileWatch.updateIndexedFoldersWatches(); QVERIFY(spy.count() || spy.wait()); QSignalSpy spyIndexNew(&fileWatch, SIGNAL(indexNewFile(QString))); @@ -157,14 +126,14 @@ // // Set an Xattr // - XattrDetector detector; - if (!detector.isSupported(dbDir.path())) { - qWarning() << "Xattr not supported on this filesystem"; + KFileMetaData::UserMetaData umd(fileUrl); + if (!umd.isSupported()) { + qWarning() << "Xattr not supported on this filesystem:" << fileUrl; return; } const QString userComment(QStringLiteral("UserComment")); - QVERIFY(baloo_setxattr(fileUrl, QLatin1String("user.xdg.comment"), userComment) != -1); + QVERIFY(umd.setUserComment(userComment) == KFileMetaData::UserMetaData::NoError); QVERIFY(spyIndexXattr.wait()); QCOMPARE(spyIndexNew.count(), 0); @@ -176,6 +145,87 @@ spyIndexXattr.clear(); } +void FileWatchTest::testConfigChange() +{ + QTemporaryDir tmpDir; + + Database db(tmpDir.path()); + db.open(Baloo::Database::CreateDatabase); + + QString d1 = tmpDir.path() + QStringLiteral("/d1"); + QString d2 = tmpDir.path() + QStringLiteral("/d2"); + QString d11 = tmpDir.path() + QStringLiteral("/d1/d11"); + QString d21 = tmpDir.path() + QStringLiteral("/d2/d21"); + QString d22 = tmpDir.path() + QStringLiteral("/d2/d22"); + + QDir().mkpath(d11); + QDir().mkpath(d21); + QDir().mkpath(d22); + + // parameters: includeFolders list, excludeFolders list + Test::writeIndexerConfig({d1, d2}, {d11, d21}); + FileIndexerConfig config; + + FileWatch fileWatch(&db, &config); + fileWatch.m_pendingFileQueue->setMaximumTimeout(0); + fileWatch.m_pendingFileQueue->setMinimumTimeout(0); + fileWatch.m_pendingFileQueue->setTrackingTime(0); + + QSignalSpy spy(&fileWatch, SIGNAL(installedWatches())); + QVERIFY(spy.isValid()); + + fileWatch.updateIndexedFoldersWatches(); + QVERIFY(spy.count() || spy.wait()); + + QSignalSpy spyIndexNew(&fileWatch, SIGNAL(indexNewFile(QString))); + QVERIFY(spyIndexNew.isValid()); + QVERIFY(createFile(d1 + "/t1")); + QVERIFY(createFile(d2 + "/t2")); + + QVERIFY(spyIndexNew.wait()); + QCOMPARE(spyIndexNew.count(), 2); + spyIndexNew.clear(); + + // dir d22 is not yet excluded, so one event is expected + QVERIFY(createFile(d11 + "/tx1")); + QVERIFY(createFile(d21 + "/tx2")); + QVERIFY(createFile(d22 + "/tx3")); + + QVERIFY(spyIndexNew.wait()); + QCOMPARE(spyIndexNew.count(), 1); + QList event = spyIndexNew.at(0); + QCOMPARE(event.at(0).toString(), d22 + "/tx3"); + spyIndexNew.clear(); + + Test::writeIndexerConfig({d2}, {d22}); + config.forceConfigUpdate(); + fileWatch.updateIndexedFoldersWatches(); + + // dir d1 is no longer included + QVERIFY(createFile(d1 + "/tx1a")); + QVERIFY(createFile(d2 + "/tx2a")); + QVERIFY(spyIndexNew.wait()); + QList result; + for (const QList& event : qAsConst(spyIndexNew)) { + result.append(event.at(0).toString()); + } + QCOMPARE(result, {d2 + "/tx2a"}); + spyIndexNew.clear(); + result.clear(); + + // d11 is implicitly excluded, as d1 is no longer included + // d22 is explicitly excluded now, d21 is included + QVERIFY(createFile(d11 + "/tx1b")); + QVERIFY(createFile(d21 + "/tx2b")); + QVERIFY(createFile(d22 + "/tx3b")); + + QVERIFY(spyIndexNew.wait(500)); + for (const QList& event : qAsConst(spyIndexNew)) { + result.append(event.at(0).toString()); + } + QCOMPARE(result, {d21 + "/tx2b"}); +} + QTEST_MAIN(FileWatchTest) #include "filewatchtest.moc" diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/unit/file/kinotifytest.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/unit/file/kinotifytest.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/unit/file/kinotifytest.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/unit/file/kinotifytest.cpp 2020-05-10 14:18:38.000000000 +0000 @@ -90,7 +90,7 @@ { // create some test files QTemporaryDir dir; - const QString d1(QStringLiteral("%1/randomJunk4").arg(dir.path())); + const QString d1(QStringLiteral("%1/randomJunk4/").arg(dir.path())); mkdir(d1); // start the inotify watcher @@ -123,7 +123,7 @@ QSignalSpy createdSpy(&kn, SIGNAL(created(QString,bool))); // create the subdir - const QString d1(QStringLiteral("%1/randomJunk1").arg(dir.path())); + const QString d1(QStringLiteral("%1/randomJunk1/").arg(dir.path())); mkdir(d1); QVERIFY(createdSpy.wait()); QCOMPARE(createdSpy.count(), 1); @@ -131,7 +131,7 @@ QVERIFY(kn.watchingPath(d1)); // lets go one level deeper - const QString d2 = QStringLiteral("%1/subdir1").arg(d1); + const QString d2 = QStringLiteral("%1subdir1/").arg(d1); mkdir(d2); QVERIFY(createdSpy.wait()); QCOMPARE(createdSpy.count(), 1); @@ -139,7 +139,7 @@ QVERIFY(kn.watchingPath(d2)); // although we are in the folder test lets try creating a file - const QString f1 = QStringLiteral("%1/somefile1").arg(d2); + const QString f1 = QStringLiteral("%1somefile1").arg(d2); touchFile(f1); QVERIFY(createdSpy.wait()); QCOMPARE(createdSpy.count(), 1); @@ -229,8 +229,8 @@ { // create some test files QTemporaryDir dir; - const QString f1(QStringLiteral("%1/randomJunk1").arg(dir.path())); - mkdir(f1); + const QString d1(QStringLiteral("%1/randomJunk1/").arg(dir.path())); + mkdir(d1); // start the inotify watcher KInotify kn(nullptr /*no config*/); @@ -239,42 +239,42 @@ // listen to the desired signal QSignalSpy spy(&kn, SIGNAL(moved(QString,QString))); - // actually move the file - const QString f2(QStringLiteral("%1/randomJunk2").arg(dir.path())); - QFile::rename(f1, f2); + // actually rename the folder + const QString d2(QStringLiteral("%1/randomJunk2/").arg(dir.path())); + QFile::rename(d1, d2); // check the desired signal QVERIFY(spy.wait()); QCOMPARE(spy.count(), 1); QList args = spy.takeFirst(); - QCOMPARE(args.at(0).toString(), f1); - QCOMPARE(args.at(1).toString(), f2); + QCOMPARE(args.at(0).toString(), d1); + QCOMPARE(args.at(1).toString(), d2); // check the path cache - QVERIFY(!kn.watchingPath(f1)); - QVERIFY(kn.watchingPath(f2)); + QVERIFY(!kn.watchingPath(d1)); + QVERIFY(kn.watchingPath(d2)); // test a subsequent rename - const QString f3(QStringLiteral("%1/randomJunk3").arg(dir.path())); - QFile::rename(f2, f3); + const QString d3(QStringLiteral("%1/randomJunk3/").arg(dir.path())); + QFile::rename(d2, d3); // check the desired signal QVERIFY(spy.wait()); QCOMPARE(spy.count(), 1); args = spy.takeFirst(); - QCOMPARE(args.at(0).toString(), f2); - QCOMPARE(args.at(1).toString(), f3); + QCOMPARE(args.at(0).toString(), d2); + QCOMPARE(args.at(1).toString(), d3); // check the path cache - QVERIFY(!kn.watchingPath(f1)); - QVERIFY(!kn.watchingPath(f2)); - QVERIFY(kn.watchingPath(f3)); + QVERIFY(!kn.watchingPath(d1)); + QVERIFY(!kn.watchingPath(d2)); + QVERIFY(kn.watchingPath(d3)); // KInotify claims it has updated its data structures, lets see if that is true // by creating a file in the new folder // listen to the desired signal - const QString f4(QStringLiteral("%1/somefile").arg(f3)); + const QString f4(QStringLiteral("%1somefile").arg(d3)); QSignalSpy createdSpy(&kn, SIGNAL(created(QString,bool))); @@ -292,8 +292,8 @@ // create some test files QTemporaryDir dir1; QTemporaryDir dir2; - const QString src(QStringLiteral("%1/randomJunk1").arg(dir1.path())); - const QString dest(QStringLiteral("%1/randomJunk2").arg(dir2.path())); + const QString src(QStringLiteral("%1/randomJunk1/").arg(dir1.path())); + const QString dest(QStringLiteral("%1/randomJunk2/").arg(dir2.path())); mkdir(src); // start the inotify watcher @@ -319,7 +319,7 @@ QVERIFY(kn.watchingPath(dest)); // test a subsequent move - const QString dest2(QStringLiteral("%1/randomJunk3").arg(dir1.path())); + const QString dest2(QStringLiteral("%1/randomJunk3/").arg(dir1.path())); QFile::rename(dest, dest2); // check the desired signal @@ -338,7 +338,7 @@ // KInotify claims it has updated its data structures, lets see if that is true // by creating a file in the new folder // listen to the desired signal - const QString f4(QStringLiteral("%1/somefile").arg(dest2)); + const QString f4(QStringLiteral("%1somefile").arg(dest2)); QSignalSpy createdSpy(&kn, SIGNAL(created(QString,bool))); diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/unit/file/metadatamovertest.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/unit/file/metadatamovertest.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/unit/file/metadatamovertest.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/unit/file/metadatamovertest.cpp 2020-05-10 14:18:38.000000000 +0000 @@ -18,22 +18,18 @@ * */ -#include "metadatamovertest.h" #include "metadatamover.h" -#include "baloowatcherapplicationadaptor.h" #include "database.h" #include "transaction.h" #include "document.h" #include "basicindexingjob.h" -#include "mainhub.h" #include #include #include #include #include -#include using namespace Baloo; @@ -56,10 +52,7 @@ private: quint64 insertUrl(const QString& url); - FileIndexerConfig m_config; - Database* m_db; - QTemporaryDir* m_tempDir; }; @@ -99,10 +92,6 @@ void MetadataMoverTest::testRemoveFile() { - MetadataMoverTestDBusSpy dbusSignalSpy; - QSignalSpy renamedFilesSignalSpy(&dbusSignalSpy, &MetadataMoverTestDBusSpy::renamedFilesSignal); - QSignalSpy fileChangedSpy(&dbusSignalSpy, &MetadataMoverTestDBusSpy::fileMetaDataChanged); - QTemporaryFile file; file.open(); QString url = file.fileName(); @@ -113,25 +102,10 @@ QVERIFY(tr.hasDocument(fid)); } - renamedFilesSignalSpy.wait(100); - fileChangedSpy.wait(100); - - QCOMPARE(renamedFilesSignalSpy.count(), 0); - QCOMPARE(fileChangedSpy.count(), 0); - MetadataMover mover(m_db, this); - - mover.registerBalooWatcher(QStringLiteral("org.kde.baloo.metadatamovertest/org/kde/BalooWatcherApplication")); - file.remove(); mover.removeFileMetadata(url); - renamedFilesSignalSpy.wait(100); - fileChangedSpy.wait(100); - - QCOMPARE(renamedFilesSignalSpy.count(), 0); - QCOMPARE(fileChangedSpy.count(), 0); - { Transaction tr(m_db, Transaction::ReadOnly); QVERIFY(!tr.hasDocument(fid)); @@ -153,10 +127,6 @@ void MetadataMoverTest::testRenameFile() { - MetadataMoverTestDBusSpy dbusSignalSpy; - QSignalSpy renamedFilesSignalSpy(&dbusSignalSpy, &MetadataMoverTestDBusSpy::renamedFilesSignal); - QSignalSpy fileChangedSpy(&dbusSignalSpy, &MetadataMoverTestDBusSpy::fileMetaDataChanged); - QTemporaryDir dir; QString url = dir.path() + "/file"; @@ -168,26 +138,11 @@ QVERIFY(tr.hasDocument(fid)); } - renamedFilesSignalSpy.wait(100); - fileChangedSpy.wait(100); - - QCOMPARE(renamedFilesSignalSpy.count(), 0); - QCOMPARE(fileChangedSpy.count(), 0); - MetadataMover mover(m_db, this); - - mover.registerBalooWatcher(QStringLiteral("org.kde.baloo.metadatamovertest/org/kde/BalooWatcherApplication")); - QString url2 = dir.path() + "/file2"; QFile::rename(url, url2); mover.moveFileMetadata(QFile::encodeName(url), QFile::encodeName(url2)); - renamedFilesSignalSpy.wait(100); - fileChangedSpy.wait(100); - - QCOMPARE(renamedFilesSignalSpy.count(), 1); - QCOMPARE(fileChangedSpy.count(), 0); - { Transaction tr(m_db, Transaction::ReadOnly); QVERIFY(tr.hasDocument(fid)); @@ -197,10 +152,6 @@ void MetadataMoverTest::testMoveFile() { - MetadataMoverTestDBusSpy dbusSignalSpy; - QSignalSpy renamedFilesSignalSpy(&dbusSignalSpy, &MetadataMoverTestDBusSpy::renamedFilesSignal); - QSignalSpy fileChangedSpy(&dbusSignalSpy, &MetadataMoverTestDBusSpy::fileMetaDataChanged); - QTemporaryDir dir; QDir().mkpath(dir.path() + "/a/b/c"); @@ -213,26 +164,11 @@ QVERIFY(tr.hasDocument(fid)); } - renamedFilesSignalSpy.wait(100); - fileChangedSpy.wait(100); - - QCOMPARE(renamedFilesSignalSpy.count(), 0); - QCOMPARE(fileChangedSpy.count(), 0); - MetadataMover mover(m_db, this); - - mover.registerBalooWatcher(QStringLiteral("org.kde.baloo.metadatamovertest/org/kde/BalooWatcherApplication")); - QString url2 = dir.path() + "/file2"; QFile::rename(url, url2); mover.moveFileMetadata(QFile::encodeName(url), QFile::encodeName(url2)); - renamedFilesSignalSpy.wait(100); - fileChangedSpy.wait(100); - - QCOMPARE(renamedFilesSignalSpy.count(), 1); - QCOMPARE(fileChangedSpy.count(), 0); - { Transaction tr(m_db, Transaction::ReadOnly); QVERIFY(tr.hasDocument(fid)); @@ -242,10 +178,6 @@ void MetadataMoverTest::testMoveFolder() { - MetadataMoverTestDBusSpy dbusSignalSpy; - QSignalSpy renamedFilesSignalSpy(&dbusSignalSpy, &MetadataMoverTestDBusSpy::renamedFilesSignal); - QSignalSpy fileChangedSpy(&dbusSignalSpy, &MetadataMoverTestDBusSpy::fileMetaDataChanged); - QTemporaryDir dir; QString folder = dir.path() + "/folder"; @@ -262,26 +194,11 @@ QVERIFY(tr.hasDocument(fid)); } - renamedFilesSignalSpy.wait(100); - fileChangedSpy.wait(100); - - QCOMPARE(renamedFilesSignalSpy.count(), 0); - QCOMPARE(fileChangedSpy.count(), 0); - QString newFolderUrl = dir.path() + "/dir"; QFile::rename(folder, newFolderUrl); MetadataMover mover(m_db, this); - - mover.registerBalooWatcher(QStringLiteral("org.kde.baloo.metadatamovertest/org/kde/BalooWatcherApplication")); - mover.moveFileMetadata(QFile::encodeName(folder), QFile::encodeName(newFolderUrl)); - renamedFilesSignalSpy.wait(100); - fileChangedSpy.wait(100); - - QCOMPARE(renamedFilesSignalSpy.count(), 1); - QCOMPARE(fileChangedSpy.count(), 0); - { Transaction tr(m_db, Transaction::ReadOnly); QVERIFY(tr.hasDocument(did)); @@ -291,32 +208,6 @@ } } - - -MetadataMoverTestDBusSpy::MetadataMoverTestDBusSpy(QObject *parent) : QObject(parent) -{ - QDBusConnection con = QDBusConnection::sessionBus(); - - con.connect(QString(), QStringLiteral("/files"), QStringLiteral("org.kde"), - QStringLiteral("changed"), this, SLOT(slotFileMetaDataChanged(QStringList))); - - - auto mDbusAdaptor = new BalooWatcherApplicationAdaptor(this); - - QCOMPARE(con.registerService(QStringLiteral("org.kde.baloo.metadatamovertest")), true); - QCOMPARE(con.registerObject(QStringLiteral("/org/kde/BalooWatcherApplication"), mDbusAdaptor, QDBusConnection::ExportAllContents), true); -} - -void MetadataMoverTestDBusSpy::slotFileMetaDataChanged(QStringList fileList) -{ - Q_EMIT fileMetaDataChanged(fileList); -} - -void MetadataMoverTestDBusSpy::renamedFiles(const QString &from, const QString &to, const QStringList &listFiles) -{ - Q_EMIT renamedFilesSignal(from, to, listFiles); -} - QTEST_GUILESS_MAIN(MetadataMoverTest) #include "metadatamovertest.moc" diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/unit/file/metadatamovertest.h baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/unit/file/metadatamovertest.h --- baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/unit/file/metadatamovertest.h 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/unit/file/metadatamovertest.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,49 +0,0 @@ -/* - * This file is part of the KDE Baloo Project - * Copyright (C) 2017 Matthieu Gallien - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#if !defined METADATAMOVERTEST_H_ -#define METADATAMOVERTEST_H_ - -#include -#include -#include - -class MetadataMoverTestDBusSpy : public QObject -{ - Q_OBJECT -public: - - MetadataMoverTestDBusSpy(QObject* parent = nullptr); - -Q_SIGNALS: - - void fileMetaDataChanged(QStringList fileList); - - void renamedFilesSignal(const QString &from, const QString &to, const QStringList &listFiles); - -public Q_SLOTS: - - void slotFileMetaDataChanged(QStringList fileList); - - void renamedFiles(const QString &from, const QString &to, const QStringList &listFiles); - -}; - -#endif diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/unit/lib/baloo_xattr_p.h baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/unit/lib/baloo_xattr_p.h --- baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/unit/lib/baloo_xattr_p.h 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/unit/lib/baloo_xattr_p.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,127 +0,0 @@ -/* - * This file is part of the KDE Baloo Project - * Copyright (C) 2014 Raphael Kubo da Costa - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef BALOO_XATTR_P_H -#define BALOO_XATTR_P_H - -#include -#include -#include - -#if defined(Q_OS_LINUX) || defined(__GLIBC__) -#include -#include -#elif defined(Q_OS_MAC) -#include -#include -#elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) -#include -#include -#endif - -inline ssize_t baloo_getxattr(const QString& path, const QString& name, QString* value) -{ - const QByteArray p = QFile::encodeName(path); - const char* encodedPath = p.constData(); - - const QByteArray n = name.toUtf8(); - const char* attributeName = n.constData(); - - // First get the size of the data we are going to get to reserve the right amount of space. -#if defined(Q_OS_LINUX) || (defined(__GLIBC__) && !defined(__stub_getxattr)) - const ssize_t size = getxattr(encodedPath, attributeName, nullptr, 0); -#elif defined(Q_OS_MAC) - const ssize_t size = getxattr(encodedPath, attributeName, NULL, 0, 0, 0); -#elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) - const ssize_t size = extattr_get_file(encodedPath, EXTATTR_NAMESPACE_USER, attributeName, NULL, 0); -#else - const ssize_t size = 0; -#endif - - if (size <= 0) { - if (value) { - value->clear(); - } - return size; - } - - QByteArray data(size, Qt::Uninitialized); - -#if defined(Q_OS_LINUX) || (defined(__GLIBC__) && !defined(__stub_getxattr)) - const ssize_t r = getxattr(encodedPath, attributeName, data.data(), size); -#elif defined(Q_OS_MAC) - const ssize_t r = getxattr(encodedPath, attributeName, data.data(), size, 0, 0); -#elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) - const ssize_t r = extattr_get_file(encodedPath, EXTATTR_NAMESPACE_USER, attributeName, data.data(), size); -#else - const ssize_t r = 0; -#endif - - *value = QString::fromUtf8(data); - return r; -} - -inline int baloo_setxattr(const QString& path, const QString& name, const QString& value) -{ - const QByteArray p = QFile::encodeName(path); - const char* encodedPath = p.constData(); - - const QByteArray n = name.toUtf8(); - const char* attributeName = n.constData(); - - const QByteArray v = value.toUtf8(); - const void* attributeValue = v.constData(); - - const size_t valueSize = v.size(); - -#if defined(Q_OS_LINUX) || (defined(__GLIBC__) && !defined(__stub_setxattr)) - return setxattr(encodedPath, attributeName, attributeValue, valueSize, 0); -#elif defined(Q_OS_MAC) - return setxattr(encodedPath, attributeName, attributeValue, valueSize, 0, 0); -#elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) - const ssize_t count = extattr_set_file(encodedPath, EXTATTR_NAMESPACE_USER, attributeName, attributeValue, valueSize); - return count == -1 ? -1 : 0; -#else - return -1; -#endif -} - - -inline int baloo_removexattr(const QString& path, const QString& name) -{ - const QByteArray p = QFile::encodeName(path); - const char* encodedPath = p.constData(); - - const QByteArray n = name.toUtf8(); - const char* attributeName = n.constData(); - - #if defined(Q_OS_LINUX) || (defined(__GLIBC__) && !defined(__stub_removexattr)) - return removexattr(encodedPath, attributeName); - #elif defined(Q_OS_MAC) - return removexattr(encodedPath, attributeName, XATTR_NOFOLLOW ); - #elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) - return extattr_delete_file (encodedPath, EXTATTR_NAMESPACE_USER, attributeName); - #else - return -1; - #endif - -} - -#endif // BALOO_XATTR_P_H diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/unit/lib/xattrdetector.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/unit/lib/xattrdetector.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/unit/lib/xattrdetector.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/unit/lib/xattrdetector.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,121 +0,0 @@ -/* - * This file is part of the KDE Baloo Project - * Copyright (C) 2014 Vishesh Handa - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include "xattrdetector.h" -#include "baloo_xattr_p.h" - -#include -#include -#include -#include -#include -#include - -using namespace Baloo; - -class XattrDetector::Private { -public: - QStringList m_unSupportedPaths; - QStringList m_supportedPaths; - - void init(); - bool m_initialized; -}; - -XattrDetector::XattrDetector(QObject* parent) - : QObject(parent) - , d(new Private) -{ - d->m_initialized = false; -} - -void XattrDetector::Private::init() -{ - const QList devices - = Solid::Device::listFromType(Solid::DeviceInterface::StorageAccess); - - QStringList mountPaths; - for (const Solid::Device& dev : devices) { - const Solid::StorageAccess* sa = dev.as(); - if (!sa->isAccessible()) - continue; - - mountPaths << sa->filePath(); - } - mountPaths << QDir::homePath(); - - for (const QString& mountPath : qAsConst(mountPaths)) { - while (1) { - QString randFile = QLatin1String("baloo-xattr-check-") + QUuid::createUuid().toString(); - const QString url = mountPath + QDir::separator() + randFile; - if (QFile::exists(url)) - continue; - - QFile file(url); - if (!file.open(QIODevice::WriteOnly)) { - m_unSupportedPaths << mountPath; - break; - } - file.close(); - - int ret = baloo_setxattr(url, QStringLiteral("test"), QStringLiteral("0")); - if (ret != -1) { - // Check the actual error? - m_unSupportedPaths << mountPath; - } - else { - m_supportedPaths << mountPath; - } - - QFile::remove(url); - break; - } - } - m_unSupportedPaths << QStringLiteral("/tmp") << QStringLiteral("/proc"); - qDebug() << "supportedPaths:" << m_supportedPaths; - qDebug() << "UnsupportedPaths:" << m_unSupportedPaths; - m_initialized = true; -} - -XattrDetector::~XattrDetector() -{ - delete d; -} - -bool XattrDetector::isSupported(const QString& path) -{ -#ifdef Q_OS_WIN - return false; -#endif - if (!d->m_initialized) - d->init(); - - for (const QString& p : qAsConst(d->m_supportedPaths)) { - if (path.startsWith(p)) - return true; - } - - for (const QString& p : qAsConst(d->m_unSupportedPaths)) { - if (path.startsWith(p)) - return false; - } - - return true; -} diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/unit/lib/xattrdetector.h baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/unit/lib/xattrdetector.h --- baloo-kf5-5.69.0+p20.04+git20200418.1103/autotests/unit/lib/xattrdetector.h 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/autotests/unit/lib/xattrdetector.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,57 +0,0 @@ -/* - * This file is part of the KDE Baloo Project - * Copyright (C) 2014 Vishesh Handa - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef BALOO_XATTRDETECTOR_H -#define BALOO_XATTRDETECTOR_H - -#include - -namespace Baloo { - -/** - * \class XattrDetector xattrdetector.h - * - * \brief This class is used to detect if a file supports the adding of - * extended attributes to given a file path. - * - * The creation of this object is expensive, so avoid it as much as possible - * - * \author Vishesh Handa - */ -class XattrDetector : public QObject -{ -public: - explicit XattrDetector(QObject* parent = nullptr); - ~XattrDetector() override; - - /** - * Checks if the give local url \p path supports - * saving of extended attributes in file system - */ - bool isSupported(const QString& path); - -private: - class Private; - Private* d; -}; - -} - -#endif // BALOO_XATTRDETECTOR_H diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/CMakeLists.txt baloo-kf5-5.70.0+p20.04+git20200510.1418/CMakeLists.txt --- baloo-kf5-5.69.0+p20.04+git20200418.1103/CMakeLists.txt 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/CMakeLists.txt 2020-05-10 14:18:38.000000000 +0000 @@ -1,8 +1,8 @@ # set minimum version requirements cmake_minimum_required(VERSION 3.5) set(REQUIRED_QT_VERSION 5.12.0) -set(KF5_VERSION "5.70.0") # handled by release scripts -set(KF5_DEP_VERSION "5.69.0") # handled by release scripts +set(KF5_VERSION "5.71.0") # handled by release scripts +set(KF5_DEP_VERSION "5.70.0") # handled by release scripts # set up project project(Baloo VERSION ${KF5_VERSION}) diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/debian/changelog baloo-kf5-5.70.0+p20.04+git20200510.1418/debian/changelog --- baloo-kf5-5.69.0+p20.04+git20200418.1103/debian/changelog 2020-04-18 11:03:48.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/debian/changelog 2020-05-10 14:18:39.000000000 +0000 @@ -1,13 +1,19 @@ -baloo-kf5 (5.69.0+p20.04+git20200418.1103-0) focal; urgency=high +baloo-kf5 (5.70.0+p20.04+git20200510.1418-0) focal; urgency=high + + * Automatic Ubuntu CI Build + + -- Kubuntu CI Sun, 10 May 2020 14:18:39 +0000 + +baloo-kf5 (5.70.0-0ubuntu1) groovy; urgency=medium [ José Manuel Santamaría Lema ] * New upstream release (5.69.0) * Refreshed patch fix-822499.patch - [ Kubuntu CI ] - * Automatic Ubuntu CI Build + [ Rik Mills ] + * New upstream release (5.70.0) - -- Kubuntu CI Sat, 18 Apr 2020 11:03:48 +0000 + -- Rik Mills Sat, 09 May 2020 12:29:25 +0100 baloo-kf5 (5.68.0-0ubuntu1) focal; urgency=medium diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/debian/control baloo-kf5-5.70.0+p20.04+git20200510.1418/debian/control --- baloo-kf5-5.69.0+p20.04+git20200418.1103/debian/control 2020-04-18 11:03:48.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/debian/control 2020-05-10 14:18:39.000000000 +0000 @@ -6,18 +6,18 @@ Build-Depends: cmake (>= 3.0~), debhelper (>= 11~), doxygen, - extra-cmake-modules (>= 5.69.0~), + extra-cmake-modules (>= 5.70.0~), graphviz, - libkf5auth-dev (>= 5.69.0~), - libkf5config-dev (>= 5.69.0~), - libkf5coreaddons-dev (>= 5.69.0~), - libkf5crash-dev (>= 5.69.0~), - libkf5dbusaddons-dev (>= 5.69.0~), - libkf5filemetadata-dev (>= 5.69.0~), - libkf5i18n-dev (>= 5.69.0~), - libkf5idletime-dev (>= 5.69.0~), - libkf5kio-dev (>= 5.69.0~), - libkf5solid-dev (>= 5.69.0~), + libkf5auth-dev (>= 5.70.0~), + libkf5config-dev (>= 5.70.0~), + libkf5coreaddons-dev (>= 5.70.0~), + libkf5crash-dev (>= 5.70.0~), + libkf5dbusaddons-dev (>= 5.70.0~), + libkf5filemetadata-dev (>= 5.70.0~), + libkf5i18n-dev (>= 5.70.0~), + libkf5idletime-dev (>= 5.70.0~), + libkf5kio-dev (>= 5.70.0~), + libkf5solid-dev (>= 5.70.0~), liblmdb-dev, libqt5sql5-sqlite, libxapian-dev, @@ -48,8 +48,8 @@ Depends: baloo-kf5 (= ${binary:Version}), libkf5baloo5 (= ${binary:Version}), libkf5balooengine5 (= ${binary:Version}), - libkf5coreaddons-dev (>= 5.69.0~), - libkf5filemetadata-dev (>= 5.69.0~), + libkf5coreaddons-dev (>= 5.70.0~), + libkf5filemetadata-dev (>= 5.70.0~), ${misc:Depends}, ${shlibs:Depends}, Recommends: libkf5baloo-doc (= ${source:Version}) diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/codecs/coding.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/src/codecs/coding.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/codecs/coding.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/codecs/coding.cpp 2020-05-10 14:18:38.000000000 +0000 @@ -112,17 +112,21 @@ { quint32 size = 0; p = getVarint32Ptr(p, limit, &size); - values->reserve(size); + values->resize(size); + + auto it = values->begin(); + auto end = values->end(); quint32 v = 0; - while (p && size) { + while (p && it != end) { quint32 n = 0; p = getVarint32Ptr(p, limit, &n); - values->append(n + v); + *it = (n + v); v += n; - size--; + ++it; } + values->erase(it, end); return p; } diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/engine/termgenerator.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/src/engine/termgenerator.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/engine/termgenerator.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/engine/termgenerator.cpp 2020-05-10 14:18:38.000000000 +0000 @@ -98,8 +98,9 @@ m_position++; } -void TermGenerator::indexFileNameText(const QString& text, const QByteArray& prefix) +void TermGenerator::indexFileNameText(const QString& text) { + const QByteArray prefix = QByteArrayLiteral("F"); const QByteArrayList terms = termList(text); if (terms.size() == 1) { QByteArray finalArr = prefix + terms[0]; @@ -115,11 +116,6 @@ m_position++; } -void TermGenerator::indexFileNameText(const QString& text) -{ - indexFileNameText(text, QByteArray()); -} - void TermGenerator::indexXattrText(const QString& text, const QByteArray& prefix) { const QByteArrayList terms = termList(text); diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/engine/termgenerator.h baloo-kf5-5.70.0+p20.04+git20200510.1418/src/engine/termgenerator.h --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/engine/termgenerator.h 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/engine/termgenerator.h 2020-05-10 14:18:38.000000000 +0000 @@ -42,7 +42,6 @@ void indexXattrText(const QString& text, const QByteArray& prefix); void indexFileNameText(const QString& text); - void indexFileNameText(const QString& text, const QByteArray& prefix); void setPosition(int position); int position() const; diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/engine/transaction.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/src/engine/transaction.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/engine/transaction.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/engine/transaction.cpp 2020-05-10 14:18:38.000000000 +0000 @@ -141,13 +141,6 @@ return parentId; } -QVector Transaction::childrenDocumentId(quint64 parentId) const -{ - DocumentUrlDB docUrlDB(m_dbis.idTreeDbi, m_dbis.idFilenameDbi, m_txn); - - return docUrlDB.getChildren(parentId); -} - DocumentTimeDB::TimeInfo Transaction::documentTimeInfo(quint64 id) const { Q_ASSERT(m_txn); diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/engine/transaction.h baloo-kf5-5.70.0+p20.04+git20200510.1418/src/engine/transaction.h --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/engine/transaction.h 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/engine/transaction.h 2020-05-10 14:18:38.000000000 +0000 @@ -64,7 +64,6 @@ * \p path into an id. */ quint64 documentId(const QByteArray& path) const; - QVector childrenDocumentId(quint64 parentId) const; QByteArray documentData(quint64 id) const; DocumentTimeDB::TimeInfo documentTimeInfo(quint64 id) const; diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/basicindexingjob.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/basicindexingjob.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/basicindexingjob.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/basicindexingjob.cpp 2020-05-10 14:18:38.000000000 +0000 @@ -192,7 +192,6 @@ TermGenerator tg(doc); tg.indexFileNameText(fileName); - tg.indexFileNameText(fileName, QByteArray("F")); tg.indexText(m_mimetype, QByteArray("M")); // (Content) Modification time, Metadata (e.g. XAttr) change time diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/CMakeLists.txt baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/CMakeLists.txt --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/CMakeLists.txt 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/CMakeLists.txt 2020-05-10 14:18:38.000000000 +0000 @@ -47,6 +47,7 @@ ecm_qt_declare_logging_category(file_static_lib_SRCS HEADER baloodebug.h IDENTIFIER BALOO CATEGORY_NAME org.kde.baloo) +# KF6 TODO - remove BalooWatcherApplication qt5_add_dbus_interface(file_static_lib_SRCS org.kde.BalooWatcherApplication.xml baloowatcherapplication_interface) kconfig_add_kcfg_files(file_static_lib_SRCS ../lib/baloosettings.kcfgc GENERATE_MOC) diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/extractor/app.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/extractor/app.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/extractor/app.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/extractor/app.cpp 2020-05-10 14:18:38.000000000 +0000 @@ -87,7 +87,7 @@ Database *db = globalDatabaseInstance(); if (!db->open(Database::ReadWriteDatabase)) { - qCritical() << "Failed to open the database"; + qCCritical(BALOO) << "Failed to open the database"; exit(1); } @@ -124,6 +124,7 @@ } m_outputStream << "S " << url << '\n'; + m_outputStream.flush(); bool indexed = index(m_tr, url, id); m_outputStream << "F " << url << '\n'; m_outputStream.flush(); @@ -214,7 +215,7 @@ result.finish(); if (doc.id() != id) { - qWarning() << url << "id seems to have changed. Perhaps baloo was not running, and this file was deleted + re-created"; + qCWarning(BALOO) << url << "id seems to have changed. Perhaps baloo was not running, and this file was deleted + re-created"; tr->removeDocument(id); if (!tr->hasDocument(doc.id())) { tr->addDocument(result.document()); diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/filecontentindexer.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/filecontentindexer.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/filecontentindexer.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/filecontentindexer.cpp 2020-05-10 14:18:38.000000000 +0000 @@ -124,11 +124,10 @@ void FileContentIndexer::slotFinishedIndexingFile(const QString& filePath) { - Q_UNUSED(filePath); + m_currentFile = QString(); if (!m_registeredMonitors.isEmpty()) { Q_EMIT finishedIndexingFile(filePath); } - m_currentFile = QString(); } void FileContentIndexer::registerMonitor(const QDBusMessage& message) diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/filewatch.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/filewatch.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/filewatch.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/filewatch.cpp 2020-05-10 14:18:38.000000000 +0000 @@ -36,7 +36,7 @@ using namespace Baloo; -FileWatch::FileWatch(Database* db, FileIndexerConfig* config, Baloo::MainHub *dbusInterface, QObject* parent) +FileWatch::FileWatch(Database* db, FileIndexerConfig* config, QObject* parent) : QObject(parent) , m_db(db) , m_config(config) @@ -73,28 +73,9 @@ { } -void FileWatch::watchIndexedFolders() -{ - // Watch all indexed folders - const QStringList folders = m_config->includeFolders(); - for (const QString& folder : folders) { - watchFolder(folder); - } -} - -void FileWatch::registerBalooWatcher(const QString &service) -{ - if (!m_metadataMover) { - return; - } - - m_metadataMover->registerBalooWatcher(service); -} - // FIXME: listen to Create for folders! void FileWatch::watchFolder(const QString& path) { - qCDebug(BALOO) << path; if (m_dirWatch && !m_dirWatch->watchingPath(path)) { KInotify::WatchEvents flags(KInotify::EventMove | KInotify::EventDelete | KInotify::EventDeleteSelf | KInotify::EventCloseWrite | KInotify::EventCreate @@ -206,11 +187,36 @@ void FileWatch::updateIndexedFoldersWatches() { if (m_dirWatch) { - const QStringList folders = m_config->includeFolders(); - for (const QString& folder : folders) { - m_dirWatch->removeWatch(folder); - watchFolder(folder); + const QStringList excludedFolders = m_config->excludeFolders(); + const QStringList includedFolders = m_config->includeFolders(); + + for (const QString& folder : excludedFolders) { + // Remove watch for new excluded folders + if (!m_excludedFolders.contains(folder)) { + m_dirWatch->removeWatch(folder); + } } + for (const QString& folder : m_excludedFolders) { + // Add no longer excluded folders + if (!excludedFolders.contains(folder)) { + watchFolder(folder); + } + } + + for (const QString& folder : m_includedFolders) { + // Remove no longer included folders + if (!includedFolders.contains(folder)) { + m_dirWatch->removeWatch(folder); + } + } + for (const QString& folder : includedFolders) { + if (!m_includedFolders.contains(folder)) { + watchFolder(folder); + } + } + + m_excludedFolders = excludedFolders; + m_includedFolders = includedFolders; } } diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/filewatch.h baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/filewatch.h --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/filewatch.h 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/filewatch.h 2020-05-10 14:18:38.000000000 +0000 @@ -31,28 +31,22 @@ class FileIndexerConfig; class PendingFileQueue; class FileWatchTest; -class MainHub; class FileWatch : public QObject { Q_OBJECT public: - FileWatch(Database* db, FileIndexerConfig* config, Baloo::MainHub *dbusInterface, QObject* parent = nullptr); + FileWatch(Database* db, FileIndexerConfig* config, QObject* parent = nullptr); ~FileWatch(); public Q_SLOTS: /** - * To be called whenever the list of indexed folders changes. This is done because - * the indexed folders are watched with the 'KInotify::EventCreate' event, and the - * non-indexed folders are not. + * To be called whenever the list of indexed/excluded folders in the config + * changes. */ void updateIndexedFoldersWatches(); - void watchIndexedFolders(); - - void registerBalooWatcher(const QString &service); - Q_SIGNALS: void indexNewFile(const QString& string); void indexModifiedFile(const QString& string); @@ -89,6 +83,9 @@ /// queue used to "compress" multiple file events like downloads PendingFileQueue* m_pendingFileQueue; + QStringList m_includedFolders; + QStringList m_excludedFolders; + friend class FileWatchTest; }; } diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/kinotify.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/kinotify.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/kinotify.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/kinotify.cpp 2020-05-10 14:18:38.000000000 +0000 @@ -42,12 +42,11 @@ namespace { -QByteArray stripTrailingSlash(const QByteArray& path) +QByteArray normalizeTrailingSlash(QByteArray&& path) { - QByteArray p(path); - if (p.endsWith('/')) - p.chop(1); - return p; + if (!path.endsWith('/')) + path.append('/'); + return path; } QByteArray concatPath(const QByteArray& p1, const QByteArray& p2) @@ -122,7 +121,7 @@ // we always need the unmount event to maintain our path hash const int mask = newMode | newFlags | EventUnmount | FlagExclUnlink; - const QByteArray encpath = stripTrailingSlash(QFile::encodeName(path)); + const QByteArray encpath = normalizeTrailingSlash(QFile::encodeName(path)); int wd = inotify_add_watch(inotify(), encpath.data(), mask); if (wd > 0) { // qCDebug(BALOO) << "Successfully added watch for" << path << watchPathHash.count(); @@ -252,7 +251,7 @@ bool KInotify::watchingPath(const QString& path) const { - const QByteArray p(stripTrailingSlash(QFile::encodeName(path))); + const QByteArray p = normalizeTrailingSlash(QFile::encodeName(path)); return d->pathWatchHash.contains(p); } @@ -363,6 +362,9 @@ const QByteArray eventName = QByteArray::fromRawData(event->name, qstrnlen(event->name, event->len)); const QByteArray hashedPath = d->watchPathHash.value(event->wd); path = concatPath(hashedPath, eventName); + if (event->mask & IN_ISDIR) { + path = normalizeTrailingSlash(std::move(path)); + } } Q_ASSERT(!path.isEmpty() || event->mask & EventIgnored); diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/main.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/main.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/main.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/main.cpp 2020-05-10 14:18:38.000000000 +0000 @@ -20,9 +20,7 @@ * */ -#include #include -#include #include @@ -43,20 +41,14 @@ lowerSchedulingPriority(); lowerPriority(); - KAboutData aboutData(QStringLiteral("baloo"), i18n("Baloo File Indexing Daemon"), PROJECT_VERSION); - aboutData.addAuthor(i18n("Vishesh Handa"), i18n("Maintainer"), QStringLiteral("vhanda@kde.org"), QStringLiteral("https://vhanda.in")); - QCoreApplication app(argc, argv); - KAboutData::setApplicationData(aboutData); - Baloo::FileIndexerConfig indexerConfig; if (!indexerConfig.indexingEnabled()) { std::cout << "Baloo File Indexing has been disabled" << std::endl; return 0; } - if (!QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.baloo"))) { qWarning() << "Failed to register via dbus. Another instance is running"; return 1; diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/mainhub.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/mainhub.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/mainhub.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/mainhub.cpp 2020-05-10 14:18:38.000000000 +0000 @@ -62,7 +62,7 @@ m_fileIndexScheduler.startupFinished(); }); } - QTimer::singleShot(0, &m_fileWatcher, &FileWatch::watchIndexedFolders); + QTimer::singleShot(0, &m_fileWatcher, &FileWatch::updateIndexedFoldersWatches); } void MainHub::quit() const @@ -77,7 +77,6 @@ m_fileIndexScheduler.updateConfig(); } -void MainHub::registerBalooWatcher(const QString &service) +void MainHub::registerBalooWatcher(const QString &) { - m_fileWatcher.registerBalooWatcher(service); } diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/mainhub.h baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/mainhub.h --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/mainhub.h 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/mainhub.h 2020-05-10 14:18:38.000000000 +0000 @@ -41,6 +41,7 @@ public Q_SLOTS: Q_SCRIPTABLE void quit() const; Q_SCRIPTABLE void updateConfig(); + // TODO KF6 - remove Q_SCRIPTABLE void registerBalooWatcher(const QString &service); private: diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/metadatamover.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/metadatamover.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/metadatamover.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/metadatamover.cpp 2020-05-10 14:18:38.000000000 +0000 @@ -22,13 +22,9 @@ #include "transaction.h" #include "basicindexingjob.h" #include "idutils.h" -#include "mainhub.h" #include "baloodebug.h" -#include "baloowatcherapplication_interface.h" - #include -#include using namespace Baloo; @@ -36,11 +32,6 @@ : QObject(parent) , m_db(db) { - m_serviceWatcher.setConnection(QDBusConnection::sessionBus()); - m_serviceWatcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration); - - connect(&m_serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, - this, &MetadataMover::watcherServiceUnregistered); } @@ -48,22 +39,6 @@ { } -bool MetadataMover::hasWatcher() const -{ - return !m_watcherApplications.isEmpty(); -} - - -static void buildRecursiveList(quint64 parentId, QList &fileList, Transaction &tr) -{ - fileList.push_back(QFile::decodeName(tr.documentUrl(parentId))); - - const auto childrenIds = tr.childrenDocumentId(parentId); - - for (const auto oneChildren : childrenIds) { - buildRecursiveList(oneChildren, fileList, tr); - } -} void MetadataMover::moveFileMetadata(const QString& from, const QString& to) { @@ -73,14 +48,6 @@ Transaction tr(m_db, Transaction::ReadWrite); - quint64 id = tr.documentId(QFile::encodeName(from)); - QList filesList; - qCDebug(BALOO) << "MetadataMover::moveFileMetadata" << (hasWatcher() ? "has watcher" : "has no watcher"); - qCDebug(BALOO) << "MetadataMover::moveFileMetadata" << "id" << id; - if (id && hasWatcher()) { - buildRecursiveList(id, filesList, tr); - } - // We do NOT get deleted messages for overwritten files! Thus, we // have to remove all metadata for overwritten files first. removeMetadata(&tr, to); @@ -89,11 +56,6 @@ updateMetadata(&tr, from, to); tr.commit(); - - if (hasWatcher()) { - qCDebug(BALOO) << "MetadataMover::moveFileMetadata" << "notifyWatchers" << filesList; - notifyWatchers(from, to, filesList); - } } void MetadataMover::removeFileMetadata(const QString& file) @@ -105,23 +67,6 @@ tr.commit(); } -void MetadataMover::registerBalooWatcher(const QString &service) -{ - int firstSlash = service.indexOf('/'); - if (firstSlash == -1) { - return; - } - - QString dbusServiceName = service.left(firstSlash); - QString dbusPath = service.mid(firstSlash); - - m_serviceWatcher.addWatchedService(dbusServiceName); - - m_watcherApplications.insert(dbusServiceName, new org::kde::BalooWatcherApplication(dbusServiceName, dbusPath, QDBusConnection::sessionBus(), this)); - - qCDebug(BALOO) << "MetadataMover::registerBalooWatcher" << service << dbusServiceName << dbusPath; -} - void MetadataMover::removeMetadata(Transaction* tr, const QString& url) { Q_ASSERT(!url.isEmpty()); @@ -174,24 +119,3 @@ // 1. file moves to the same device - id is preserved // 2. file moves to a different device - id is not preserved } - -void MetadataMover::notifyWatchers(const QString &from, const QString &to, const QList &filesList) -{ - for (org::kde::BalooWatcherApplication *watcherApplication : qAsConst(m_watcherApplications)) { - qCDebug(BALOO) << "MetadataMover::notifyWatchers" << watcherApplication->service() << watcherApplication->objectName() << watcherApplication->path(); - watcherApplication->renamedFiles(from, to, filesList); - } -} - -void MetadataMover::watcherServiceUnregistered(const QString &serviceName) -{ - auto itService = m_watcherApplications.find(serviceName); - if (itService == m_watcherApplications.end()) { - return; - } - - qCDebug(BALOO) << "MetadataMover::watcherServiceUnregistered" << itService.key(); - - delete itService.value(); - m_watcherApplications.erase(itService); -} diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/metadatamover.h baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/metadatamover.h --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/metadatamover.h 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/metadatamover.h 2020-05-10 14:18:38.000000000 +0000 @@ -21,22 +21,6 @@ #define BALOO_METADATA_MOVER_H_ #include -#include -#include - -class OrgKdeBalooWatcherApplicationInterface; - -namespace org -{ - -namespace kde -{ - -typedef ::OrgKdeBalooWatcherApplicationInterface BalooWatcherApplication; - -} - -} namespace Baloo { @@ -52,14 +36,10 @@ MetadataMover(Database* db, QObject* parent = nullptr); ~MetadataMover(); - bool hasWatcher() const; - public Q_SLOTS: void moveFileMetadata(const QString& from, const QString& to); void removeFileMetadata(const QString& file); - void registerBalooWatcher(const QString &service); - Q_SIGNALS: /** * Emitted for files (and folders) that have been moved but @@ -72,10 +52,6 @@ void fileRemoved(const QString& path); -private Q_SLOTS: - - void watcherServiceUnregistered(const QString &serviceName); - private: /** * Remove the metadata for file \p url @@ -88,12 +64,6 @@ */ void updateMetadata(Transaction* tr, const QString& from, const QString& to); - void notifyWatchers(const QString &from, const QString &to, const QList &filesList); - - QMap m_watcherApplications; - - QDBusServiceWatcher m_serviceWatcher; - Database* m_db; }; } diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/modifiedfileindexer.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/modifiedfileindexer.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/file/modifiedfileindexer.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/file/modifiedfileindexer.cpp 2020-05-10 14:18:38.000000000 +0000 @@ -119,8 +119,8 @@ continue; } - // we can get modified events for files which do not exist - // cause Baloo was not running and missed those events + // We can get modified events for files which do not yet exist in the database + // because Baloo was not running and missed the creation events if (isKnownFile && (job.document().id() == fileId)) { tr.replaceDocument(job.document(), XAttrTerms | DocumentTime | FileNameTerms | DocumentUrl); } else { diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/lib/searchstore.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/src/lib/searchstore.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/lib/searchstore.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/lib/searchstore.cpp 2020-05-10 14:18:38.000000000 +0000 @@ -309,6 +309,10 @@ Q_ASSERT(0); return nullptr; } + } else if (property == "") { + Term cterm(QStringLiteral("content"), term.value(), term.comparator()); + Term fterm(QStringLiteral("filename"), term.value(), term.comparator()); + return constructQuery(tr, Term{cterm, Term::Operation::Or, fterm}); } QByteArray prefix; diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/qml/experimental/monitor.cpp baloo-kf5-5.70.0+p20.04+git20200510.1418/src/qml/experimental/monitor.cpp --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/qml/experimental/monitor.cpp 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/qml/experimental/monitor.cpp 2020-05-10 14:18:38.000000000 +0000 @@ -78,16 +78,17 @@ void Monitor::newFile(const QString& filePath) { + m_filePath = filePath; if (m_totalFiles == 0) { fetchTotalFiles(); } - m_filePath = filePath; ++m_filesIndexed; Q_EMIT newFileIndexed(); - if (m_remainingTimeTimer.elapsed() > 1000) { + auto now = QDeadlineTimer::current(); + if (now > m_remainingTimeTimer) { updateRemainingTime(); - m_remainingTimeTimer.restart(); + m_remainingTimeTimer = now + 1000; } } @@ -134,8 +135,12 @@ void Monitor::updateRemainingTime() { - m_remainingTime = KFormat().formatSpelloutDuration(m_scheduler->getRemainingTime()); - Q_EMIT remainingTimeChanged(); + auto remainingTime = m_scheduler->getRemainingTime(); + if ((remainingTime != m_remainingTimeSeconds) && (remainingTime > 0)) { + m_remainingTime = KFormat().formatSpelloutDuration(remainingTime); + m_remainingTimeSeconds = remainingTime; + Q_EMIT remainingTimeChanged(); + } } void Monitor::slotIndexerStateChanged(int state) @@ -144,13 +149,11 @@ if (m_indexerState != newState) { m_indexerState = newState; - Q_EMIT indexerStateChanged(); fetchTotalFiles(); - if (m_indexerState == Baloo::ContentIndexing) { - m_remainingTimeTimer.start(); - } else { + if (m_indexerState != Baloo::ContentIndexing) { m_filePath = QString(); } + Q_EMIT indexerStateChanged(); } } diff -Nru baloo-kf5-5.69.0+p20.04+git20200418.1103/src/qml/experimental/monitor.h baloo-kf5-5.70.0+p20.04+git20200510.1418/src/qml/experimental/monitor.h --- baloo-kf5-5.69.0+p20.04+git20200418.1103/src/qml/experimental/monitor.h 2020-04-18 11:03:47.000000000 +0000 +++ baloo-kf5-5.70.0+p20.04+git20200510.1418/src/qml/experimental/monitor.h 2020-05-10 14:18:38.000000000 +0000 @@ -23,6 +23,7 @@ #ifndef BALOOMONITOR_MONITOR_H #define BALOOMONITOR_MONITOR_H +#include #include #include @@ -78,7 +79,7 @@ QString m_filePath; bool m_balooRunning = false; Baloo::IndexerState m_indexerState = Baloo::Unavailable; - QElapsedTimer m_remainingTimeTimer; + QDeadlineTimer m_remainingTimeTimer = QDeadlineTimer(0); org::kde::baloo::scheduler* m_scheduler; org::kde::baloo::fileindexer* m_fileindexer; @@ -86,6 +87,7 @@ uint m_totalFiles = 0; uint m_filesIndexed = 0; QString m_remainingTime; + uint m_remainingTimeSeconds = 0; }; } #endif //BALOOMONITOR_MONITOR_H