feat(file-watcher):文件可读权限发生改变后更新索引
This commit is contained in:
parent
7d59fd81fd
commit
497eec01c8
|
@ -23,7 +23,7 @@
|
|||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <cerrno>
|
||||
#include <QDir>
|
||||
#include <QQueue>
|
||||
#include <QtConcurrentRun>
|
||||
|
@ -360,6 +360,22 @@ void FileSystemWatcher::eventProcess(int socket)
|
|||
if (event->mask & EventAttributeChange) {
|
||||
// qDebug() << path << "--EventAttributeChange";
|
||||
Q_EMIT attributeChanged(path);
|
||||
if (event->mask & IN_ISDIR) {
|
||||
QFileInfo info(path);
|
||||
if(!info.isReadable() || !info.isExecutable()) {
|
||||
for(const QString &removedPath : d->removeWatch(path)) {
|
||||
Q_EMIT accessibleChanged(removedPath, true, false);
|
||||
}
|
||||
} else {
|
||||
if (!d->m_watchPathHash.values().contains(path)) {
|
||||
for(const QString &createdPath : traverse(path)) {
|
||||
Q_EMIT accessibleChanged(createdPath, QFileInfo(createdPath).isDir(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Q_EMIT accessibleChanged(path, false, QFileInfo(path).isReadable());
|
||||
}
|
||||
}
|
||||
if (event->mask & EventAccess) {
|
||||
// qDebug() << path << "--EventAccess";
|
||||
|
|
|
@ -158,7 +158,10 @@ Q_SIGNALS:
|
|||
* Note:if the new file moved here overwrited a file already existed, there will not be a 'deleted' signal.
|
||||
*/
|
||||
void moveTo(const QString& path, bool isDir);
|
||||
|
||||
/**
|
||||
* Emitted when the current user's file permissions changed(FileSystemWatcher::EventAttributeChange)
|
||||
*/
|
||||
void accessibleChanged(const QString& path, bool isDir, bool accessable);
|
||||
private Q_SLOTS:
|
||||
void eventProcess(int socket);
|
||||
QStringList traverse(QString &path);
|
||||
|
|
|
@ -22,17 +22,23 @@ using namespace UkuiSearch;
|
|||
FileWatcher::FileWatcher(QObject *parent) : QObject(parent), m_config(FileIndexerConfig::getInstance())
|
||||
{
|
||||
qRegisterMetaType<QVector<PendingFile>>("QVector<PendingFile>");
|
||||
m_watcher = new FileSystemWatcher();
|
||||
m_pendingFileQUeue = PendingFileQueue::getInstance();
|
||||
m_watcher = new FileSystemWatcher(true,
|
||||
FileSystemWatcher::WatchEvents(FileSystemWatcher::EventMove | FileSystemWatcher::EventMoveSelf |
|
||||
FileSystemWatcher::EventCreate | FileSystemWatcher::EventDelete |
|
||||
FileSystemWatcher::EventDeleteSelf | FileSystemWatcher::EventUnmount |
|
||||
FileSystemWatcher::EventModify | FileSystemWatcher::EventAttributeChange),
|
||||
FileSystemWatcher::WatchFlags(), nullptr);
|
||||
m_pendingFileQueue = PendingFileQueue::getInstance();
|
||||
|
||||
connect(m_watcher, &FileSystemWatcher::created, this, &FileWatcher::onFileCreated);
|
||||
connect(m_watcher, &FileSystemWatcher::moveTo, this, &FileWatcher::onFileMoveTo);
|
||||
connect(m_watcher, &FileSystemWatcher::modified, this, &FileWatcher::onFileModefied);
|
||||
connect(m_watcher, &FileSystemWatcher::modified, this, &FileWatcher::onFileModified);
|
||||
connect(m_watcher, &FileSystemWatcher::deleted, this, &FileWatcher::onFileDeletedOrMoved);
|
||||
connect(m_watcher, &FileSystemWatcher::moved, this, &FileWatcher::onFileDeletedOrMoved);
|
||||
connect(m_watcher, &FileSystemWatcher::unmounted, this, &FileWatcher::onFileDeletedOrMoved);
|
||||
connect(m_watcher, &FileSystemWatcher::accessibleChanged, this, &FileWatcher::onFileAccessibleChanged);
|
||||
|
||||
connect(m_pendingFileQUeue, &PendingFileQueue::filesUpdate, this, &FileWatcher::filesUpdate);
|
||||
connect(m_pendingFileQueue, &PendingFileQueue::filesUpdate, this, &FileWatcher::filesUpdate);
|
||||
}
|
||||
|
||||
FileWatcher::~FileWatcher()
|
||||
|
@ -56,7 +62,7 @@ void FileWatcher::removeWatch(const QString &path, bool updateIndex)
|
|||
PendingFile file(pathToDelete);
|
||||
file.setIsDir();
|
||||
file.setDeleted();
|
||||
m_pendingFileQUeue->enqueue(file);
|
||||
m_pendingFileQueue->enqueue(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +83,7 @@ void FileWatcher::onFileDeletedOrMoved(const QString &path, bool isDir)
|
|||
PendingFile file(path);
|
||||
file.setIsDir(isDir);
|
||||
file.setDeleted();
|
||||
m_pendingFileQUeue->enqueue(file);
|
||||
m_pendingFileQueue->enqueue(file);
|
||||
}
|
||||
|
||||
void FileWatcher::onFileCreated(const QString &path, bool isDir)
|
||||
|
@ -85,7 +91,7 @@ void FileWatcher::onFileCreated(const QString &path, bool isDir)
|
|||
PendingFile file(path);
|
||||
file.setIsDir(isDir);
|
||||
file.setCreated();
|
||||
m_pendingFileQUeue->enqueue(file);
|
||||
m_pendingFileQueue->enqueue(file);
|
||||
}
|
||||
|
||||
void FileWatcher::onFileMoveTo(const QString &path, bool isDir)
|
||||
|
@ -93,12 +99,24 @@ void FileWatcher::onFileMoveTo(const QString &path, bool isDir)
|
|||
PendingFile file(path);
|
||||
file.setIsDir(isDir);
|
||||
file.setMoveTo();
|
||||
m_pendingFileQUeue->enqueue(file);
|
||||
m_pendingFileQueue->enqueue(file);
|
||||
}
|
||||
|
||||
void FileWatcher::onFileModefied(const QString &path)
|
||||
void FileWatcher::onFileModified(const QString &path)
|
||||
{
|
||||
PendingFile file(path);
|
||||
file.setModified();
|
||||
m_pendingFileQUeue->enqueue(file);
|
||||
m_pendingFileQueue->enqueue(file);
|
||||
}
|
||||
|
||||
void FileWatcher::onFileAccessibleChanged(const QString &path, bool isDir, bool accessible)
|
||||
{
|
||||
PendingFile file(path);
|
||||
file.setIsDir(isDir);
|
||||
if(accessible) {
|
||||
file.setModified();
|
||||
} else {
|
||||
file.setDeleted();
|
||||
}
|
||||
m_pendingFileQueue->enqueue(file);
|
||||
}
|
||||
|
|
|
@ -63,11 +63,12 @@ Q_SIGNALS:
|
|||
private:
|
||||
void onFileCreated(const QString& path, bool isDir);
|
||||
void onFileMoveTo(const QString& path, bool isDir);
|
||||
void onFileModefied(const QString& path);
|
||||
void onFileModified(const QString& path);
|
||||
void onFileDeletedOrMoved(const QString& path, bool isDir);
|
||||
void onFileAccessibleChanged(const QString& path, bool isDir, bool accessible);
|
||||
FileSystemWatcher *m_watcher = nullptr;
|
||||
FileIndexerConfig *m_config = nullptr;
|
||||
PendingFileQueue *m_pendingFileQUeue = nullptr;
|
||||
PendingFileQueue *m_pendingFileQueue = nullptr;
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ void PendingFile::merge(const PendingFile& file)
|
|||
|
||||
void PendingFile::printFlags() const
|
||||
{
|
||||
// qDebug() << "Created:" << m_created;
|
||||
qDebug() << "Created:" << m_created;
|
||||
qDebug() << "Deleted:" << m_deleted;
|
||||
qDebug() << "Modified:" << m_modified;
|
||||
qDebug() << "Is dir:" << m_isDir;
|
||||
|
|
Loading…
Reference in New Issue