summaryrefslogtreecommitdiffstats
path: root/smdirwatcher.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'smdirwatcher.cpp')
-rw-r--r--smdirwatcher.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/smdirwatcher.cpp b/smdirwatcher.cpp
index a216af5..78dae2a 100644
--- a/smdirwatcher.cpp
+++ b/smdirwatcher.cpp
@@ -38,15 +38,13 @@ void SmDirWatcher::setDir(const QString &dir){
* since we're only watching one directory at all times
* don't care about the other events
*/
- mDescr = inotify_add_watch(mFd, qPrintable(dir), IN_CLOSE_WRITE | IN_CREATE | IN_DELETE | IN_MODIFY);
+ mDescr = inotify_add_watch(mFd, qPrintable(dir), IN_CLOSE_WRITE | IN_CREATE | IN_DELETE | IN_MODIFY | IN_MOVED_FROM);
mCurrent = dir;
}
-#include <QDebug>
-
void SmDirWatcher::run(){
QMutexLocker lock(&mWatchMx);
- QVarLengthArray<char, 4096> data(ioctl(mFd, FIONREAD) + 1);
+ QVarLengthArray<char, 4096> data(4096);
int r = read(mFd, data.data(), data.size());
while(r < 0){
int err = errno;
@@ -65,19 +63,22 @@ void SmDirWatcher::run(){
char *end = at + data.size();
while(at < end){
inotify_event *e = reinterpret_cast<inotify_event*>(at);
- qDebug() << "inotify:" << e->name;
if(e->mask & IN_IGNORED){
at += sizeof(inotify_event) + e->len;
continue;
}
+ QString name = QString("%1/%2").arg(mCurrent).arg(e->name);
if(e->mask & IN_CREATE){
- emit dwEvent(e->name, Added);
+ emit dwEvent(name, Added);
}
if(e->mask & IN_DELETE){
- emit dwEvent(e->name, Deleted);
+ emit dwEvent(name, Deleted);
+ }
+ if(e->mask & IN_CLOSE_WRITE || e->mask & IN_MODIFY){
+ emit dwEvent(name, Modified);
}
- if((e->mask & IN_CLOSE_WRITE) || (e->mask & IN_MODIFY)){
- emit dwEvent(e->name, Modified);
+ if(e->mask & IN_MOVED_FROM){
+ emit needRefresh();
}
at += sizeof(inotify_event) + e->len;
}