[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 Sat Sep 19 11:04:26 PDT 2020 using Jira 8.5.2#805002-sha1:a66f9354b9e12ac788984e5d84669c903a370049.