Make wxFileSystemWatcher watch entries reference-counted.
This helps to avoid problems that arise from watching the same physical file system path multiple times, which could happen when adding a watch for a path already watched because of a recursive watch on a parent directory, for example. Closes #14490. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72679 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -49,8 +49,13 @@ public:
|
||||
|
||||
virtual bool Add(const wxFSWatchInfo& winfo)
|
||||
{
|
||||
wxCHECK_MSG( m_watches.find(winfo.GetPath()) == m_watches.end(), false,
|
||||
"Path '%s' is already watched");
|
||||
if ( m_watches.find(winfo.GetPath()) != m_watches.end() )
|
||||
{
|
||||
wxLogTrace(wxTRACE_FSWATCHER,
|
||||
"Path '%s' is already watched", winfo.GetPath());
|
||||
// This can happen if a dir is watched, then a parent tree added
|
||||
return true;
|
||||
}
|
||||
|
||||
// construct watch entry
|
||||
wxSharedPtr<wxFSWatchEntry> watch(new wxFSWatchEntry(winfo));
|
||||
@@ -66,8 +71,13 @@ public:
|
||||
virtual bool Remove(const wxFSWatchInfo& winfo)
|
||||
{
|
||||
wxFSWatchEntries::iterator it = m_watches.find(winfo.GetPath());
|
||||
wxCHECK_MSG( it != m_watches.end(), false, "Path '%s' is not watched");
|
||||
|
||||
if ( it == m_watches.end() )
|
||||
{
|
||||
wxLogTrace(wxTRACE_FSWATCHER,
|
||||
"Path '%s' is not watched", winfo.GetPath());
|
||||
// This can happen if a dir is watched, then a parent tree added
|
||||
return true;
|
||||
}
|
||||
wxSharedPtr<wxFSWatchEntry> watch = it->second;
|
||||
m_watches.erase(it);
|
||||
return DoRemove(watch);
|
||||
|
Reference in New Issue
Block a user