boot/init: Fix System.which logic
- A missing program in a single directory shouldn't error out
- A program missing from all directories should return nil
@@ -77,11 +77,14 @@ module System
# Discovers the location of given program name.
def self.which(program_name)
- ENV["PATH"].split(":").each do |path|
+ (ENV["PATH"] or "").split(":").each do |path|
full = File.join(path, program_name)
- return full if File.stat(full).executable? && !File.directory?(full)
+ if File.exists?(full) && !File.directory?(full) && File.stat(full).executable? then
+ return full
end
end
+ nil
+ end
def self.write(file, contents)
$logger.debug(" $ echo #{contents.to_json} > #{file}")
