summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRiccardo Ferrazzo <rferrazz@develer.com>2013-08-29 12:36:34 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-19 09:13:57 +0200
commit31db8728cf038f0a38c42d64c375403fde8598c9 (patch)
treed90706ae06b54e08f18313962f2ac6f2803e65f6 /src
parent73b88fccedfe3912649d119bedf8490ab6c41812 (diff)
Fix QFileSystemWatcher inotify
On linux using QFileSystemWatcher with inotify backend when a watched file is moved and added again to the watched files its path is not replaced with the new one. This behavior prevents the emission of the fileChanged signal with the wrong file path. Task-number: QTBUG-33211 Change-Id: Ib45d8efdf5afbf8b8f6b4b26e43f3d6ee740aca6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qfilesystemwatcher_inotify.cpp21
-rw-r--r--src/corelib/io/qfilesystemwatcher_inotify_p.h5
2 files changed, 21 insertions, 5 deletions
diff --git a/src/corelib/io/qfilesystemwatcher_inotify.cpp b/src/corelib/io/qfilesystemwatcher_inotify.cpp
index 024af79c33..c731f3d417 100644
--- a/src/corelib/io/qfilesystemwatcher_inotify.cpp
+++ b/src/corelib/io/qfilesystemwatcher_inotify.cpp
@@ -365,11 +365,11 @@ void QInotifyFileSystemWatcherEngine::readFromInotify()
// qDebug() << "inotify event, wd" << event.wd << "mask" << hex << event.mask;
int id = event.wd;
- QString path = idToPath.value(id);
+ QString path = getPathFromID(id);
if (path.isEmpty()) {
// perhaps a directory?
id = -id;
- path = idToPath.value(id);
+ path = getPathFromID(id);
if (path.isEmpty())
continue;
}
@@ -378,8 +378,9 @@ void QInotifyFileSystemWatcherEngine::readFromInotify()
if ((event.mask & (IN_DELETE_SELF | IN_MOVE_SELF | IN_UNMOUNT)) != 0) {
pathToID.remove(path);
- idToPath.remove(id);
- inotify_rm_watch(inotifyFd, event.wd);
+ idToPath.remove(id, getPathFromID(id));
+ if (!idToPath.contains(id))
+ inotify_rm_watch(inotifyFd, event.wd);
if (id < 0)
emit directoryChanged(path, true);
@@ -394,6 +395,18 @@ void QInotifyFileSystemWatcherEngine::readFromInotify()
}
}
+QString QInotifyFileSystemWatcherEngine::getPathFromID(int id) const
+{
+ QHash<int, QString>::const_iterator i = idToPath.find(id);
+ while (i != idToPath.constEnd() && i.key() == id) {
+ if ((i + 1) == idToPath.constEnd() || (i + 1).key() != id) {
+ return i.value();
+ }
+ ++i;
+ }
+ return QString();
+}
+
QT_END_NAMESPACE
#endif // QT_NO_FILESYSTEMWATCHER
diff --git a/src/corelib/io/qfilesystemwatcher_inotify_p.h b/src/corelib/io/qfilesystemwatcher_inotify_p.h
index 959d9edc12..d02f04eed6 100644
--- a/src/corelib/io/qfilesystemwatcher_inotify_p.h
+++ b/src/corelib/io/qfilesystemwatcher_inotify_p.h
@@ -79,10 +79,13 @@ private Q_SLOTS:
void readFromInotify();
private:
+ QString getPathFromID(int id) const;
+
+private:
QInotifyFileSystemWatcherEngine(int fd, QObject *parent);
int inotifyFd;
QHash<QString, int> pathToID;
- QHash<int, QString> idToPath;
+ QMultiHash<int, QString> idToPath;
QSocketNotifier notifier;
};