增加索引删除功能。

This commit is contained in:
iaom 2022-06-02 09:23:53 +08:00
parent e94fc38c92
commit 46c7ab437c
5 changed files with 43 additions and 15 deletions

View File

@ -53,22 +53,16 @@ void FileIndexManager::initIndexPathSetFunction()
return; return;
} }
QDBusInterface *interface = new QDBusInterface("com.ukui.search.fileindex.service", connect(DirWatcher::getDirWatcher(), &DirWatcher::appendIndexItem, this, &FileIndexManager::handleIndexPathAppend, Qt::QueuedConnection);
"/org/ukui/search/privateDirWatcher", connect(DirWatcher::getDirWatcher(), &DirWatcher::removeIndexItem, this, &FileIndexManager::handleRemovePathAppend, Qt::QueuedConnection);
"org.ukui.search.fileindex");
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(); DirWatcher::getDirWatcher()->initDbusService();
} }
void FileIndexManager::handleIndexPathAppend(const QString path, const QStringList blockList) void FileIndexManager::handleIndexPathAppend(const QString path, const QStringList blockList)
{ {
qDebug() << "I'm in handleIndexPathAppend"; qDebug() << "Add Index path:" << path << " blockList:" << blockList;
qDebug() << "path" << path << "blockList" << blockList;
if(!m_searchSettings->get(SEARCH_METHOD_KEY).toBool()) { if(!m_searchSettings->get(SEARCH_METHOD_KEY).toBool()) {
m_searchSettings->set(SEARCH_METHOD_KEY, true); m_searchSettings->set(SEARCH_METHOD_KEY, true);
} else { } else {
@ -76,3 +70,13 @@ void FileIndexManager::handleIndexPathAppend(const QString path, const QStringLi
m_iw->addIndexPath(path, blockList); 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);
}
}

View File

@ -16,6 +16,7 @@ public:
void initIndexPathSetFunction(); void initIndexPathSetFunction();
private Q_SLOTS: private Q_SLOTS:
void handleIndexPathAppend(const QString path, const QStringList blockList); void handleIndexPathAppend(const QString path, const QStringList blockList);
void handleRemovePathAppend(const QString path);
private: private:
FileIndexManager(QObject *parent = nullptr); FileIndexManager(QObject *parent = nullptr);
FirstIndex *m_fi; FirstIndex *m_fi;

View File

@ -1,8 +1,9 @@
#include "inotify-watch.h" #include "inotify-watch.h"
#include "dir-watcher.h" #include <QMutexLocker>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <malloc.h> #include <malloc.h>
#include <errno.h> #include <errno.h>
#include "dir-watcher.h"
using namespace UkuiSearch; using namespace UkuiSearch;
static InotifyWatch* global_instance_InotifyWatch = nullptr; static InotifyWatch* global_instance_InotifyWatch = nullptr;
@ -98,6 +99,7 @@ void InotifyWatch::work(const QFileInfo &info)
void InotifyWatch::firstTraverse(QStringList pathList, QStringList blockList) void InotifyWatch::firstTraverse(QStringList pathList, QStringList blockList)
{ {
QMutexLocker locker(&m_pathMapLock);
if(pathList.isEmpty()) { if(pathList.isEmpty()) {
pathList = m_pathList; pathList = m_pathList;
} }
@ -151,9 +153,27 @@ void InotifyWatch::addIndexPath(const QString path, const QStringList blockList)
this->firstTraverse(QStringList() << path, 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<int, QString>::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() void InotifyWatch::stopWatch()
@ -323,7 +343,9 @@ void InotifyWatch::slotEvent(char *buf, ssize_t len)
in >> pathMap; in >> pathMap;
m_sharedMemory->unlock(); m_sharedMemory->unlock();
m_sharedMemory->detach(); m_sharedMemory->detach();
m_pathMapLock.lock();
m_pathMap = pathMap; m_pathMap = pathMap;
m_pathMapLock.unlock();
} }
} else { } else {
assert(false); assert(false);

View File

@ -32,7 +32,7 @@ public:
void firstTraverse(QStringList pathList = {}, QStringList blockList = {}); void firstTraverse(QStringList pathList = {}, QStringList blockList = {});
void stopWatch(); void stopWatch();
void addIndexPath(const QString path, const QStringList blockList); void addIndexPath(const QString path, const QStringList blockList);
void removeIndexPath(QString &path); void removeIndexPath(const QString &path, bool fileIndexEnable);
protected: protected:
void run() override; void run() override;
@ -49,7 +49,7 @@ private:
QSocketNotifier* m_notifier = nullptr; QSocketNotifier* m_notifier = nullptr;
QSharedMemory *m_sharedMemory = nullptr; QSharedMemory *m_sharedMemory = nullptr;
QMap<int, QString> m_pathMap; QMap<int, QString> m_pathMap;
QMutex m_mutex; QMutex m_pathMapLock;
QSystemSemaphore m_semaphore; QSystemSemaphore m_semaphore;
}; };

View File

@ -66,6 +66,7 @@ PendingFileQueue::~PendingFileQueue()
delete m_minProcessTimer; delete m_minProcessTimer;
m_minProcessTimer = nullptr; m_minProcessTimer = nullptr;
} }
global_instance_pending_file_queue = nullptr;
IndexGenerator::getInstance()->~IndexGenerator(); IndexGenerator::getInstance()->~IndexGenerator();
} }