Skip to content

Commit e89eb6e

Browse files
committed
Fix first time startup timing bug
1 parent fe1af35 commit e89eb6e

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ def initialize(module_instance)
5454
end
5555
end
5656

57+
def update_mod_time(mod_time)
58+
@mod_time = mod_time
59+
end
60+
5761
def path
5862
if @is_install_path
5963
return ::File.join(Msf::Config.install_root, @path)

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ def update_store
3535
def load_metadata
3636
begin
3737
retries ||= 0
38-
configure_user_store
39-
@store = PStore.new(@path_to_user_metadata)
38+
copied = configure_user_store
39+
@store = PStore.new(@path_to_user_metadata, true)
4040
@module_metadata_cache = @store.transaction(true) { @store[:module_metadata]}
41-
validate_data if (!@module_metadata_cache.nil? && @module_metadata_cache.size > 0)
41+
validate_data(copied) if (!@module_metadata_cache.nil? && @module_metadata_cache.size > 0)
4242
@module_metadata_cache = {} if @module_metadata_cache.nil?
43+
puts "module size #{@module_metadata_cache.size}"
4344
rescue
4445
retries +=1
4546

@@ -54,30 +55,42 @@ def load_metadata
5455

5556
end
5657

57-
def validate_data
58+
def validate_data(copied)
5859
size_prior = @module_metadata_cache.size
59-
@module_metadata_cache.delete_if {|path, module_metadata| !::File.exist?(module_metadata.path)}
60-
update_store if (size_prior != @module_metadata_cache.size)
60+
@module_metadata_cache.delete_if {|key, module_metadata| !::File.exist?(module_metadata.path)}
61+
62+
if (copied)
63+
@module_metadata_cache.each_value {|module_metadata|
64+
module_metadata.update_mod_time(::File.mtime(module_metadata.path))
65+
}
66+
end
67+
68+
update_store if (size_prior != @module_metadata_cache.size || copied)
6169
end
6270

6371
def configure_user_store
72+
copied = false
6473
@path_to_user_metadata = ::File.join(Msf::Config.config_directory, UserMetaDataFile)
65-
path_to_base_metadata = ::File.join(Msf::Config.install_root, "db", BaseMetaDataFile)
74+
@path_to_base_metadata = ::File.join(Msf::Config.install_root, "db", BaseMetaDataFile)
6675

6776
if (!::File.exist?(path_to_base_metadata))
6877
wlog("Missing base module metadata file: #{path_to_base_metadata}")
6978
else
7079
if (!::File.exist?(@path_to_user_metadata))
71-
FileUtils.cp(path_to_base_metadata, @path_to_user_metadata)
80+
FileUtils.cp(@path_to_base_metadata, @path_to_user_metadata)
81+
copied = true
7282
dlog('Created user based module store')
7383

7484
# Update the user based module store if an updated base file is created/pushed
7585
elsif (::File.mtime(path_to_base_metadata).to_i > ::File.mtime(@path_to_user_metadata).to_i)
7686
FileUtils.remove(@path_to_user_metadata, true)
77-
FileUtils.cp(path_to_base_metadata, @path_to_user_metadata)
87+
FileUtils.cp(@path_to_base_metadata, @path_to_user_metadata)
88+
copied = true
7889
dlog('Updated user based module store')
7990
end
8091
end
92+
93+
return copied
8194
end
8295

8396
end

0 commit comments

Comments
 (0)