lib/puppet/provider/augeas/augeas.rb in puppet-3.3.2 vs lib/puppet/provider/augeas/augeas.rb in puppet-3.4.0.rc1

- old
+ new

@@ -123,11 +123,11 @@ else argline << sc.scan(/[^\s]+/) end fail("missing string argument #{narg} for #{cmd}") unless argline[-1] elsif f == :comparator - argline << sc.scan(/(==|!=|=~|<|<=|>|>=)/) + argline << sc.scan(/(==|!=|=~|<=|>=|<|>)/) unless argline[-1] puts sc.rest fail("invalid comparator for command #{cmd}") end elsif f == :int @@ -196,10 +196,21 @@ debug("Closed the augeas connection") @aug = nil end end + def is_numeric?(s) + case s + when Fixnum + true + when String + s.match(/\A[+-]?\d+?(\.\d+)?\Z/n) == nil ? false : true + else + false + end + end + # Used by the need_to_run? method to process get filters. Returns # true if there is a match, false if otherwise # Assumes a syntax of get /files/path [COMPARATOR] value def process_get(cmd_array) return_value = false @@ -211,14 +222,19 @@ comparator = cmd_array.shift arg = cmd_array.join(" ") #check the value in augeas result = @aug.get(path) || '' - case comparator - when "!=" + + if ['<', '<=', '>=', '>'].include? comparator and is_numeric?(result) and + is_numeric?(arg) + resultf = result.to_f + argf = arg.to_f + return_value = (resultf.send(comparator, argf)) + elsif comparator == "!=" return_value = (result != arg) - when "=~" + elsif comparator == "=~" regex = Regexp.new(arg) return_value = (result =~ regex) else return_value = (result.send(comparator, arg)) end @@ -290,10 +306,10 @@ load_path = [resource[:load_path]].flatten load_path.map! { |path| path.split(/:/) } load_path.flatten! end - if File.exists?("#{Puppet[:libdir]}/augeas/lenses") + if Puppet::FileSystem::File.exist?("#{Puppet[:libdir]}/augeas/lenses") load_path << "#{Puppet[:libdir]}/augeas/lenses" end load_path.join(":") end