# File lib/rb-inotify/notifier.rb, line 189
    def watch(path, *flags, &callback)
      return Watcher.new(self, path, *flags, &callback) unless flags.include?(:recursive)

      Dir.glob(File.join(path, '*'), File::FNM_DOTMATCH).each do |d|
        binary_d = d.respond_to?(:force_encoding) ? d.dup.force_encoding('BINARY') : d
        next if binary_d =~ /\/\.\.?$/ # Current or parent directory
        watch(d, *flags, &callback) if !RECURSIVE_BLACKLIST.include?(d) && File.directory?(d)
      end

      rec_flags = [:create, :moved_to]
      return watch(path, *((flags - [:recursive]) | rec_flags)) do |event|
        callback.call(event) if flags.include?(:all_events) || !(flags & event.flags).empty?
        next if (rec_flags & event.flags).empty? || !event.flags.include?(:isdir)
        begin
          watch(event.absolute_name, *flags, &callback)
        rescue Errno::ENOENT
          # If the file has been deleted since the glob was run, we don't want to error out.
        end
      end
    end