From 1135c48abf1947006edbd55727807f62e89c1ba0 Mon Sep 17 00:00:00 2001 From: iaom Date: Sat, 9 Apr 2022 17:32:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E6=97=B6=E5=8F=96=E6=B6=88=E7=9B=91=E5=90=AC?= =?UTF-8?q?=E4=B8=8D=E5=AE=8C=E5=85=A8=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libsearch/index/inotify-watch.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libsearch/index/inotify-watch.cpp b/libsearch/index/inotify-watch.cpp index d28678c..a7f7ce7 100644 --- a/libsearch/index/inotify-watch.cpp +++ b/libsearch/index/inotify-watch.cpp @@ -225,7 +225,10 @@ void InotifyWatch::run() qDebug() << "Leave watch loop"; if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) { IndexStatusRecorder::getInstance()->setStatus(INOTIFY_NORMAL_EXIT, "3"); - removeWatch(QStandardPaths::writableLocation(QStandardPaths::HomeLocation), false); + for(QString path : currentPath) { + inotify_rm_watch(m_inotifyFd, currentPath.key(path)); + } + currentPath.clear(); } close(m_inotifyFd); // fcntl(m_inotifyFd, F_SETFD, FD_CLOEXEC); From 8661d1393b0c9cf11869a0c9a0982304c345c69b Mon Sep 17 00:00:00 2001 From: iaom Date: Mon, 11 Apr 2022 17:46:13 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E5=A4=84=E5=91=BD=E5=90=8D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libsearch/index/inotify-watch.cpp | 30 +++++++++++++++--------------- libsearch/index/inotify-watch.h | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/libsearch/index/inotify-watch.cpp b/libsearch/index/inotify-watch.cpp index a7f7ce7..4fb33c8 100644 --- a/libsearch/index/inotify-watch.cpp +++ b/libsearch/index/inotify-watch.cpp @@ -37,40 +37,40 @@ bool InotifyWatch::addWatch(const QString &path) qWarning() << "AddWatch error:" << path; return false; } - currentPath[ret] = path; + m_pathMap[ret] = path; // qDebug() << "Watch: " << path << "ret: " << ret; return true; } bool InotifyWatch::removeWatch(const QString &path, bool removeFromDatabase) { - inotify_rm_watch(m_inotifyFd, currentPath.key(path)); + inotify_rm_watch(m_inotifyFd, m_pathMap.key(path)); if(removeFromDatabase) { - for(QMap::Iterator i = currentPath.begin(); i != currentPath.end();) { + for(QMap::Iterator i = m_pathMap.begin(); i != m_pathMap.end();) { // qDebug() << i.value(); // if(i.value().length() > path.length()) { if(FileUtils::isOrUnder(i.value(), path)) { qDebug() << "remove path: " << i.value(); - inotify_rm_watch(m_inotifyFd, currentPath.key(path)); + inotify_rm_watch(m_inotifyFd, m_pathMap.key(path)); PendingFile f(i.value()); f.setDeleted(); f.setIsDir(); PendingFileQueue::getInstance()->enqueue(f); - currentPath.erase(i++); + m_pathMap.erase(i++); } else { i++; } } } else { - for(QMap::Iterator i = currentPath.begin(); i != currentPath.end();) { + for(QMap::Iterator i = m_pathMap.begin(); i != m_pathMap.end();) { // qDebug() << i.value(); if(i.value().length() > path.length()) { if(FileUtils::isOrUnder(i.value(), path)) { // if(i.value().startsWith(path + "/")) { // qDebug() << "remove path: " << i.value(); - inotify_rm_watch(m_inotifyFd, currentPath.key(path)); - currentPath.erase(i++); + inotify_rm_watch(m_inotifyFd, m_pathMap.key(path)); + m_pathMap.erase(i++); } else { i++; } @@ -79,7 +79,7 @@ bool InotifyWatch::removeWatch(const QString &path, bool removeFromDatabase) } } } - currentPath.remove(currentPath.key(path)); + m_pathMap.remove(m_pathMap.key(path)); return true; } @@ -225,10 +225,10 @@ void InotifyWatch::run() qDebug() << "Leave watch loop"; if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) { IndexStatusRecorder::getInstance()->setStatus(INOTIFY_NORMAL_EXIT, "3"); - for(QString path : currentPath) { - inotify_rm_watch(m_inotifyFd, currentPath.key(path)); + for(QString path : m_pathMap) { + inotify_rm_watch(m_inotifyFd, m_pathMap.key(path)); } - currentPath.clear(); + m_pathMap.clear(); } close(m_inotifyFd); // fcntl(m_inotifyFd, F_SETFD, FD_CLOEXEC); @@ -271,7 +271,7 @@ void InotifyWatch::slotEvent(char *buf, ssize_t len) m_sharedMemory->detach(); } buffer.open(QBuffer::ReadWrite); - out << currentPath; + out << m_pathMap; int size = buffer.size(); if (!m_sharedMemory->create(size)) { qDebug() << "Create sharedMemory Error: " << m_sharedMemory->errorString(); @@ -306,7 +306,7 @@ void InotifyWatch::slotEvent(char *buf, ssize_t len) in >> pathMap; m_sharedMemory->unlock(); m_sharedMemory->detach(); - currentPath = pathMap; + m_pathMap = pathMap; } } else { assert(false); @@ -389,7 +389,7 @@ void InotifyWatch::eventProcess(const char *buffer, ssize_t len) // qDebug() << "Read Event: " << currentPath[event->wd] << QString(event->name) << event->cookie << event->wd << event->mask; // qDebug("mask:0x%x,",event->mask); if(event->name[0] != '.') { - QString path = currentPath[event->wd] + '/' + event->name; + QString path = m_pathMap[event->wd] + '/' + event->name; //过滤黑名单下的信号 for(QString i : m_blockList) { diff --git a/libsearch/index/inotify-watch.h b/libsearch/index/inotify-watch.h index 919a862..ad72bbe 100644 --- a/libsearch/index/inotify-watch.h +++ b/libsearch/index/inotify-watch.h @@ -45,7 +45,7 @@ private: int m_inotifyFd; QSocketNotifier* m_notifier = nullptr; QSharedMemory *m_sharedMemory = nullptr; - QMap currentPath; + QMap m_pathMap; QMutex m_mutex;