lib/puppet/file_serving/base.rb in puppet-2.7.11 vs lib/puppet/file_serving/base.rb in puppet-2.7.12

- old
+ new

@@ -1,6 +1,7 @@ require 'puppet/file_serving' +require 'puppet/util' # The base class for Content and Metadata; provides common # functionality like the behaviour around links. class Puppet::FileServing::Base # This is for external consumers to store the source that was used @@ -47,22 +48,19 @@ end # Set our base path. attr_reader :path def path=(path) - unless path =~ /^#{::File::SEPARATOR}/ or path =~ /^[a-z]:[\/\\]/i - raise ArgumentError.new("Paths must be fully qualified") - end - + raise ArgumentError.new("Paths must be fully qualified") unless Puppet::FileServing::Base.absolute?(path) @path = path end # Set a relative path; this is used for recursion, and sets # the file's path relative to the initial recursion point. attr_reader :relative_path def relative_path=(path) - raise ArgumentError.new("Relative paths must not be fully qualified") if path =~ /^#{::File::SEPARATOR}/ + raise ArgumentError.new("Relative paths must not be fully qualified") if Puppet::FileServing::Base.absolute?(path) @relative_path = path end # Stat our file, using the appropriate link-sensitive method. def stat @@ -82,6 +80,9 @@ 'api_version' => 1 } } end + def self.absolute?(path) + Puppet::Util.absolute_path?(path, :posix) or (Puppet.features.microsoft_windows? and Puppet::Util.absolute_path?(path, :windows)) + end end