Skip to content

Commit

Permalink
Land #19887, Update reload_lib to ignore gemfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
cgranleese-r7 authored Feb 17, 2025
2 parents 8092212 + f16d31b commit 2e93268
Showing 1 changed file with 35 additions and 17 deletions.
52 changes: 35 additions & 17 deletions lib/msf/ui/console/command_dispatcher/developer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ def local_pager
end

# XXX: This will try to reload *any* .rb and break on modules
def reload_file(path, print_errors: true)
full_path = File.expand_path(path)

def reload_file(full_path, print_errors: true)
unless File.exist?(full_path) && full_path.end_with?('.rb')
print_error("#{full_path} must exist and be a .rb file") if print_errors
return
Expand All @@ -94,11 +92,16 @@ def modified_file_paths(print_errors: true)
files = []
end

ignored_patterns = %w[
**/Gemfile
**/Gemfile.lock
**/*_spec.rb
**/spec_helper.rb
]
@modified_files ||= []
@modified_files |= files.map do |file|
next if file.end_with?('_spec.rb') || file.end_with?("spec_helper.rb")
File.join(Msf::Config.install_root, file)
end.compact
@modified_files |= files.reject do |file|
ignored_patterns.any? { |pattern| File.fnmatch(pattern, file) }
end
@modified_files
end

Expand Down Expand Up @@ -512,20 +515,35 @@ def cmd_time_help
print_line
end

private
protected

def source_directories
[Msf::Config.install_root]
end

def modified_files
# Using an array avoids shelling out, so we avoid escaping/quoting
changed_files = %w[git diff --name-only]
begin
output, status = Open3.capture2e(*changed_files, chdir: Msf::Config.install_root)
is_success = status.success?
output = output.split("\n")
rescue => e
elog(e)
output = []
is_success = false

is_success = true
files = []
source_directories.each do |directory|
begin
output, status = Open3.capture2e(*changed_files, chdir: directory)
is_success = status.success?
break unless is_success

files += output.split("\n").map do |path|
realpath = Pathname.new(directory).join(path).realpath
raise "invalid path" unless realpath.to_s.start_with?(directory)
realpath.to_s
end
rescue => e
elog(e)
is_success = false
break
end
end
return output, is_success
[files, is_success]
end
end

0 comments on commit 2e93268

Please sign in to comment.