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:
Vadim Zeitlin
2012-10-15 01:08:37 +00:00
parent 227dee95e0
commit 76cfd1bf95
4 changed files with 85 additions and 18 deletions

View File

@@ -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);