[FACT-1286] Facter::Util::Resolution.which() returns directories, not only executable files Created: 2015/12/14  Updated: 2016/01/20  Resolved: 2015/12/21

Status: Closed
Project: Facter
Component/s: Community
Affects Version/s: FACT 2.4.4
Fix Version/s: FACT 2.4.5

Type: Bug Priority: Normal
Reporter: Peter Wilmott Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Story Points: 1
Sprint: Client 2015-12-30
Release Notes: Bug Fix
Release Notes Summary: `Facter::Util::Resolution.which` no longer returns a directory if a directory with a matching name is found earlier in the PATH than an executable file with a matching name.
QA Contact: Eric Thompson

 Description   

Environment:

$ echo $PATH
/usr/java/default/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
$ PATH=/tmp:$PATH
 
$ echo $PATH
/tmp:/usr/java/default/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
$ mkdir /tmp/ifconfig

Expected behavior:

$ which ifconfig
/sbin/ifconfig
 
$ irb
irb(main):001:0> require 'facter'
=> true
irb(main):002:0> Facter::Util::Resolution.which('ifconfig')
=> "/sbin/ifconfig"

Actual behavior:

$ which ifconfig
/sbin/ifconfig
 
$ irb
irb(main):001:0> require 'facter'
=> true
irb(main):002:0> Facter::Util::Resolution.which('ifconfig')
=> "/tmp/ifconfig"

This appears to be caused by the fact that Ruby's 'File.executable?' method returns true for directories.


Generated at Sun Feb 16 16:14:10 PST 2020 using JIRA 7.7.1#77002-sha1:e75ca93d5574d9409c0630b81c894d9065296414.