private void RemoveWatchedDirectoryUnlocked(WatchedDirectory directoryEntry, bool removeInotify)
{
// If the directory has children, recursively remove them (see comments on recursion in AddDirectoryWatch).
if (directoryEntry.Children != null)
{
foreach (WatchedDirectory child in directoryEntry.Children)
{
RemoveWatchedDirectoryUnlocked (child, removeInotify);
}
directoryEntry.Children = null;
}
// Then remove the directory itself.
_wdToPathMap.Remove(directoryEntry.WatchDescriptor);
// And if the caller has requested, remove the associated inotify watch.
if (removeInotify)
{
// Remove the inotify watch. This could fail if our state has become inconsistent
// with the state of the world (e.g. due to lost events). So we don't want failures
// to throw exceptions, but we do assert to detect coding problems during debugging.
int result = Interop.Sys.INotifyRemoveWatch(_inotifyHandle, directoryEntry.WatchDescriptor);
Debug.Assert(result >= 0);
}
}