diff options
| author | David Schmitt <david@dasz.at> | 2010-05-18 15:46:41 +0200 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | 1c016a1ed457af40fc627fa14cf3f93d1671f483 (patch) | |
| tree | 4115f23ff9334c4d304342b60ac2f5b71596b4ad /lib/puppet | |
| parent | 6a928940a43001f62cbd62d6c760c7d287bad855 (diff) | |
| download | puppet-1c016a1ed457af40fc627fa14cf3f93d1671f483.tar.gz puppet-1c016a1ed457af40fc627fa14cf3f93d1671f483.tar.xz puppet-1c016a1ed457af40fc627fa14cf3f93d1671f483.zip | |
Implement quoting on the exec commands and repair specs
Diffstat (limited to 'lib/puppet')
| -rwxr-xr-x | lib/puppet/type/exec.rb | 73 |
1 files changed, 51 insertions, 22 deletions
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index 47d85dad4..41150ba94 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -163,7 +163,13 @@ module Puppet # Support both arrays and colon-separated fields. def value=(*values) @value = values.flatten.collect { |val| - val.split(":") + if val =~ /;/ # recognize semi-colon separated paths + val.split(";") + elsif val =~ /^\w:[^:]*$/ # heuristic to avoid splitting a driveletter away + val + else + val.split(":") + end }.flatten end end @@ -444,6 +450,10 @@ module Puppet reqs << str } + self[:command].scan(/^"([^"]+)"/) { |str| + reqs << str + } + [:onlyif, :unless].each { |param| next unless tmp = self[param] @@ -498,29 +508,40 @@ module Puppet # Verify that we have the executable def checkexe(cmd) - if cmd =~ /^\// - exe = cmd.split(/ /)[0] - unless FileTest.exists?(exe) - raise ArgumentError, "Could not find executable %s" % exe - end - unless FileTest.executable?(exe) - raise ArgumentError, - "%s is not executable" % exe - end - elsif path = self[:path] - exe = cmd.split(/ /)[0] - withenv :PATH => self[:path].join(":") do - path = %{which #{exe}}.chomp - if path == "" - raise ArgumentError, - "Could not find command '%s'" % exe + exe = extractexe(cmd) + + if self[:path] + if Puppet.features.posix? and !File.exists?(exe) + withenv :PATH => self[:path].join(File::PATH_SEPARATOR) do + path = %{which #{exe}}.chomp + if path == "" + raise ArgumentError, + "Could not find command '%s'" % exe + else + exe = File.join(path, exe) + end + end + elsif Puppet.features.win32? and !File.exists?(exe) + self[:path].each do |path| + [".exe", ".ps1", ".bat", ".com", ""].each do |extension| + file = File.join(path, exe+extension) + return if File.exists?(file) + end end end else raise ArgumentError, - "%s is somehow not qualified with no search path" % + "'%s' is somehow not qualified with no search path" % self[:command] end + + unless FileTest.exists?(exe) + raise ArgumentError, "Could not find executable '%s'" % exe + end + unless FileTest.executable?(exe) + raise ArgumentError, + "'%s' is not executable" % exe + end end def output @@ -616,11 +637,19 @@ module Puppet end def validatecmd(cmd) + exe = extractexe(cmd) # if we're not fully qualified, require a path - if cmd !~ /^\// - if self[:path].nil? - self.fail "'%s' is both unqualifed and specified no search path" % cmd - end + if File.expand_path(exe) != exe and self[:path].nil? + self.fail "'%s' is both unqualifed and specified no search path" % cmd + end + end + + def extractexe(cmd) + # easy case: command was quoted + if cmd =~ /^"([^"]+)"/ + $1 + else + cmd.split(/ /)[0] end end end |
