Merge pull request #162 from MouseZhangZh/main

[Fix]Index process may crash while system first boot;
This commit is contained in:
张佳萍 2021-03-08 14:39:44 +08:00 committed by GitHub
commit 8fb9eb38c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 26 deletions

View File

@ -27,16 +27,12 @@
//extern QList<Document> *_doc_list_path;
//extern QMutex _mutex_doc_list_path;
ConstructDocumentForPath::ConstructDocumentForPath(QVector<QString> list, IndexGenerator *parent)
ConstructDocumentForPath::ConstructDocumentForPath(QVector<QString> list)
{
this->setAutoDelete(true);
m_list = std::move(list);
}
ConstructDocumentForPath::~ConstructDocumentForPath()
{
}
void ConstructDocumentForPath::run()
{
// qDebug()<<"ConstructDocumentForPath";
@ -103,17 +99,12 @@ void ConstructDocumentForPath::run()
return;
}
ConstructDocumentForContent::ConstructDocumentForContent(QString path,QObject *parent)
ConstructDocumentForContent::ConstructDocumentForContent(QString path)
{
this->setAutoDelete(true);
m_path = std::move(path);
}
ConstructDocumentForContent::~ConstructDocumentForContent()
{
}
void ConstructDocumentForContent::run()
{
// qDebug() << "ConstructDocumentForContent currentThreadId()" << QThread::currentThreadId();

View File

@ -31,28 +31,23 @@ class IndexGenerator;
class ConstructDocumentForPath : public QRunnable
{
public:
explicit ConstructDocumentForPath(QVector<QString> list,IndexGenerator *parent = nullptr);
~ConstructDocumentForPath();
explicit ConstructDocumentForPath(QVector<QString> list);
~ConstructDocumentForPath() = default;
protected:
void run();
private:
QVector<QString> m_list;
};
class ConstructDocumentForContent : public QObject, public QRunnable
class ConstructDocumentForContent : public QRunnable
{
Q_OBJECT
public:
explicit ConstructDocumentForContent(QString path,QObject *parent = nullptr);
~ConstructDocumentForContent();
explicit ConstructDocumentForContent(QString path);
~ConstructDocumentForContent() = default;
protected:
void run();
private:
QString m_path;
};
#endif // CONSTRUCTDOCUMENT_H

View File

@ -160,7 +160,8 @@ void FirstIndex::run(){
QtConcurrent::run([&](){
sem.acquire(2);
mutex3.unlock();
QQueue<QString>* tmp = new QQueue<QString>();;
QQueue<QString>* tmp = new QQueue<QString>();
qDebug()<<"q_content_index:"<<q_content_index->size();
while (!this->q_content_index->empty()) {
// for (size_t i = 0; (i < this->u_send_length) && (!this->q_content_index->empty()); ++i){
for (size_t i = 0; (i < 30) && (!this->q_content_index->empty()); ++i){

View File

@ -63,7 +63,11 @@ bool IndexGenerator::setIndexdataPath()
bool IndexGenerator::creatAllIndex(QQueue<QVector<QString> > *messageList)
{
// FileUtils::_index_status |= 0x1;
// qDebug() << messageList->size();
HandlePathList(messageList);
if (_doc_list_path == NULL){
return false;
}
qDebug()<<"begin creatAllIndex";
GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE,"0");
try
@ -75,6 +79,7 @@ bool IndexGenerator::creatAllIndex(QQueue<QVector<QString> > *messageList)
// m_indexer.set_stemming_strategy(Xapian::TermGenerator::STEM_SOME);
// int count =0;
for (auto i : *_doc_list_path){
insertIntoDatabase(i);
@ -107,6 +112,9 @@ bool IndexGenerator::creatAllIndex(QQueue<QString> *messageList)
// FileUtils::_index_status |= 0x2;
HandlePathList(messageList);
qDebug()<<"begin creatAllIndex for content";
if (_doc_list_content == NULL){
return false;
}
int size = _doc_list_content->size();
if(!size == 0)
{
@ -260,8 +268,8 @@ void IndexGenerator::HandlePathList(QQueue<QVector<QString>> *messageList)
// delete constructer;
// constructer = nullptr;
qDebug()<<_doc_list_path->size();
// qDebug()<<_doc_list_path->size();
// qWarning() << _doc_list_path;
// QList<Document> docList = future.results();
// m_doc_list_path = new QList<Document>(docList);
// m_doc_list_path = std::move(future.results());
@ -299,7 +307,9 @@ void IndexGenerator::HandlePathList(QQueue<QString> *messageList)
// QList<Document> docList = future.results();
// m_doc_list_content = new QList<Document>(docList);
qDebug()<<_doc_list_content->size();
// qDebug()<<_doc_list_content->size();
// QList<Document> docList = future.results();
// m_doc_list_content = new QList<Document>(docList);
// m_doc_list_content = std::move(future.results());

View File

@ -44,5 +44,5 @@ void UkuiSearchQDBus::setInotifyMaxUserWatches()
// sysctl
this->tmpSystemQDBusInterface->call("setInotifyMaxUserWatchesStep2");
// /etc/sysctl.conf
this->tmpSystemQDBusInterface->call("setInotifyMaxUserWatchesStep3");
// this->tmpSystemQDBusInterface->call("setInotifyMaxUserWatchesStep3");
}

View File

@ -124,6 +124,27 @@ void centerToScreen(QWidget* widget) {
int main(int argc, char *argv[])
{
char *p_home = NULL;
unsigned int i = 0;
while(p_home == NULL)
{
::sleep(1);
++i;
p_home = getenv("HOME");
if(i%5==0)
{
qWarning()<<"I can't find home! I'm done here!!";
printf("I can't find home! I'm done here!!");
}
}
p_home = NULL;
while(!QDir(QDir::homePath()).exists())
{
qWarning()<<"Home not exits!!";
printf("Home not exits!!");
::sleep(1);
}
unlink(UKUI_SEARCH_PIPE_PATH);
int retval = mkfifo(UKUI_SEARCH_PIPE_PATH, 0777);
if(retval == -1)
@ -247,6 +268,7 @@ int main(int argc, char *argv[])
// FirstIndex fi("/home/zhangzihao/Desktop/qwerty");
// FirstIndex* fi = new FirstIndex("/home/zhangzihao/Desktop/qwerty");
FirstIndex fi("/home/zhangzihao/Desktop");
fi.start();
// fi.wait();