Merge branch 'ukss-dev' into 'ukss-dev'
修复索引关闭时取消监听不完全的问题。 See merge request kylin-desktop/ukui-search!285
This commit is contained in:
commit
122efbc724
|
@ -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,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 : m_pathMap) {
|
||||
inotify_rm_watch(m_inotifyFd, m_pathMap.key(path));
|
||||
}
|
||||
m_pathMap.clear();
|
||||
}
|
||||
close(m_inotifyFd);
|
||||
// fcntl(m_inotifyFd, F_SETFD, FD_CLOEXEC);
|
||||
|
@ -268,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();
|
||||
|
@ -303,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);
|
||||
|
@ -386,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) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue