增加索引删除功能。
This commit is contained in:
parent
e94fc38c92
commit
46c7ab437c
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#include "inotify-watch.h"
|
||||
#include "dir-watcher.h"
|
||||
#include "inotify-watch.h"
|
||||
#include <QMutexLocker>
|
||||
#include <sys/ioctl.h>
|
||||
#include <malloc.h>
|
||||
#include <errno.h>
|
||||
#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<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()
|
||||
|
@ -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);
|
||||
|
|
|
@ -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<int, QString> m_pathMap;
|
||||
QMutex m_mutex;
|
||||
QMutex m_pathMapLock;
|
||||
QSystemSemaphore m_semaphore;
|
||||
|
||||
};
|
||||
|
|
|
@ -66,6 +66,7 @@ PendingFileQueue::~PendingFileQueue()
|
|||
delete m_minProcessTimer;
|
||||
m_minProcessTimer = nullptr;
|
||||
}
|
||||
global_instance_pending_file_queue = nullptr;
|
||||
|
||||
IndexGenerator::getInstance()->~IndexGenerator();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue