class Brakeman::Rescanner
Class for rescanning changed files after an initial scan
def ignorable? path
def ignorable? path path.relative.match? IGNORE_PATTERN end
def initialize options, processor, changed_files
def initialize options, processor, changed_files super(options) @old_tracker = processor.tracked_events @paths = changed_files.map {|f| tracker.app_tree.file_path(f) } @old_results = @old_tracker.filtered_warnings.dup #Old warnings from previous scan @changes = nil #True if files had to be rescanned @reindex = Set.new end
def recheck
Runs checks.
def recheck rescan if @changes.nil? if @changes tracker.run_checks Brakeman.filter_warnings(tracker, options) # Actually sets ignored_filter Brakeman::RescanReport.new @old_results, tracker else # No changes, fake no new results Brakeman::RescanReport.new @old_results, @old_tracker end end
def rescan
def rescan raise "Cannot rescan: set `support_rescanning: true`" unless @old_tracker.options[:support_rescanning] tracker.file_cache = @old_tracker.pristine_file_cache template_paths = [] ruby_paths = [] # Remove changed files from the cache. # Collect files to re-parse. @paths.each do |path| file_cache.delete path if path.exists? if path.relative.match? KNOWN_TEMPLATE_EXTENSIONS template_paths << path elsif path.relative.end_with? '.rb' ruby_paths << path end end end # Try to skip rescanning files that do not impact # Brakeman results if @paths.all? { |path| ignorable? path } @changes = false else @changes = true process(ruby_paths:, template_paths:) end self end