修改了一处命名。

This commit is contained in:
iaom 2022-04-11 17:46:13 +08:00
parent 1135c48abf
commit 8661d1393b
2 changed files with 16 additions and 16 deletions

View File

@ -37,40 +37,40 @@ bool InotifyWatch::addWatch(const QString &path)
qWarning() << "AddWatch error:" << path; qWarning() << "AddWatch error:" << path;
return false; return false;
} }
currentPath[ret] = path; m_pathMap[ret] = path;
// qDebug() << "Watch: " << path << "ret: " << ret; // qDebug() << "Watch: " << path << "ret: " << ret;
return true; return true;
} }
bool InotifyWatch::removeWatch(const QString &path, bool removeFromDatabase) 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) { if(removeFromDatabase) {
for(QMap<int, QString>::Iterator i = currentPath.begin(); i != currentPath.end();) { for(QMap<int, QString>::Iterator i = m_pathMap.begin(); i != m_pathMap.end();) {
// qDebug() << i.value(); // qDebug() << i.value();
// if(i.value().length() > path.length()) { // if(i.value().length() > path.length()) {
if(FileUtils::isOrUnder(i.value(), path)) { if(FileUtils::isOrUnder(i.value(), path)) {
qDebug() << "remove path: " << i.value(); 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()); PendingFile f(i.value());
f.setDeleted(); f.setDeleted();
f.setIsDir(); f.setIsDir();
PendingFileQueue::getInstance()->enqueue(f); PendingFileQueue::getInstance()->enqueue(f);
currentPath.erase(i++); m_pathMap.erase(i++);
} else { } else {
i++; i++;
} }
} }
} else { } else {
for(QMap<int, QString>::Iterator i = currentPath.begin(); i != currentPath.end();) { for(QMap<int, QString>::Iterator i = m_pathMap.begin(); i != m_pathMap.end();) {
// qDebug() << i.value(); // qDebug() << i.value();
if(i.value().length() > path.length()) { if(i.value().length() > path.length()) {
if(FileUtils::isOrUnder(i.value(), path)) { if(FileUtils::isOrUnder(i.value(), path)) {
// if(i.value().startsWith(path + "/")) { // if(i.value().startsWith(path + "/")) {
// qDebug() << "remove path: " << i.value(); // qDebug() << "remove path: " << i.value();
inotify_rm_watch(m_inotifyFd, currentPath.key(path)); inotify_rm_watch(m_inotifyFd, m_pathMap.key(path));
currentPath.erase(i++); m_pathMap.erase(i++);
} else { } else {
i++; 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; return true;
} }
@ -225,10 +225,10 @@ void InotifyWatch::run()
qDebug() << "Leave watch loop"; qDebug() << "Leave watch loop";
if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) { if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) {
IndexStatusRecorder::getInstance()->setStatus(INOTIFY_NORMAL_EXIT, "3"); IndexStatusRecorder::getInstance()->setStatus(INOTIFY_NORMAL_EXIT, "3");
for(QString path : currentPath) { for(QString path : m_pathMap) {
inotify_rm_watch(m_inotifyFd, currentPath.key(path)); inotify_rm_watch(m_inotifyFd, m_pathMap.key(path));
} }
currentPath.clear(); m_pathMap.clear();
} }
close(m_inotifyFd); close(m_inotifyFd);
// fcntl(m_inotifyFd, F_SETFD, FD_CLOEXEC); // fcntl(m_inotifyFd, F_SETFD, FD_CLOEXEC);
@ -271,7 +271,7 @@ void InotifyWatch::slotEvent(char *buf, ssize_t len)
m_sharedMemory->detach(); m_sharedMemory->detach();
} }
buffer.open(QBuffer::ReadWrite); buffer.open(QBuffer::ReadWrite);
out << currentPath; out << m_pathMap;
int size = buffer.size(); int size = buffer.size();
if (!m_sharedMemory->create(size)) { if (!m_sharedMemory->create(size)) {
qDebug() << "Create sharedMemory Error: " << m_sharedMemory->errorString(); qDebug() << "Create sharedMemory Error: " << m_sharedMemory->errorString();
@ -306,7 +306,7 @@ void InotifyWatch::slotEvent(char *buf, ssize_t len)
in >> pathMap; in >> pathMap;
m_sharedMemory->unlock(); m_sharedMemory->unlock();
m_sharedMemory->detach(); m_sharedMemory->detach();
currentPath = pathMap; m_pathMap = pathMap;
} }
} else { } else {
assert(false); 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() << "Read Event: " << currentPath[event->wd] << QString(event->name) << event->cookie << event->wd << event->mask;
// qDebug("mask:0x%x,",event->mask); // qDebug("mask:0x%x,",event->mask);
if(event->name[0] != '.') { if(event->name[0] != '.') {
QString path = currentPath[event->wd] + '/' + event->name; QString path = m_pathMap[event->wd] + '/' + event->name;
//过滤黑名单下的信号 //过滤黑名单下的信号
for(QString i : m_blockList) { for(QString i : m_blockList) {

View File

@ -45,7 +45,7 @@ private:
int m_inotifyFd; int m_inotifyFd;
QSocketNotifier* m_notifier = nullptr; QSocketNotifier* m_notifier = nullptr;
QSharedMemory *m_sharedMemory = nullptr; QSharedMemory *m_sharedMemory = nullptr;
QMap<int, QString> currentPath; QMap<int, QString> m_pathMap;
QMutex m_mutex; QMutex m_mutex;