diff --git a/libsearch/filesystemwatcher/file-system-watcher.cpp b/libsearch/filesystemwatcher/file-system-watcher.cpp index 08c196b..9853bb4 100644 --- a/libsearch/filesystemwatcher/file-system-watcher.cpp +++ b/libsearch/filesystemwatcher/file-system-watcher.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -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"; diff --git a/libsearch/filesystemwatcher/file-system-watcher.h b/libsearch/filesystemwatcher/file-system-watcher.h index 2b35768..6acb3b3 100644 --- a/libsearch/filesystemwatcher/file-system-watcher.h +++ b/libsearch/filesystemwatcher/file-system-watcher.h @@ -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); diff --git a/libsearch/index/file-watcher.cpp b/libsearch/index/file-watcher.cpp index c30e385..dcf46db 100644 --- a/libsearch/index/file-watcher.cpp +++ b/libsearch/index/file-watcher.cpp @@ -22,17 +22,23 @@ using namespace UkuiSearch; FileWatcher::FileWatcher(QObject *parent) : QObject(parent), m_config(FileIndexerConfig::getInstance()) { qRegisterMetaType>("QVector"); - 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); } diff --git a/libsearch/index/file-watcher.h b/libsearch/index/file-watcher.h index de4b159..bc143b7 100644 --- a/libsearch/index/file-watcher.h +++ b/libsearch/index/file-watcher.h @@ -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; }; } diff --git a/libsearch/index/pending-file.cpp b/libsearch/index/pending-file.cpp index 8529e96..749c446 100644 --- a/libsearch/index/pending-file.cpp +++ b/libsearch/index/pending-file.cpp @@ -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;