Creat two sub-processes for file index to reduce the resource consumption(ongoing).
This commit is contained in:
parent
3efac5701c
commit
452896a354
|
@ -1,3 +1,9 @@
|
||||||
|
ukui-search (0.0.1+0120) v101; urgency=medium
|
||||||
|
|
||||||
|
* Bugs Fixed.
|
||||||
|
|
||||||
|
-- zhangpengfei <zhangpengfei@kylinos.cn> Wed, 20 Jan 2021 15:55:57 +0800
|
||||||
|
|
||||||
ukui-search (0.0.1+0118) v101; urgency=medium
|
ukui-search (0.0.1+0118) v101; urgency=medium
|
||||||
|
|
||||||
* Feature: Add animation into inputbox.
|
* Feature: Add animation into inputbox.
|
||||||
|
@ -11,8 +17,7 @@ ukui-search (0.0.1+0118) v101; urgency=medium
|
||||||
* Fix: Translation is incompleted.(33047)
|
* Fix: Translation is incompleted.(33047)
|
||||||
* Fix: Widget crashed when searching & open file/filepath failed.
|
* Fix: Widget crashed when searching & open file/filepath failed.
|
||||||
|
|
||||||
-- zhangjiaping <zhangjiaping@zhangpengfei> Mon, 18 Jan 2021 14:3
|
-- zhangjiaping <zhangjiaping@kylinos.cn> Mon, 18 Jan 2021 14:31:24 +0800
|
||||||
6:12 +0800
|
|
||||||
|
|
||||||
ukui-search (0.0.1+0115) v101; urgency=medium
|
ukui-search (0.0.1+0115) v101; urgency=medium
|
||||||
|
|
||||||
|
@ -24,7 +29,7 @@ ukui-search (0.0.1+0114) v101; urgency=medium
|
||||||
|
|
||||||
* Bugs fixed.
|
* Bugs fixed.
|
||||||
|
|
||||||
-- zhangpengfei <zhangpengfei@zhangpengfei> Thu, 14 Jan 2021 20:47:42 +0800
|
-- zhangpengfei <zhangpengfei@kylinos.cn> Thu, 14 Jan 2021 20:47:42 +0800
|
||||||
|
|
||||||
ukui-search (0.0.1+0113) v101; urgency=medium
|
ukui-search (0.0.1+0113) v101; urgency=medium
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ QMutex ChineseSegmentation::m_mutex;
|
||||||
|
|
||||||
ChineseSegmentation::ChineseSegmentation()
|
ChineseSegmentation::ChineseSegmentation()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&m_mutex);
|
|
||||||
const char * const DICT_PATH = "/usr/share/ukui-search/res/dict/jieba.dict.utf8";
|
const char * const DICT_PATH = "/usr/share/ukui-search/res/dict/jieba.dict.utf8";
|
||||||
const char * const HMM_PATH = "/usr/share/ukui-search/res/dict/hmm_model.utf8";
|
const char * const HMM_PATH = "/usr/share/ukui-search/res/dict/hmm_model.utf8";
|
||||||
const char * const USER_DICT_PATH ="/usr/share/ukui-search/res/dict/user.dict.utf8";
|
const char * const USER_DICT_PATH ="/usr/share/ukui-search/res/dict/user.dict.utf8";
|
||||||
|
@ -29,6 +28,7 @@ ChineseSegmentation::~ChineseSegmentation()
|
||||||
|
|
||||||
ChineseSegmentation *ChineseSegmentation::getInstance()
|
ChineseSegmentation *ChineseSegmentation::getInstance()
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&m_mutex);
|
||||||
if (!global_instance_chinese_segmentation) {
|
if (!global_instance_chinese_segmentation) {
|
||||||
global_instance_chinese_segmentation = new ChineseSegmentation;
|
global_instance_chinese_segmentation = new ChineseSegmentation;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#define CREATING_INDEX 1
|
#define CREATING_INDEX 1
|
||||||
#define FINISH_CREATING_INDEX 2
|
#define FINISH_CREATING_INDEX 2
|
||||||
|
|
||||||
|
|
||||||
class LIBSEARCH_EXPORT FileUtils
|
class LIBSEARCH_EXPORT FileUtils
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -66,6 +66,7 @@ void FileSearcher::onKeywordSearch(QString keyword,QQueue<QString> *searchResult
|
||||||
total += resultCount;
|
total += resultCount;
|
||||||
begin += num;
|
begin += num;
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
});
|
});
|
||||||
// Q_EMIT this->resultFile(m_search_result_file);
|
// Q_EMIT this->resultFile(m_search_result_file);
|
||||||
//dir
|
//dir
|
||||||
|
@ -84,6 +85,7 @@ void FileSearcher::onKeywordSearch(QString keyword,QQueue<QString> *searchResult
|
||||||
total += resultCount;
|
total += resultCount;
|
||||||
begin += num;
|
begin += num;
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
});
|
});
|
||||||
// Q_EMIT this->resultDir(m_search_result_dir);
|
// Q_EMIT this->resultDir(m_search_result_dir);
|
||||||
//content
|
//content
|
||||||
|
@ -103,6 +105,7 @@ void FileSearcher::onKeywordSearch(QString keyword,QQueue<QString> *searchResult
|
||||||
total += resultCount;
|
total += resultCount;
|
||||||
begin += num;
|
begin += num;
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
});
|
});
|
||||||
// Q_EMIT this->resultContent(m_search_result_content);
|
// Q_EMIT this->resultContent(m_search_result_content);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#include "first-index.h"
|
#include "first-index.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
|
||||||
void handler(int){
|
void handler(int){
|
||||||
qDebug() << "Recieved SIGTERM!";
|
qDebug() << "Recieved SIGTERM!";
|
||||||
GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE, "2");
|
GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE, "2");
|
||||||
|
@ -107,67 +106,81 @@ void FirstIndex::run(){
|
||||||
// this->p_indexGenerator->creatAllIndex(this->q_content_index);
|
// this->p_indexGenerator->creatAllIndex(this->q_content_index);
|
||||||
|
|
||||||
|
|
||||||
FileUtils::_index_status = CREATING_INDEX;
|
pid_t pid;
|
||||||
QSemaphore sem(5);
|
pid = fork();
|
||||||
QMutex mutex1, mutex2, mutex3;
|
if(pid == 0)
|
||||||
mutex1.lock();
|
{
|
||||||
mutex2.lock();
|
prctl(PR_SET_NAME,"first-index");
|
||||||
mutex3.lock();
|
FileUtils::_index_status = CREATING_INDEX;
|
||||||
sem.acquire(4);
|
QSemaphore sem(5);
|
||||||
QtConcurrent::run([&](){
|
QMutex mutex1, mutex2, mutex3;
|
||||||
sem.acquire(1);
|
mutex1.lock();
|
||||||
|
mutex2.lock();
|
||||||
|
mutex3.lock();
|
||||||
|
sem.acquire(4);
|
||||||
|
QtConcurrent::run([&](){
|
||||||
|
sem.acquire(1);
|
||||||
|
mutex1.unlock();
|
||||||
|
this->Traverse();
|
||||||
|
FileUtils::_max_index_count = this->q_index->length();
|
||||||
|
sem.release(5);
|
||||||
|
});
|
||||||
|
QtConcurrent::run([&](){
|
||||||
|
sem.acquire(2);
|
||||||
|
mutex2.unlock();
|
||||||
|
qDebug() << "index start;";
|
||||||
|
this->p_indexGenerator->creatAllIndex(this->q_index);
|
||||||
|
qDebug() << "index end;";
|
||||||
|
sem.release(2);
|
||||||
|
});
|
||||||
|
QtConcurrent::run([&](){
|
||||||
|
sem.acquire(2);
|
||||||
|
mutex3.unlock();
|
||||||
|
qDebug() << "content index start;";
|
||||||
|
this->p_indexGenerator->creatAllIndex(this->q_content_index);
|
||||||
|
qDebug() << "content index end;";
|
||||||
|
sem.release(2);
|
||||||
|
});
|
||||||
|
mutex1.lock();
|
||||||
|
mutex2.lock();
|
||||||
|
mutex3.lock();
|
||||||
|
sem.acquire(5);
|
||||||
mutex1.unlock();
|
mutex1.unlock();
|
||||||
this->Traverse();
|
|
||||||
FileUtils::_max_index_count = this->q_index->length();
|
|
||||||
sem.release(5);
|
|
||||||
});
|
|
||||||
QtConcurrent::run([&](){
|
|
||||||
sem.acquire(2);
|
|
||||||
mutex2.unlock();
|
mutex2.unlock();
|
||||||
qDebug() << "index start;";
|
|
||||||
this->p_indexGenerator->creatAllIndex(this->q_index);
|
|
||||||
qDebug() << "index end;";
|
|
||||||
sem.release(2);
|
|
||||||
});
|
|
||||||
QtConcurrent::run([&](){
|
|
||||||
sem.acquire(2);
|
|
||||||
mutex3.unlock();
|
mutex3.unlock();
|
||||||
qDebug() << "content index start;";
|
_exit(0);
|
||||||
this->p_indexGenerator->creatAllIndex(this->q_content_index);
|
|
||||||
qDebug() << "content index end;";
|
|
||||||
sem.release(2);
|
|
||||||
});
|
|
||||||
mutex1.lock();
|
|
||||||
mutex2.lock();
|
|
||||||
mutex3.lock();
|
|
||||||
sem.acquire(5);
|
|
||||||
mutex1.unlock();
|
|
||||||
mutex2.unlock();
|
|
||||||
mutex3.unlock();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// qDebug() << "first index end;";
|
|
||||||
//don't use it now!!!!
|
// qDebug() << "first index end;";
|
||||||
//MouseZhangZh
|
//don't use it now!!!!
|
||||||
// this->~FirstIndex();
|
//MouseZhangZh
|
||||||
// qDebug() << "~FirstIndex end;";
|
// this->~FirstIndex();
|
||||||
|
// qDebug() << "~FirstIndex end;"
|
||||||
|
|
||||||
|
|
||||||
if (this->q_index)
|
if (this->q_index)
|
||||||
delete this->q_index;
|
delete this->q_index;
|
||||||
this->q_index = nullptr;
|
this->q_index = nullptr;
|
||||||
if (this->q_content_index)
|
if (this->q_content_index)
|
||||||
delete this->q_content_index;
|
delete this->q_content_index;
|
||||||
this->q_content_index = nullptr;
|
this->q_content_index = nullptr;
|
||||||
if (this->p_indexGenerator)
|
if (this->p_indexGenerator)
|
||||||
delete this->p_indexGenerator;
|
delete this->p_indexGenerator;
|
||||||
this->p_indexGenerator = nullptr;
|
this->p_indexGenerator = nullptr;
|
||||||
|
|
||||||
QThreadPool::globalInstance()->releaseThread();
|
|
||||||
QThreadPool::globalInstance()->waitForDone();
|
|
||||||
|
|
||||||
|
|
||||||
|
QThreadPool::globalInstance()->releaseThread();
|
||||||
|
QThreadPool::globalInstance()->waitForDone();
|
||||||
|
}
|
||||||
|
else if(pid < 0)
|
||||||
|
{
|
||||||
|
qWarning()<<"First Index fork error!!";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
waitpid(pid,NULL,0);
|
||||||
|
}
|
||||||
|
|
||||||
FileUtils::_index_status = FINISH_CREATING_INDEX;
|
FileUtils::_index_status = FINISH_CREATING_INDEX;
|
||||||
qDebug() << "sigset start!";
|
qDebug() << "sigset start!";
|
||||||
|
|
|
@ -4,6 +4,11 @@
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QtConcurrent/QtConcurrent>
|
#include <QtConcurrent/QtConcurrent>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <QSemaphore>
|
||||||
|
#include<sys/types.h>
|
||||||
|
#include<unistd.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <sys/prctl.h>
|
||||||
//#include <QtConcurrent>
|
//#include <QtConcurrent>
|
||||||
#include "traverse_bfs.h"
|
#include "traverse_bfs.h"
|
||||||
#include "global-settings.h"
|
#include "global-settings.h"
|
||||||
|
|
|
@ -450,7 +450,11 @@ bool IndexGenerator::deleteAllIndex(QStringList *pathlist)
|
||||||
qDebug()<<"delete path"<<doc;
|
qDebug()<<"delete path"<<doc;
|
||||||
qDebug()<<"delete md5"<<QString::fromStdString(uniqueterm);
|
qDebug()<<"delete md5"<<QString::fromStdString(uniqueterm);
|
||||||
m_database_path->commit();
|
m_database_path->commit();
|
||||||
|
m_database_content->commit();
|
||||||
qDebug()<< "--delete finish--";
|
qDebug()<< "--delete finish--";
|
||||||
|
// qDebug()<<"m_database_path->get_lastdocid()!!!"<<m_database_path->get_lastdocid();
|
||||||
|
|
||||||
|
// qDebug()<<"m_database_path->get_doccount()!!!"<<m_database_path->get_doccount();
|
||||||
}
|
}
|
||||||
catch(const Xapian::Error &e)
|
catch(const Xapian::Error &e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "inotify-index.h"
|
#include "inotify-index.h"
|
||||||
|
|
||||||
|
|
||||||
InotifyIndex::InotifyIndex(const QString& path) : Traverse_BFS(path)
|
InotifyIndex::InotifyIndex(const QString& path) : Traverse_BFS(path)
|
||||||
{
|
{
|
||||||
/*-------------ukuisearchdbus Test start-----------------*/
|
/*-------------ukuisearchdbus Test start-----------------*/
|
||||||
|
@ -88,51 +87,64 @@ bool InotifyIndex::RemoveWatch(const QString &path){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
void InotifyIndex::eventProcess(const char* buf, ssize_t tmp){
|
||||||
* Symbolic Link!!!!!!!!!!!!!!!!!!
|
// qDebug() << "Read " << numRead << " bytes from inotify fd";
|
||||||
* Sysmbolic link to database dir will make a Infinite loop !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
* MouseZhangZh
|
|
||||||
*/
|
|
||||||
|
|
||||||
void InotifyIndex::run(){
|
/* Process all of the events in buffer returned by read() */
|
||||||
|
|
||||||
char * p;
|
|
||||||
char buf[BUF_LEN] __attribute__((aligned(8)));
|
|
||||||
|
|
||||||
ssize_t numRead;
|
|
||||||
|
|
||||||
QQueue<QVector<QString>>* indexQueue = new QQueue<QVector<QString>>();
|
QQueue<QVector<QString>>* indexQueue = new QQueue<QVector<QString>>();
|
||||||
QQueue<QString>* contentIndexQueue = new QQueue<QString>();
|
QQueue<QString>* contentIndexQueue = new QQueue<QString>();
|
||||||
|
|
||||||
for (;;) { /* Read events forever */
|
ssize_t numRead = 0;
|
||||||
numRead = read(m_fd, buf, BUF_LEN);
|
numRead = tmp;
|
||||||
if (numRead == 0) {
|
char * p = const_cast<char*>(buf);
|
||||||
qDebug() << "read() from inotify fd returned 0!";
|
|
||||||
}
|
|
||||||
if (numRead == -1) {
|
|
||||||
qDebug() << "read";
|
|
||||||
}
|
|
||||||
// qDebug() << "Read " << numRead << " bytes from inotify fd";
|
|
||||||
|
|
||||||
/* Process all of the events in buffer returned by read() */
|
for (; p < buf + numRead;) {
|
||||||
|
struct inotify_event * event = reinterpret_cast<inotify_event *>(p);
|
||||||
|
// qDebug() << "Read Event: " << currentPath[event->wd] << QString(event->name) << event->cookie << event->wd << event->mask;
|
||||||
|
if(event->name[0] != '.'){
|
||||||
|
qDebug() << QString(currentPath[event->wd] + '/' + event->name);
|
||||||
|
FileUtils::_index_status = CREATING_INDEX;
|
||||||
|
|
||||||
for (p = buf; p < buf + numRead;) {
|
// switch (event->mask) {
|
||||||
struct inotify_event * event = reinterpret_cast<inotify_event *>(p);
|
if (event->mask & IN_CREATE){
|
||||||
// qDebug() << "Read Event: " << currentPath[event->wd] << QString(event->name) << event->cookie << event->wd << event->mask;
|
if (event->mask & IN_ISDIR){
|
||||||
if(event->name[0] != '.'){
|
AddWatch(currentPath[event->wd] + '/' + event->name);
|
||||||
qDebug() << QString(currentPath[event->wd] + '/' + event->name);
|
this->setPath(currentPath[event->wd] + '/' + event->name);
|
||||||
FileUtils::_index_status = CREATING_INDEX;
|
Traverse();
|
||||||
|
}
|
||||||
|
|
||||||
// switch (event->mask) {
|
/*--------------------------------*/
|
||||||
if (event->mask & IN_CREATE){
|
// IndexGenerator::getInstance()->creatAllIndex(QQueue<QVector<QString>>(QVector<QString>() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir() ? "1" : "0")));
|
||||||
if (event->mask & IN_ISDIR){
|
indexQueue->enqueue(QVector<QString>() << QString(event->name) << QString(currentPath[event->wd] + '/' + event->name) << QString((event->mask & IN_ISDIR) ? "1" : "0"));
|
||||||
AddWatch(currentPath[event->wd] + '/' + event->name);
|
IndexGenerator::getInstance()->creatAllIndex(indexQueue);
|
||||||
this->setPath(currentPath[event->wd] + '/' + event->name);
|
indexQueue->clear();
|
||||||
Traverse();
|
for (auto i : this->targetFileTypeVec){
|
||||||
|
if (QString(currentPath[event->wd] + '/' + event->name).endsWith(i)){
|
||||||
|
contentIndexQueue->enqueue(QString(currentPath[event->wd] + '/' + event->name));
|
||||||
|
IndexGenerator::getInstance()->creatAllIndex(contentIndexQueue);
|
||||||
|
contentIndexQueue->clear();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
goto next;
|
||||||
|
}
|
||||||
|
|
||||||
/*--------------------------------*/
|
|
||||||
// IndexGenerator::getInstance()->creatAllIndex(QQueue<QVector<QString>>(QVector<QString>() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir() ? "1" : "0")));
|
if ((event->mask & IN_DELETE) | (event->mask & IN_MOVED_FROM)){
|
||||||
|
if (event->mask & IN_ISDIR){
|
||||||
|
RemoveWatch(currentPath[event->wd] + '/' + event->name);
|
||||||
|
}
|
||||||
|
//delete once more
|
||||||
|
IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
|
||||||
|
goto next;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (event->mask & IN_MODIFY){
|
||||||
|
if (!(event->mask & IN_ISDIR)){
|
||||||
|
IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
|
||||||
indexQueue->enqueue(QVector<QString>() << QString(event->name) << QString(currentPath[event->wd] + '/' + event->name) << QString((event->mask & IN_ISDIR) ? "1" : "0"));
|
indexQueue->enqueue(QVector<QString>() << QString(event->name) << QString(currentPath[event->wd] + '/' + event->name) << QString((event->mask & IN_ISDIR) ? "1" : "0"));
|
||||||
IndexGenerator::getInstance()->creatAllIndex(indexQueue);
|
IndexGenerator::getInstance()->creatAllIndex(indexQueue);
|
||||||
indexQueue->clear();
|
indexQueue->clear();
|
||||||
|
@ -144,134 +156,101 @@ void InotifyIndex::run(){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
goto next;
|
|
||||||
}
|
}
|
||||||
|
goto next;
|
||||||
|
|
||||||
if ((event->mask & IN_DELETE) | (event->mask & IN_MOVED_FROM)){
|
|
||||||
if (event->mask & IN_ISDIR){
|
|
||||||
RemoveWatch(currentPath[event->wd] + '/' + event->name);
|
|
||||||
}
|
|
||||||
//delete once more
|
|
||||||
IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
|
|
||||||
goto next;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (event->mask & IN_MODIFY){
|
|
||||||
if (!(event->mask & IN_ISDIR)){
|
|
||||||
IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
|
|
||||||
indexQueue->enqueue(QVector<QString>() << QString(event->name) << QString(currentPath[event->wd] + '/' + event->name) << QString((event->mask & IN_ISDIR) ? "1" : "0"));
|
|
||||||
IndexGenerator::getInstance()->creatAllIndex(indexQueue);
|
|
||||||
indexQueue->clear();
|
|
||||||
for (auto i : this->targetFileTypeVec){
|
|
||||||
if (QString(currentPath[event->wd] + '/' + event->name).endsWith(i)){
|
|
||||||
contentIndexQueue->enqueue(QString(currentPath[event->wd] + '/' + event->name));
|
|
||||||
IndexGenerator::getInstance()->creatAllIndex(contentIndexQueue);
|
|
||||||
contentIndexQueue->clear();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
goto next;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (event->mask & IN_MOVED_TO){
|
|
||||||
if (event->mask & IN_ISDIR){
|
|
||||||
RemoveWatch(currentPath[event->wd] + '/' + event->name);
|
|
||||||
IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
|
|
||||||
AddWatch(currentPath[event->wd] + '/' + event->name);
|
|
||||||
this->setPath(currentPath[event->wd] + '/' + event->name);
|
|
||||||
Traverse();
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
indexQueue->enqueue(QVector<QString>() << QString(event->name) << QString(currentPath[event->wd] + '/' + event->name) << QString((event->mask & IN_ISDIR) ? "1" : "0"));
|
|
||||||
IndexGenerator::getInstance()->creatAllIndex(indexQueue);
|
|
||||||
indexQueue->clear();
|
|
||||||
for (auto i : this->targetFileTypeVec){
|
|
||||||
if (QString(currentPath[event->wd] + '/' + event->name).endsWith(i)){
|
|
||||||
contentIndexQueue->enqueue(QString(currentPath[event->wd] + '/' + event->name));
|
|
||||||
IndexGenerator::getInstance()->creatAllIndex(contentIndexQueue);
|
|
||||||
contentIndexQueue->clear();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
|
|
||||||
indexQueue->enqueue(QVector<QString>() << QString(event->name) << QString(currentPath[event->wd] + '/' + event->name) << QString((event->mask & IN_ISDIR) ? "1" : "0"));
|
|
||||||
IndexGenerator::getInstance()->creatAllIndex(indexQueue);
|
|
||||||
indexQueue->clear();
|
|
||||||
for (auto i : this->targetFileTypeVec){
|
|
||||||
if (QString(currentPath[event->wd] + '/' + event->name).endsWith(i)){
|
|
||||||
contentIndexQueue->enqueue(QString(currentPath[event->wd] + '/' + event->name));
|
|
||||||
IndexGenerator::getInstance()->creatAllIndex(contentIndexQueue);
|
|
||||||
contentIndexQueue->clear();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
goto next;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //传创建或移动过来的文件路径
|
|
||||||
// if((event->mask & IN_CREATE)){
|
|
||||||
// //添加监视要先序遍历,先添加top节点
|
|
||||||
// if (event->mask & IN_ISDIR){
|
|
||||||
// AddWatch(currentPath[event->wd] + '/' + event->name);
|
|
||||||
// this->setPath(currentPath[event->wd] + '/' + event->name);
|
|
||||||
// Traverse();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /*--------------------------------*/
|
|
||||||
//// IndexGenerator::getInstance()->creatAllIndex(QQueue<QVector<QString>>(QVector<QString>() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir() ? "1" : "0")));
|
|
||||||
// indexQueue->enqueue(QVector<QString>() << QString(event->name) << QString(currentPath[event->wd] + '/' + event->name) << QString((event->mask & IN_ISDIR) ? "1" : "0"));
|
|
||||||
// IndexGenerator::getInstance()->creatAllIndex(indexQueue);
|
|
||||||
// indexQueue->clear();
|
|
||||||
// for (auto i : this->targetFileTypeVec){
|
|
||||||
// if (QString(currentPath[event->wd] + '/' + event->name).endsWith(i)){
|
|
||||||
// contentIndexQueue->enqueue(QString(currentPath[event->wd] + '/' + event->name));
|
|
||||||
// IndexGenerator::getInstance()->creatAllIndex(contentIndexQueue);
|
|
||||||
// contentIndexQueue->clear();
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// /*--------------------------------*/
|
|
||||||
// }
|
|
||||||
// else if((event->mask & IN_DELETE) | (event->mask & IN_MOVED_FROM)){
|
|
||||||
// if (event->mask & IN_ISDIR){
|
|
||||||
// RemoveWatch(currentPath[event->wd] + '/' + event->name);
|
|
||||||
// }
|
|
||||||
// IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
|
|
||||||
// }
|
|
||||||
// else if((event->mask & IN_MODIFY) | (event->mask & IN_MOVED_TO)){
|
|
||||||
// if (!(event->mask & IN_ISDIR)){
|
|
||||||
// IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
|
|
||||||
// indexQueue->enqueue(QVector<QString>() << QString(event->name) << QString(currentPath[event->wd] + '/' + event->name) << QString((event->mask & IN_ISDIR) ? "1" : "0"));
|
|
||||||
// IndexGenerator::getInstance()->creatAllIndex(indexQueue);
|
|
||||||
// indexQueue->clear();
|
|
||||||
// for (auto i : this->targetFileTypeVec){
|
|
||||||
// if (QString(currentPath[event->wd] + '/' + event->name).endsWith(i)){
|
|
||||||
// contentIndexQueue->enqueue(QString(currentPath[event->wd] + '/' + event->name));
|
|
||||||
// IndexGenerator::getInstance()->creatAllIndex(contentIndexQueue);
|
|
||||||
// contentIndexQueue->clear();
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
/*--------------------------------*/
|
|
||||||
FileUtils::_index_status = FINISH_CREATING_INDEX;
|
|
||||||
}
|
}
|
||||||
next:
|
|
||||||
p += sizeof(struct inotify_event) + event->len;
|
|
||||||
|
if (event->mask & IN_MOVED_TO){
|
||||||
|
if (event->mask & IN_ISDIR){
|
||||||
|
RemoveWatch(currentPath[event->wd] + '/' + event->name);
|
||||||
|
IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
|
||||||
|
AddWatch(currentPath[event->wd] + '/' + event->name);
|
||||||
|
this->setPath(currentPath[event->wd] + '/' + event->name);
|
||||||
|
Traverse();
|
||||||
|
|
||||||
|
indexQueue->enqueue(QVector<QString>() << QString(event->name) << QString(currentPath[event->wd] + '/' + event->name) << QString((event->mask & IN_ISDIR) ? "1" : "0"));
|
||||||
|
IndexGenerator::getInstance()->creatAllIndex(indexQueue);
|
||||||
|
indexQueue->clear();
|
||||||
|
for (auto i : this->targetFileTypeVec){
|
||||||
|
if (QString(currentPath[event->wd] + '/' + event->name).endsWith(i)){
|
||||||
|
contentIndexQueue->enqueue(QString(currentPath[event->wd] + '/' + event->name));
|
||||||
|
IndexGenerator::getInstance()->creatAllIndex(contentIndexQueue);
|
||||||
|
contentIndexQueue->clear();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
|
||||||
|
indexQueue->enqueue(QVector<QString>() << QString(event->name) << QString(currentPath[event->wd] + '/' + event->name) << QString((event->mask & IN_ISDIR) ? "1" : "0"));
|
||||||
|
IndexGenerator::getInstance()->creatAllIndex(indexQueue);
|
||||||
|
indexQueue->clear();
|
||||||
|
for (auto i : this->targetFileTypeVec){
|
||||||
|
if (QString(currentPath[event->wd] + '/' + event->name).endsWith(i)){
|
||||||
|
contentIndexQueue->enqueue(QString(currentPath[event->wd] + '/' + event->name));
|
||||||
|
IndexGenerator::getInstance()->creatAllIndex(contentIndexQueue);
|
||||||
|
contentIndexQueue->clear();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
goto next;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// //传创建或移动过来的文件路径
|
||||||
|
// if((event->mask & IN_CREATE)){
|
||||||
|
// //添加监视要先序遍历,先添加top节点
|
||||||
|
// if (event->mask & IN_ISDIR){
|
||||||
|
// AddWatch(currentPath[event->wd] + '/' + event->name);
|
||||||
|
// this->setPath(currentPath[event->wd] + '/' + event->name);
|
||||||
|
// Traverse();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// /*--------------------------------*/
|
||||||
|
//// IndexGenerator::getInstance()->creatAllIndex(QQueue<QVector<QString>>(QVector<QString>() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir() ? "1" : "0")));
|
||||||
|
// indexQueue->enqueue(QVector<QString>() << QString(event->name) << QString(currentPath[event->wd] + '/' + event->name) << QString((event->mask & IN_ISDIR) ? "1" : "0"));
|
||||||
|
// IndexGenerator::getInstance()->creatAllIndex(indexQueue);
|
||||||
|
// indexQueue->clear();
|
||||||
|
// for (auto i : this->targetFileTypeVec){
|
||||||
|
// if (QString(currentPath[event->wd] + '/' + event->name).endsWith(i)){
|
||||||
|
// contentIndexQueue->enqueue(QString(currentPath[event->wd] + '/' + event->name));
|
||||||
|
// IndexGenerator::getInstance()->creatAllIndex(contentIndexQueue);
|
||||||
|
// contentIndexQueue->clear();
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// /*--------------------------------*/
|
||||||
|
// }
|
||||||
|
// else if((event->mask & IN_DELETE) | (event->mask & IN_MOVED_FROM)){
|
||||||
|
// if (event->mask & IN_ISDIR){
|
||||||
|
// RemoveWatch(currentPath[event->wd] + '/' + event->name);
|
||||||
|
// }
|
||||||
|
// IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
|
||||||
|
// }
|
||||||
|
// else if((event->mask & IN_MODIFY) | (event->mask & IN_MOVED_TO)){
|
||||||
|
// if (!(event->mask & IN_ISDIR)){
|
||||||
|
// IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
|
||||||
|
// indexQueue->enqueue(QVector<QString>() << QString(event->name) << QString(currentPath[event->wd] + '/' + event->name) << QString((event->mask & IN_ISDIR) ? "1" : "0"));
|
||||||
|
// IndexGenerator::getInstance()->creatAllIndex(indexQueue);
|
||||||
|
// indexQueue->clear();
|
||||||
|
// for (auto i : this->targetFileTypeVec){
|
||||||
|
// if (QString(currentPath[event->wd] + '/' + event->name).endsWith(i)){
|
||||||
|
// contentIndexQueue->enqueue(QString(currentPath[event->wd] + '/' + event->name));
|
||||||
|
// IndexGenerator::getInstance()->creatAllIndex(contentIndexQueue);
|
||||||
|
// contentIndexQueue->clear();
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
/*--------------------------------*/
|
||||||
|
FileUtils::_index_status = FINISH_CREATING_INDEX;
|
||||||
}
|
}
|
||||||
|
next:
|
||||||
|
p += sizeof(struct inotify_event) + event->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete indexQueue;
|
delete indexQueue;
|
||||||
|
@ -279,3 +258,59 @@ next:
|
||||||
delete contentIndexQueue;
|
delete contentIndexQueue;
|
||||||
contentIndexQueue = nullptr;
|
contentIndexQueue = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Symbolic Link!!!!!!!!!!!!!!!!!!
|
||||||
|
* Sysmbolic link to database dir will make a Infinite loop !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
* MouseZhangZh
|
||||||
|
*/
|
||||||
|
|
||||||
|
void InotifyIndex::run(){
|
||||||
|
char buf[BUF_LEN] __attribute__((aligned(8)));
|
||||||
|
|
||||||
|
ssize_t numRead;
|
||||||
|
|
||||||
|
for (;;) { /* Read events forever */
|
||||||
|
numRead = read(m_fd, buf, BUF_LEN);
|
||||||
|
|
||||||
|
|
||||||
|
pid_t pid;
|
||||||
|
pid = fork();
|
||||||
|
if(pid == 0)
|
||||||
|
{
|
||||||
|
prctl(PR_SET_NAME,"inotify-index");
|
||||||
|
if (numRead == 0) {
|
||||||
|
qDebug() << "read() from inotify fd returned 0!";
|
||||||
|
}
|
||||||
|
if (numRead == -1) {
|
||||||
|
qDebug() << "read";
|
||||||
|
}
|
||||||
|
eventProcess(buf, numRead);
|
||||||
|
QTimer* liveTime = new QTimer(this);
|
||||||
|
bool b_timeout = false;
|
||||||
|
liveTime->setInterval(30000);
|
||||||
|
connect(liveTime, &QTimer::timeout, this, [&](){
|
||||||
|
// _exit(0);
|
||||||
|
b_timeout = true;
|
||||||
|
});
|
||||||
|
liveTime->start();
|
||||||
|
for (;;){
|
||||||
|
numRead = read(m_fd, buf, BUF_LEN);
|
||||||
|
liveTime->stop();
|
||||||
|
this->eventProcess(buf, numRead);
|
||||||
|
if (b_timeout){
|
||||||
|
_exit(0);
|
||||||
|
}
|
||||||
|
liveTime->start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (pid > 0){
|
||||||
|
memset(buf, 0x00, BUF_LEN);
|
||||||
|
waitpid(pid, NULL, 0);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define INOTIFYINDEX_H
|
#define INOTIFYINDEX_H
|
||||||
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
#include <QTimer>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/inotify.h>
|
#include <sys/inotify.h>
|
||||||
#include "index-generator.h"
|
#include "index-generator.h"
|
||||||
|
@ -9,6 +10,7 @@
|
||||||
#include "ukui-search-qdbus.h"
|
#include "ukui-search-qdbus.h"
|
||||||
#include "global-settings.h"
|
#include "global-settings.h"
|
||||||
#include "file-utils.h"
|
#include "file-utils.h"
|
||||||
|
#include "first-index.h"
|
||||||
|
|
||||||
#define BUF_LEN 1024
|
#define BUF_LEN 1024
|
||||||
class InotifyIndex;
|
class InotifyIndex;
|
||||||
|
@ -29,6 +31,8 @@ public:
|
||||||
bool AddWatch(const QString&);
|
bool AddWatch(const QString&);
|
||||||
bool RemoveWatch(const QString&);
|
bool RemoveWatch(const QString&);
|
||||||
virtual void DoSomething(const QFileInfo &) final;
|
virtual void DoSomething(const QFileInfo &) final;
|
||||||
|
|
||||||
|
void eventProcess(const char*, ssize_t);
|
||||||
protected:
|
protected:
|
||||||
void run() override;
|
void run() override;
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QSemaphore>
|
||||||
#include "qt-single-application.h"
|
#include "qt-single-application.h"
|
||||||
#include "qt-local-peer.h"
|
#include "qt-local-peer.h"
|
||||||
//#include "inotify-manager.h"
|
//#include "inotify-manager.h"
|
||||||
|
@ -185,6 +186,7 @@ int main(int argc, char *argv[])
|
||||||
// FirstIndex* fi = new FirstIndex("/home/zhangzihao/Desktop/qwerty");
|
// FirstIndex* fi = new FirstIndex("/home/zhangzihao/Desktop/qwerty");
|
||||||
FirstIndex fi("/home");
|
FirstIndex fi("/home");
|
||||||
fi.start();
|
fi.start();
|
||||||
|
fi.wait();
|
||||||
// fi->wait();
|
// fi->wait();
|
||||||
// fi->exit();
|
// fi->exit();
|
||||||
// delete fi;
|
// delete fi;
|
||||||
|
|
Loading…
Reference in New Issue