diff --git a/libsearch/file-utils.cpp b/libsearch/file-utils.cpp index c6fdacd..f6f8e50 100644 --- a/libsearch/file-utils.cpp +++ b/libsearch/file-utils.cpp @@ -483,8 +483,10 @@ void FileUtils::getDocxTextContent(QString &path, QString &textcontent) { if(!file.open(QuaZip::mdUnzip)) return; - if(!file.setCurrentFile("word/document.xml", QuaZip::csSensitive)) + if(!file.setCurrentFile("word/document.xml", QuaZip::csSensitive)) { + file.close(); return; + } QuaZipFile fileR(&file); fileR.open(QIODevice::ReadOnly); //读取方式打开 @@ -545,8 +547,10 @@ void FileUtils::getPptxTextContent(QString &path, QString &textcontent) { if(i.startsWith(prefix)) fileList << i; } - if(fileList.isEmpty()) + if(fileList.isEmpty()) { + file.close(); return; + } for(int i = 0; i < fileList.size(); ++i){ QString name = prefix + QString::number(i + 1) + ".xml"; @@ -650,8 +654,10 @@ void FileUtils::getXlsxTextContent(QString &path, QString &textcontent) { if(!file.open(QuaZip::mdUnzip)) return; - if(!file.setCurrentFile("xl/sharedStrings.xml", QuaZip::csSensitive)) + if(!file.setCurrentFile("xl/sharedStrings.xml", QuaZip::csSensitive)) { + file.close(); return; + } QuaZipFile fileR(&file); fileR.open(QIODevice::ReadOnly); @@ -706,8 +712,10 @@ void FileUtils::getXlsxTextContent(QString &path, QString &textcontent) { void FileUtils::getPdfTextContent(QString &path, QString &textcontent) { Poppler::Document *doc = Poppler::Document::load(path); - if(doc->isLocked()) + if(doc->isLocked()) { + delete doc; return; + } const QRectF qf; int pageNum = doc->numPages(); for(int i = 0; i < pageNum; ++i) { diff --git a/libsearch/index/inotify-watch.cpp b/libsearch/index/inotify-watch.cpp index 9ffdc5f..3cd7f6b 100644 --- a/libsearch/index/inotify-watch.cpp +++ b/libsearch/index/inotify-watch.cpp @@ -1,6 +1,7 @@ #include "inotify-watch.h" #include #include +#include using namespace Zeeker; static InotifyWatch* global_instance_InotifyWatch = nullptr; @@ -65,7 +66,7 @@ bool InotifyWatch::removeWatch(const QString &path, bool removeFromDatabase) // qDebug() << i.value(); if(i.value().length() > path.length()) { if(i.value().startsWith(path)) { - qDebug() << "remove path: " << i.value(); +// qDebug() << "remove path: " << i.value(); inotify_rm_watch(m_inotifyFd, currentPath.key(path)); currentPath.erase(i++); } else { @@ -132,6 +133,8 @@ void InotifyWatch::run() if (m_inotifyFd > 0) { qDebug()<<"Inotify init success!"; } else { + printf("errno=%d\n",errno); + printf("Mesg:%s\n",strerror(errno)); Q_ASSERT_X(0, "InotifyWatch", "Failed to initialize inotify"); } @@ -205,10 +208,12 @@ void InotifyWatch::run() assert(false); } } + qDebug() << "Leave watch loop"; if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) { IndexStatusRecorder::getInstance()->setStatus(INOTIFY_NORMAL_EXIT, "3"); removeWatch(QStandardPaths::writableLocation(QStandardPaths::HomeLocation), false); } + close(m_inotifyFd); // fcntl(m_inotifyFd, F_SETFD, FD_CLOEXEC); // m_notifier = new QSocketNotifier(m_inotifyFd, QSocketNotifier::Read); // connect(m_notifier, &QSocketNotifier::activated, this, &InotifyWatch::slotEvent, Qt::DirectConnection); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2c593da..cf80e43 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -129,6 +129,8 @@ MainWindow::MainWindow(QWidget *parent) : this->m_searchLayout->focusIn(); //打开主界面时输入框夺焦,可直接输入 this->raise(); this->activateWindow(); + } else if(this->isVisible()&&!this->isActiveWindow()) { + this->activateWindow(); } else { tryHideMainwindow(); }