X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f31f9900e472941fbb9635d7e531bbbecb654249..5edaa5ebb0b01f063a9df87236e8365d7c3886f4:/src/unix/fswatcher_inotify.cpp diff --git a/src/unix/fswatcher_inotify.cpp b/src/unix/fswatcher_inotify.cpp index 6f02d7071e..4801a2f708 100644 --- a/src/unix/fswatcher_inotify.cpp +++ b/src/unix/fswatcher_inotify.cpp @@ -236,34 +236,82 @@ protected: // get watch entry for this event wxFSWatchEntryDescriptors::iterator it = m_watchMap.find(inevt.wd); - if (it == m_watchMap.end()) + + // wd will be -1 for IN_Q_OVERFLOW, which would trigger the wxFAIL_MSG + if (inevt.wd != -1) { - // It's not in the map; check if was recently removed from it. - if (m_staleDescriptors.Index(inevt.wd) != wxNOT_FOUND) - { - wxLogTrace(wxTRACE_FSWATCHER, - "Got an event for stale wd %i", inevt.wd); - } - else + if (it == m_watchMap.end()) { - wxFAIL_MSG("Event for unknown watch descriptor."); - } + // It's not in the map; check if was recently removed from it. + if (m_staleDescriptors.Index(inevt.wd) != wxNOT_FOUND) + { + wxLogTrace(wxTRACE_FSWATCHER, + "Got an event for stale wd %i", inevt.wd); + } + else + { + // In theory we shouldn't reach here. In practice, some + // events, e.g. IN_MODIFY, arrive just after the IN_IGNORED + // so their wd has already been discarded. Warn about them. + wxFileSystemWatcherEvent + event + ( + wxFSW_EVENT_WARNING, + wxString::Format + ( + _("Unexpected event for \"%s\": no " + "matching watch descriptor."), + inevt.len ? inevt.name : "" + ) + ); + SendEvent(event); - // In any case, don't process this event: it's either for an - // already removed entry, or for a completely unknown one. - return; + } + + // In any case, don't process this event: it's either for an + // already removed entry, or for an unknown one. + return; + } } - wxFSWatchEntry& watch = *(it->second); int nativeFlags = inevt.mask; int flags = Native2WatcherFlags(nativeFlags); // check out for error/warning condition if (flags & wxFSW_EVENT_WARNING || flags & wxFSW_EVENT_ERROR) { - wxString errMsg = GetErrorDescription(Watcher2NativeFlags(flags)); + wxString errMsg = GetErrorDescription(nativeFlags); wxFileSystemWatcherEvent event(flags, errMsg); SendEvent(event); + return; + } + + if (inevt.wd == -1) + { + // Although this is not supposed to happen, we seem to be getting + // occasional IN_ACCESS/IN_MODIFY events without valid watch value. + wxFileSystemWatcherEvent + event + ( + wxFSW_EVENT_WARNING, + wxString::Format + ( + _("Invalid inotify event for \"%s\""), + inevt.len ? inevt.name : "" + ) + ); + SendEvent(event); + return; + } + + wxFSWatchEntry& watch = *(it->second); + + // Now IN_UNMOUNT. We must do so here, as it's not in the watch flags + if (nativeFlags & IN_UNMOUNT) + { + wxFileName path = GetEventPath(watch, inevt); + wxFileSystemWatcherEvent event(wxFSW_EVENT_UNMOUNT, path, path); + SendEvent(event); } // filter out ignored events and those not asked for. // we never filter out warnings or exceptions @@ -405,19 +453,24 @@ protected: // get watch entry for this event wxFSWatchEntryDescriptors::iterator wit = m_watchMap.find(inevt.wd); - wxCHECK_RET(wit != m_watchMap.end(), - "Watch descriptor not present in the watch map!"); - - // Tell the owner, in case it's interested - // If there's a filespec, assume he's not - wxFSWatchEntry& watch = *(wit->second); - if ( watch.GetFilespec().empty() ) + if (wit == m_watchMap.end()) { - int flags = Native2WatcherFlags(inevt.mask); - wxFileName path = GetEventPath(watch, inevt); + wxLogTrace(wxTRACE_FSWATCHER, + "Watch descriptor not present in the watch map!"); + } + else + { + // Tell the owner, in case it's interested + // If there's a filespec, assume he's not + wxFSWatchEntry& watch = *(wit->second); + if ( watch.GetFilespec().empty() ) { - wxFileSystemWatcherEvent event(flags, path, path); - SendEvent(event); + int flags = Native2WatcherFlags(inevt.mask); + wxFileName path = GetEventPath(watch, inevt); + { + wxFileSystemWatcherEvent event(flags, path, path); + SendEvent(event); + } } } @@ -488,12 +541,13 @@ protected: } static const int flag_mapping[][2] = { - { wxFSW_EVENT_ACCESS, IN_ACCESS }, - { wxFSW_EVENT_MODIFY, IN_MODIFY }, - { wxFSW_EVENT_ATTRIB, IN_ATTRIB }, - { wxFSW_EVENT_RENAME, IN_MOVE }, - { wxFSW_EVENT_CREATE, IN_CREATE }, - { wxFSW_EVENT_DELETE, IN_DELETE|IN_DELETE_SELF|IN_MOVE_SELF } + { wxFSW_EVENT_ACCESS, IN_ACCESS }, + { wxFSW_EVENT_MODIFY, IN_MODIFY }, + { wxFSW_EVENT_ATTRIB, IN_ATTRIB }, + { wxFSW_EVENT_RENAME, IN_MOVE }, + { wxFSW_EVENT_CREATE, IN_CREATE }, + { wxFSW_EVENT_DELETE, IN_DELETE|IN_DELETE_SELF|IN_MOVE_SELF }, + { wxFSW_EVENT_UNMOUNT, IN_UNMOUNT } // wxFSW_EVENT_ERROR/WARNING make no sense here }; @@ -523,7 +577,7 @@ protected: { IN_DELETE_SELF, wxFSW_EVENT_DELETE }, { IN_MOVE_SELF, wxFSW_EVENT_DELETE }, - { IN_UNMOUNT, wxFSW_EVENT_ERROR }, + { IN_UNMOUNT, wxFSW_EVENT_UNMOUNT}, { IN_Q_OVERFLOW, wxFSW_EVENT_WARNING}, // ignored, because this is generated mainly by watcher::Remove() @@ -549,8 +603,6 @@ protected: { switch ( flag ) { - case IN_UNMOUNT: - return _("File system containing watched object was unmounted"); case IN_Q_OVERFLOW: return _("Event queue overflowed"); }