Skip to content

Commit cc60c95

Browse files
committed
Rescue Errno::ENONENT when using File.mtime for memory cache
[#47720609]
1 parent e0e348a commit cc60c95

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

lib/msf/core/module_manager/cache.rb

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,31 @@ def cache_in_memory(class_or_module, options={})
3737
options.assert_valid_keys(:path, :reference_name, :type)
3838

3939
path = options.fetch(:path)
40-
modification_time = File.mtime(path)
41-
42-
parent_path = class_or_module.parent.parent_path
43-
reference_name = options.fetch(:reference_name)
44-
type = options.fetch(:type)
45-
46-
module_info_by_path[path] = {
47-
:modification_time => modification_time,
48-
:parent_path => parent_path,
49-
:reference_name => reference_name,
50-
:type => type
51-
}
40+
41+
begin
42+
modification_time = File.mtime(path)
43+
rescue Errno::ENOENT => error
44+
log_lines = []
45+
log_lines << "Could not find the modification of time of #{path}:"
46+
log_lines << error.class.to_s
47+
log_lines << error.to_s
48+
log_lines << "Call stack:"
49+
log_lines += error.backtrace
50+
51+
log_message = log_lines.join("\n")
52+
elog(log_message)
53+
else
54+
parent_path = class_or_module.parent.parent_path
55+
reference_name = options.fetch(:reference_name)
56+
type = options.fetch(:type)
57+
58+
module_info_by_path[path] = {
59+
:modification_time => modification_time,
60+
:parent_path => parent_path,
61+
:reference_name => reference_name,
62+
:type => type
63+
}
64+
end
5265
end
5366

5467
# Forces loading of the module with the given type and module reference name from the cache.

0 commit comments

Comments
 (0)