4 module Puppet::Parser::Functions
5 newfunction(:is_absolute_path, :type => :rvalue, :arity => 1, :doc => <<-'DOC') do |args|
7 **Deprecated:** Returns boolean true if the string represents an absolute path in the filesystem.
9 This function works for windows and unix style paths.
11 @example The following values will return true:
12 $my_path = 'C:/Program Files (x86)/Puppet Labs/Puppet'
13 is_absolute_path($my_path)
14 $my_path2 = '/var/lib/puppet'
15 is_absolute_path($my_path2)
16 $my_path3 = ['C:/Program Files (x86)/Puppet Labs/Puppet']
17 is_absolute_path($my_path3)
18 $my_path4 = ['/var/lib/puppet']
19 is_absolute_path($my_path4)
21 @example The following values will return false:
22 is_absolute_path(true)
23 is_absolute_path('../var/lib/puppet')
24 is_absolute_path('var/lib/puppet')
26 is_absolute_path($undefined)
29 Returns `true` or `false`
31 > **Note:* **Deprecated** Will be removed in a future version of stdlib. See
32 [`validate_legacy`](#validate_legacy).
34 function_deprecation([:is_absolute_path, 'This method is deprecated, please use the stdlib validate_legacy function,
35 with Stdlib::Compat::Absolute_path. There is further documentation for validate_legacy function in the README.'])
39 # This logic was borrowed from
40 # [lib/puppet/file_serving/base.rb](https://github.com/puppetlabs/puppet/blob/master/lib/puppet/file_serving/base.rb)
41 # Puppet 2.7 and beyond will have Puppet::Util.absolute_path? Fall back to a back-ported implementation otherwise.
42 if Puppet::Util.respond_to?(:absolute_path?)
43 value = (Puppet::Util.absolute_path?(path, :posix) || Puppet::Util.absolute_path?(path, :windows))
45 # This code back-ported from 2.7.x's lib/puppet/util.rb Puppet::Util.absolute_path?
46 # Determine in a platform-specific way whether a path is absolute. This
47 # defaults to the local platform if none is specified.
48 # Escape once for the string literal, and once for the regex.
52 :windows => %r{^(([A-Z]:#{slash})|(#{slash}#{slash}#{name}#{slash}#{name})|(#{slash}#{slash}\?#{slash}#{name}))}i,
55 value = !!(path =~ regexes[:posix]) || !!(path =~ regexes[:windows]) # rubocop:disable Style/DoubleNegation : No alternative known