Reduce stat(2) calls

`File.file?` and other predicates for permissions can use same
stat(2) call result.
This commit is contained in:
Nobuyoshi Nakada 2019-09-22 18:23:09 +09:00
parent 03acb3fb4f
commit 477e71b6b6
No known key found for this signature in database
GPG Key ID: 4BC7D6DF58D8DF60
2 changed files with 10 additions and 3 deletions

@ -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