puppetlabs/facter — pull request #189 by stschulte (2012-04-07 11:46:15+00:00)
Title: (#13678) Expand commands to absolute paths before running them

The former behaviour of facter is to allow passing commands to `Facter::Util::Resolution.exec` without specifying an absolute path to the binary . To check if the executable is present on the system facter would then run `%x{which commandname}`. If this worked it would then run `%x{commandname}` and let the shell find the command. As a result we end up with two shell invocations just to run a single command.

The patch now tries to convert the executable of the command into an absolute pathname so we can easiliy check with the `File.executable?` if the binary is present on our system.

The new methods `which` and `absolute_path?` are adopted from puppet which claim to run on both windows and unix systems. This is great because we do not have to distinct between the platforms in the exec method anymore.

The reason I started to work on this is because the `ifconfig` binary moved from `/sbin` to `/bin`. Instead of writing a bunch of conditionals it might be easier to let facter find the binary for us. But relying on the former `which` behaviour of facter will break the `ipaddress` facts for everyone with `ifconfig` in `/sbin/ifconfig` but not having `/sbin` in path. The new implemenation makes sure that `/sbin` and `/bin` are checked when searching for the binary.