[Pkg-puppet-devel] [facter] 05/18: (FACT-1286) Only return files, never directories

Stig Sandbeck Mathisen ssm at debian.org
Wed Jan 27 21:12:52 UTC 2016


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository facter.

commit a66ea61e3e72bd6a3cc380b96189e5273d3d48ac
Author: Peter Wilmott <peter.wilmott at netdev.co.uk>
Date:   Mon Dec 14 13:38:42 2015 +0000

    (FACT-1286) Only return files, never directories
    
    Without this patch 'Facter::Util::Resolution.which' will return a
    directory if a directory with a matching name is found earlier in the
    PATH than a executable file with a matching name.
    
    This patch ensures that 'Facter::Util::Resolution.which' will only
    return items which are files.
---
 lib/facter/core/execution/posix.rb     |  4 ++--
 spec/unit/core/execution/posix_spec.rb | 10 ++++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/lib/facter/core/execution/posix.rb b/lib/facter/core/execution/posix.rb
index f710ff9..4f30467 100644
--- a/lib/facter/core/execution/posix.rb
+++ b/lib/facter/core/execution/posix.rb
@@ -11,11 +11,11 @@ class Facter::Core::Execution::Posix < Facter::Core::Execution::Base
 
   def which(bin)
     if absolute_path?(bin)
-      return bin if File.executable?(bin)
+      return bin if File.executable?(bin) and File.file?(bin)
     else
       search_paths.each do |dir|
         dest = File.join(dir, bin)
-        return dest if File.executable?(dest)
+        return dest if File.executable?(dest) and File.file?(dest)
       end
     end
     nil
diff --git a/spec/unit/core/execution/posix_spec.rb b/spec/unit/core/execution/posix_spec.rb
index d672f91..3719deb 100644
--- a/spec/unit/core/execution/posix_spec.rb
+++ b/spec/unit/core/execution/posix_spec.rb
@@ -16,6 +16,7 @@ describe Facter::Core::Execution::Posix, :unless => Facter::Util::Config.is_wind
 
     context "and provided with an absolute path" do
       it "should return the binary if executable" do
+        File.expects(:file?).with('/opt/foo').returns true
         File.expects(:executable?).with('/opt/foo').returns true
         subject.which('/opt/foo').should == '/opt/foo'
       end
@@ -24,12 +25,21 @@ describe Facter::Core::Execution::Posix, :unless => Facter::Util::Config.is_wind
         File.expects(:executable?).with('/opt/foo').returns false
         subject.which('/opt/foo').should be_nil
       end
+
+      it "should return nil if the binary is not a file" do
+        File.expects(:file?).with('/opt/foo').returns false
+        File.expects(:executable?).with('/opt/foo').returns true
+        subject.which('/opt/foo').should be_nil
+      end
     end
 
     context "and not provided with an absolute path" do
       it "should return the absolute path if found" do
+        File.expects(:file?).with('/bin/foo').never
         File.expects(:executable?).with('/bin/foo').returns false
+        File.expects(:file?).with('/sbin/foo').returns true
         File.expects(:executable?).with('/sbin/foo').returns true
+        File.expects(:file?).with('/usr/sbin/foo').never
         File.expects(:executable?).with('/usr/sbin/foo').never
         subject.which('foo').should == '/sbin/foo'
       end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git



More information about the Pkg-puppet-devel mailing list