class Puppet::FileServing::Base

The base class for Content and Metadata; provides common functionality like the behaviour around links.

Attributes

path[R]

Set our base path.

relative_path[R]

Set a relative path; this is used for recursion, and sets the file's path relative to the initial recursion point.

source[RW]

This is for external consumers to store the source that was used to retrieve the metadata.

Public Class Methods

absolute?(path) click to toggle source
   # File lib/puppet/file_serving/base.rb
84 def self.absolute?(path)
85   Puppet::Util.absolute_path?(path, :posix) || (Puppet::Util::Platform.windows? && Puppet::Util.absolute_path?(path, :windows))
86 end
new(path, links: nil, relative_path: nil, source: nil) click to toggle source
   # File lib/puppet/file_serving/base.rb
36 def initialize(path, links: nil, relative_path: nil, source: nil)
37   self.path = path
38   @links = :manage
39 
40   self.links = links if links
41   self.relative_path = relative_path if relative_path
42   self.source = source if source
43 end

Public Instance Methods

exist?() click to toggle source

Does our file exist?

   # File lib/puppet/file_serving/base.rb
13 def exist?
14     stat
15     return true
16 rescue
17     return false
18 end
full_path() click to toggle source

Return the full path to our file. Fails if there's no path set.

   # File lib/puppet/file_serving/base.rb
21 def full_path
22   if relative_path.nil? or relative_path == "" or relative_path == "."
23     full_path = path
24   else
25     full_path = File.join(path, relative_path)
26   end
27 
28   if Puppet::Util::Platform.windows?
29     # Replace multiple slashes as long as they aren't at the beginning of a filename
30     full_path.gsub(%r{(./)/+}, '\1')
31   else
32     full_path.gsub(%r{//+}, '/')
33   end
34 end
path=(path) click to toggle source
   # File lib/puppet/file_serving/base.rb
57 def path=(path)
58   raise ArgumentError.new(_("Paths must be fully qualified")) unless Puppet::FileServing::Base.absolute?(path)
59   @path = path
60 end
relative_path=(path) click to toggle source
   # File lib/puppet/file_serving/base.rb
65 def relative_path=(path)
66   raise ArgumentError.new(_("Relative paths must not be fully qualified")) if Puppet::FileServing::Base.absolute?(path)
67   @relative_path = path
68 end
stat() click to toggle source

Stat our file, using the appropriate link-sensitive method.

   # File lib/puppet/file_serving/base.rb
71 def stat
72   @stat_method ||= self.links == :manage ? :lstat : :stat
73   Puppet::FileSystem.send(@stat_method, full_path)
74 end
to_data_hash() click to toggle source
   # File lib/puppet/file_serving/base.rb
76 def to_data_hash
77   {
78     'path'          => @path,
79     'relative_path' => @relative_path,
80     'links'         => @links.to_s
81   }
82 end