diff --git a/libsearch/index/first-index.cpp b/libsearch/index/first-index.cpp index 878593b..6d5a8bc 100644 --- a/libsearch/index/first-index.cpp +++ b/libsearch/index/first-index.cpp @@ -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"<getValue(INDEX_DATABASE_STATE).toString(); QString contentIndexDataBaseStatus = GlobalSettings::getInstance()->getValue(CONTENT_INDEX_DATABASE_STATE).toString(); QString inotifyIndexStatus = GlobalSettings::getInstance()->getValue(INOTIFY_NORMAL_EXIT).toString(); diff --git a/libsearch/index/first-index.h b/libsearch/index/first-index.h index 2d90ba9..a7af436 100644 --- a/libsearch/index/first-index.h +++ b/libsearch/index/first-index.h @@ -34,6 +34,7 @@ #include #include #include +#include //#include #include "traverse_bfs.h" #include "global-settings.h" diff --git a/libsearch/index/inotify-index.cpp b/libsearch/index/inotify-index.cpp index fa7ae2b..2f44bc6 100644 --- a/libsearch/index/inotify-index.cpp +++ b/libsearch/index/inotify-index.cpp @@ -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; diff --git a/src/main.cpp b/src/main.cpp index 9bd7055..4aaa3a2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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();