Skip to content

Commit 8b4c7b8

Browse files
committed
Updated to use delete_if
1 parent 964be3b commit 8b4c7b8

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

lib/msf/core/modules/metadata/cache.rb

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,11 @@ def get_unchanged_module_references
107107
#######
108108

109109
def remove_from_cache(module_name)
110-
@module_metadata_cache.each do |cache_key, module_metadata|
111-
112-
if module_metadata.ref_name.eql? module_name
113-
@module_metadata_cache.delete cache_key
114-
return true
115-
end
116-
end
110+
removed = @module_metadata_cache.delete_if {|_, module_metadata|
111+
module_metadata.ref_name.eql? module_name
112+
}
117113

118-
return false
114+
return !removed.empty?
119115
end
120116

121117
def wait_for_load
@@ -124,21 +120,14 @@ def wait_for_load
124120

125121
def refresh_metadata_instance_internal(module_instance)
126122
metadata_obj = Obj.new(module_instance)
127-
purge_duplicate(metadata_obj)
128-
@module_metadata_cache[get_cache_key(module_instance)] = metadata_obj
129-
end
130123

131-
#
132-
# Remove all instances of modules pointing to the same path. This prevents stale data hanging
133-
# around when modules are incorrectly typed (eg: Auxilary that should be Exploit)
134-
#
135-
def purge_duplicate(metadata_obj)
136-
@module_metadata_cache.each do |cache_key, module_metadata|
124+
# Remove all instances of modules pointing to the same path. This prevents stale data hanging
125+
# around when modules are incorrectly typed (eg: Auxilary that should be Exploit)
126+
@module_metadata_cache.delete_if {|_, module_metadata|
127+
module_metadata.path.eql? metadata_obj.path
128+
}
137129

138-
if module_metadata.path.eql? metadata_obj.path
139-
@module_metadata_cache.delete cache_key
140-
end
141-
end
130+
@module_metadata_cache[get_cache_key(module_instance)] = metadata_obj
142131
end
143132

144133
def get_cache_key(module_instance)

0 commit comments

Comments
 (0)