def self.scan(queue, sync_record, dir, rel_path, options)
return unless (record = sync_record.async)
previous = sync_record.dir_entries(dir, rel_path)
record.add_dir(dir, rel_path)
path = dir + rel_path
current = Set.new(path.children)
if options[:silence]
_log :debug, "Recording: #{rel_path}: #{options.inspect}" " [#{previous.inspect}] -> (#{current.inspect})"
else
_log :debug, "Scanning: #{rel_path}: #{options.inspect}" " [#{previous.inspect}] -> (#{current.inspect})"
end
current.each do |full_path|
type = full_path.directory? ? :dir : :file
item_rel_path = full_path.relative_path_from(dir).to_s
_change(queue, type, dir, item_rel_path, options)
end
previous.reject! { |entry, _| current.include? path + entry }
_async_changes(dir, rel_path, queue, previous, options)
rescue Errno::ENOENT
record.unset_path(dir, rel_path)
_async_changes(dir, rel_path, queue, previous, options)
rescue Errno::ENOTDIR
record.unset_path(dir, rel_path)
_async_changes(dir, path, queue, previous, options)
_change(queue, :file, dir, rel_path, options)
rescue
_log :warn, "scanning DIED: #{$!}:#{$@.join("\n")}"
raise
end