diff options
author | Nick Lewis <nick@puppetlabs.com> | 2011-08-15 15:51:37 -0700 |
---|---|---|
committer | Nick Lewis <nick@puppetlabs.com> | 2011-08-16 11:33:26 -0700 |
commit | b28bcb031346cfd2026361ec5ffb420c1dcf60d7 (patch) | |
tree | c9bfc608ea4dc201a7724f6f376c63fdfb4920b3 /lib | |
parent | c9c331bda6f4220d3fde636cdfdc7b0ae449c005 (diff) | |
download | puppet-b28bcb031346cfd2026361ec5ffb420c1dcf60d7.tar.gz puppet-b28bcb031346cfd2026361ec5ffb420c1dcf60d7.tar.xz puppet-b28bcb031346cfd2026361ec5ffb420c1dcf60d7.zip |
(#5495) Remove dead Windows-specific code from posix exec provider
Because this provider only applies when the posix feature is present (and thus
not the windows feature), it can never be used on Windows. Thus, the
Windows-specific command handling is unnecessary and unused.
Also added more specific error messages for the cases where a command doesn't
exist, isn't a file, and isn't executable. These only apply when the command
path is absolute (otherwise the message is simply command not found).
Reviewed-By: Matt Robinson <matt@puppetlabs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/provider/exec/posix.rb | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/lib/puppet/provider/exec/posix.rb b/lib/puppet/provider/exec/posix.rb index 157d0f28d..782f1eac6 100644 --- a/lib/puppet/provider/exec/posix.rb +++ b/lib/puppet/provider/exec/posix.rb @@ -76,26 +76,26 @@ Puppet::Type.type(:exec).provide :posix do def checkexe(command) exe = extractexe(command) - if resource[:path] - if Puppet.features.posix? and !File.exists?(exe) - withenv :PATH => resource[:path].join(File::PATH_SEPARATOR) do - exe = which(exe) || raise(ArgumentError,"Could not find command '#{exe}'") - end - elsif Puppet.features.microsoft_windows? and !File.exists?(exe) - resource[:path].each do |path| - [".exe", ".ps1", ".bat", ".com", ""].each do |extension| - file = File.join(path, exe+extension) - return if File.exists?(file) - end - end + if File.expand_path(exe) == exe + if !File.exists?(exe) + raise ArgumentError, "Could not find command '#{exe}'" + elsif !File.file?(exe) + raise ArgumentError, "'#{exe}' is a #{File.ftype(exe)}, not a file" + elsif !File.executable?(exe) + raise ArgumentError, "'#{exe}' is not executable" end + return end - raise ArgumentError, "Could not find command '#{exe}'" unless File.exists?(exe) - unless File.executable?(exe) - raise ArgumentError, - "'#{exe}' is not executable" + if resource[:path] + withenv :PATH => resource[:path].join(File::PATH_SEPARATOR) do + return if which(exe) + end end + + # 'which' will only return the command if it's executable, so we can't + # distinguish not found from not executable + raise ArgumentError, "Could not find command '#{exe}'" end def extractexe(command) |