diff --git a/libsearch/index/file-index-manager.cpp b/libsearch/index/file-index-manager.cpp index fbc20f7..dab3f78 100644 --- a/libsearch/index/file-index-manager.cpp +++ b/libsearch/index/file-index-manager.cpp @@ -53,22 +53,16 @@ void FileIndexManager::initIndexPathSetFunction() return; } - QDBusInterface *interface = new QDBusInterface("com.ukui.search.fileindex.service", - "/org/ukui/search/privateDirWatcher", - "org.ukui.search.fileindex"); + connect(DirWatcher::getDirWatcher(), &DirWatcher::appendIndexItem, this, &FileIndexManager::handleIndexPathAppend, Qt::QueuedConnection); + connect(DirWatcher::getDirWatcher(), &DirWatcher::removeIndexItem, this, &FileIndexManager::handleRemovePathAppend, Qt::QueuedConnection); - if (interface->isValid()) { - connect(interface, SIGNAL(appendIndexItem(QString, QStringList)), this, SLOT(handleIndexPathAppend(QString, QStringList)), Qt::QueuedConnection); - } -// connect(DirWatcher::getDirWatcher(), &DirWatcher::appendIndexItem, this, &FileIndexManager::handleIndexPathAppend, Qt::QueuedConnection); DirWatcher::getDirWatcher()->initDbusService(); } void FileIndexManager::handleIndexPathAppend(const QString path, const QStringList blockList) { - qDebug() << "I'm in handleIndexPathAppend"; - qDebug() << "path" << path << "blockList" << blockList; + qDebug() << "Add Index path:" << path << " blockList:" << blockList; if(!m_searchSettings->get(SEARCH_METHOD_KEY).toBool()) { m_searchSettings->set(SEARCH_METHOD_KEY, true); } else { @@ -76,3 +70,13 @@ void FileIndexManager::handleIndexPathAppend(const QString path, const QStringLi m_iw->addIndexPath(path, blockList); } } + +void FileIndexManager::handleRemovePathAppend(const QString path) +{ + qDebug() << "Remove index path:" << path; + if(m_searchSettings->get(SEARCH_METHOD_KEY).toBool()) { + m_iw->removeIndexPath(path, true); + } else { + m_iw->removeIndexPath(path, false); + } +} diff --git a/libsearch/index/file-index-manager.h b/libsearch/index/file-index-manager.h index 0bab966..c961dfe 100644 --- a/libsearch/index/file-index-manager.h +++ b/libsearch/index/file-index-manager.h @@ -16,6 +16,7 @@ public: void initIndexPathSetFunction(); private Q_SLOTS: void handleIndexPathAppend(const QString path, const QStringList blockList); + void handleRemovePathAppend(const QString path); private: FileIndexManager(QObject *parent = nullptr); FirstIndex *m_fi; diff --git a/libsearch/index/inotify-watch.cpp b/libsearch/index/inotify-watch.cpp index ed198f0..a5c3268 100644 --- a/libsearch/index/inotify-watch.cpp +++ b/libsearch/index/inotify-watch.cpp @@ -1,8 +1,9 @@ -#include "inotify-watch.h" -#include "dir-watcher.h" +#include "inotify-watch.h" +#include #include #include #include +#include "dir-watcher.h" using namespace UkuiSearch; static InotifyWatch* global_instance_InotifyWatch = nullptr; @@ -98,6 +99,7 @@ void InotifyWatch::work(const QFileInfo &info) void InotifyWatch::firstTraverse(QStringList pathList, QStringList blockList) { + QMutexLocker locker(&m_pathMapLock); if(pathList.isEmpty()) { pathList = m_pathList; } @@ -151,9 +153,27 @@ void InotifyWatch::addIndexPath(const QString path, const QStringList blockList) this->firstTraverse(QStringList() << path, blockList); } -void InotifyWatch::removeIndexPath(QString &path) +void InotifyWatch::removeIndexPath(const QString &path, bool fileIndexEnable) { - + QMutexLocker locker(&m_pathMapLock); + if(fileIndexEnable) { + removeWatch(path, true); + }else { + for(QMap::Iterator i = m_pathMap.begin(); i != m_pathMap.end();) { + if(FileUtils::isOrUnder(i.value(), path)) { + qDebug() << "remove path: " << i.value(); + PendingFile f(i.value()); + f.setDeleted(); + f.setIsDir(); + PendingFileQueue::getInstance()->enqueue(f); + m_pathMap.erase(i++); + } else { + i++; + } + } + } + PendingFileQueue::getInstance()->forceFinish(); + PendingFileQueue::getInstance()->~PendingFileQueue(); } void InotifyWatch::stopWatch() @@ -323,7 +343,9 @@ void InotifyWatch::slotEvent(char *buf, ssize_t len) in >> pathMap; m_sharedMemory->unlock(); m_sharedMemory->detach(); + m_pathMapLock.lock(); m_pathMap = pathMap; + m_pathMapLock.unlock(); } } else { assert(false); diff --git a/libsearch/index/inotify-watch.h b/libsearch/index/inotify-watch.h index 52af25c..72b1f29 100644 --- a/libsearch/index/inotify-watch.h +++ b/libsearch/index/inotify-watch.h @@ -32,7 +32,7 @@ public: void firstTraverse(QStringList pathList = {}, QStringList blockList = {}); void stopWatch(); void addIndexPath(const QString path, const QStringList blockList); - void removeIndexPath(QString &path); + void removeIndexPath(const QString &path, bool fileIndexEnable); protected: void run() override; @@ -49,7 +49,7 @@ private: QSocketNotifier* m_notifier = nullptr; QSharedMemory *m_sharedMemory = nullptr; QMap m_pathMap; - QMutex m_mutex; + QMutex m_pathMapLock; QSystemSemaphore m_semaphore; }; diff --git a/libsearch/index/pending-file-queue.cpp b/libsearch/index/pending-file-queue.cpp index 0b60048..a0ee56c 100644 --- a/libsearch/index/pending-file-queue.cpp +++ b/libsearch/index/pending-file-queue.cpp @@ -66,6 +66,7 @@ PendingFileQueue::~PendingFileQueue() delete m_minProcessTimer; m_minProcessTimer = nullptr; } + global_instance_pending_file_queue = nullptr; IndexGenerator::getInstance()->~IndexGenerator(); }