diff options
author | Riccardo Ferrazzo <rferrazz@develer.com> | 2013-08-29 12:36:34 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-19 09:13:57 +0200 |
commit | 31db8728cf038f0a38c42d64c375403fde8598c9 (patch) | |
tree | d90706ae06b54e08f18313962f2ac6f2803e65f6 /src/corelib/io/qfilesystemwatcher_inotify.cpp | |
parent | 73b88fccedfe3912649d119bedf8490ab6c41812 (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/corelib/io/qfilesystemwatcher_inotify.cpp')
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_inotify.cpp | 21 |
1 files changed, 17 insertions, 4 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 |