Add switch search method.

This commit is contained in:
Mouse Zhang 2021-04-16 16:09:50 +08:00
parent ffb51b9d17
commit fd9a19ecae
4 changed files with 42 additions and 8 deletions

View File

@ -27,6 +27,22 @@
FirstIndex::FirstIndex(const QString& path) : Traverse_BFS(path)
{
// Create a fifo at ~/.config/org.ukui/ukui-search, the fifo is used to control the order of child processes' running.
QDir fifoDir = QDir(QDir::homePath()+"/.config/org.ukui/ukui-search");
if(!fifoDir.exists())
qDebug()<<"create fifo path"<<fifoDir.mkpath(fifoDir.absolutePath());
unlink(UKUI_SEARCH_PIPE_PATH);
int retval = mkfifo(UKUI_SEARCH_PIPE_PATH, 0777);
if(retval == -1)
{
qCritical()<<"creat fifo error!!";
syslog(LOG_ERR,"creat fifo error!!\n");
assert(false);
return;
}
qDebug()<<"create fifo success\n";
QString indexDataBaseStatus = GlobalSettings::getInstance()->getValue(INDEX_DATABASE_STATE).toString();
QString contentIndexDataBaseStatus = GlobalSettings::getInstance()->getValue(CONTENT_INDEX_DATABASE_STATE).toString();
QString inotifyIndexStatus = GlobalSettings::getInstance()->getValue(INOTIFY_NORMAL_EXIT).toString();

View File

@ -34,6 +34,7 @@
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/prctl.h>
#include <syslog.h>
//#include <QtConcurrent>
#include "traverse_bfs.h"
#include "global-settings.h"

View File

@ -256,8 +256,8 @@ void InotifyIndex::run(){
ssize_t numRead;
for (;;) { /* Read events forever */
read:
while (!isInterruptionRequested()) {
// for (;;) { /* Read events forever */
memset(buf, 0x00, BUF_LEN);
numRead = read(m_fd, buf, BUF_LEN);
@ -276,14 +276,14 @@ read:
// qDebug() << "Read Event: " << currentPath[event->wd] << QString(event->name) << event->cookie << event->wd << event->mask;
if(event->name[0] != '.'){
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "0");
goto fork;
break;
}
tmp += sizeof(struct inotify_event) + event->len;
}
goto read;
if (tmp >= buf + numRead) {
continue;
}
fork:
++FileUtils::_index_status;
pid_t pid;

View File

@ -118,6 +118,23 @@ void centerToScreen(QWidget* widget) {
widget->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top());
}
void searchMethod(FileUtils::SearchMethod sm){
if (FileUtils::SearchMethod::INDEXSEARCH == sm || FileUtils::SearchMethod::DIRECTSEARCH == sm){
FileUtils::searchMethod = sm;
} else {
printf("enum class error!!!\n");
qWarning("enum class error!!!\n");
}
if (FileUtils::SearchMethod::INDEXSEARCH == sm) {
FirstIndex fi("/home/zhangzihao/Desktop");
fi.start();
InotifyIndex* ii = InotifyIndex::getInstance("/home");
ii->start();
} else if (FileUtils::SearchMethod::DIRECTSEARCH == sm) {
InotifyIndex::getInstance("/home")->requestInterruption();
}
}
int main(int argc, char *argv[])
{
// Determine whether the home directory has been created, and if not, keep waiting.
@ -178,7 +195,7 @@ int main(int argc, char *argv[])
parser.addOptions({debugOption, showsearch});
parser.process(app);
}*/
/*
// Create a fifo at ~/.config/org.ukui/ukui-search, the fifo is used to control the order of child processes' running.
QDir fifoDir = QDir(QDir::homePath()+"/.config/org.ukui/ukui-search");
if(!fifoDir.exists())
@ -194,7 +211,7 @@ int main(int argc, char *argv[])
return -1;
}
qDebug()<<"create fifo success\n";
*/
// Set max_user_watches to a number which is enough big.
UkuiSearchQDBus usQDBus;
usQDBus.setInotifyMaxUserWatches();