Fail if init_module_paths called more than once

MSP-11672

Calling init_module_paths takes 6 seconds on my machine even when there are no
files to that are changed just because it takes that long to walk the
directories and gather the mtime for each file.  Therefore, calling it
more than once should be avoided.  Also, there is no reason to call it
twice as to add paths later, `modules.add_module_paths` should be used.
bug/bundler_fix
Luke Imhoff 2014-12-02 10:17:09 -06:00
parent 394d132d33
commit 653c71e029
No known key found for this signature in database
GPG Key ID: 5B1FB01FB33356F8
1 changed files with 22 additions and 16 deletions

View File

@ -7,26 +7,32 @@ module Msf
# #
# @return [void] # @return [void]
def init_module_paths(opts={}) def init_module_paths(opts={})
# Ensure the module cache is accurate if @module_paths_inited
self.modules.refresh_cache_from_database fail "Module paths already initialized. To add more module paths call `modules.add_module_path`"
else
# Ensure the module cache is accurate
self.modules.refresh_cache_from_database
add_engine_module_paths(Rails.application, opts) add_engine_module_paths(Rails.application, opts)
Rails.application.railties.engines.each do |engine| Rails.application.railties.engines.each do |engine|
add_engine_module_paths(engine, opts) add_engine_module_paths(engine, opts)
end end
# Initialize the user module search path # Initialize the user module search path
if (Msf::Config.user_module_directory) if (Msf::Config.user_module_directory)
self.modules.add_module_path(Msf::Config.user_module_directory, opts) self.modules.add_module_path(Msf::Config.user_module_directory, opts)
end end
# If additional module paths have been defined globally, then load them. # If additional module paths have been defined globally, then load them.
# They should be separated by semi-colons. # They should be separated by semi-colons.
if self.datastore['MsfModulePaths'] if self.datastore['MsfModulePaths']
self.datastore['MsfModulePaths'].split(";").each { |path| self.datastore['MsfModulePaths'].split(";").each { |path|
self.modules.add_module_path(path, opts) self.modules.add_module_path(path, opts)
} }
end
@module_paths_inited = true
end end
end end