blob: 44886afd05e35ee42559b9c1ec29e965d0f5c3a5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
require 'puppet/parameter'
class Puppet::Parameter::Path < Puppet::Parameter
def self.accept_arrays(bool = true)
@accept_arrays = !!bool
end
def self.arrays?
@accept_arrays
end
def validate_path(paths)
if paths.is_a?(Array) and ! self.class.arrays? then
fail "#{name} only accepts a single path, not an array of paths"
end
# We *always* support Unix path separators, as Win32 does now too.
absolute = "[/#{::Regexp.quote(::File::SEPARATOR)}]"
win32 = Puppet.features.microsoft_windows?
Array(paths).each do |path|
next if path =~ %r{^#{absolute}}
next if win32 and path =~ %r{^(?:[a-zA-Z]:)?#{absolute}}
fail("#{name} must be a fully qualified path")
end
paths
end
# This will be overridden if someone uses the validate option, which is why
# it just delegates to the other, useful, method.
def unsafe_validate(paths)
validate_path(paths)
end
# Likewise, this might be overridden, but by default...
def unsafe_munge(paths)
if paths.is_a?(Array) and ! self.class.arrays? then
fail "#{name} only accepts a single path, not an array of paths"
end
paths
end
end
|