Reduce stat(2) calls
`File.file?` and other predicates for permissions can use same stat(2) call result.
This commit is contained in:
parent
03acb3fb4f
commit
477e71b6b6
@ -92,9 +92,11 @@ def gzip_file_path(path)
|
||||
end
|
||||
|
||||
def file_readable?(path)
|
||||
file_path = File.join(@root, path.b)
|
||||
File.file?(file_path) && File.readable?(file_path)
|
||||
file_stat = File.stat(File.join(@root, path.b))
|
||||
rescue SystemCallError
|
||||
false
|
||||
else
|
||||
file_stat.file? && file_stat.readable?
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -131,7 +131,12 @@ def find_cmd_and_exec(commands, *args) # :doc:
|
||||
found = commands.detect do |cmd|
|
||||
dirs_on_path.detect do |path|
|
||||
full_path_command = File.join(path, cmd)
|
||||
File.file?(full_path_command) && File.executable?(full_path_command)
|
||||
begin
|
||||
stat = File.stat(full_path_command)
|
||||
rescue SystemCallError
|
||||
else
|
||||
stat.file? && stat.executable?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user