From 8661d1393b0c9cf11869a0c9a0982304c345c69b Mon Sep 17 00:00:00 2001 From: iaom Date: Mon, 11 Apr 2022 17:46:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E4=B8=80=E5=A4=84?= =?UTF-8?q?=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;