修改了一处命名。

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;
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<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();
// 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<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();
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) {

View File

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