class Puppet::FileServing::Metadata

A class that handles retrieving file metadata.

Constants

PARAM_ORDER

Attributes

checksum[R]
checksum_type[R]
content_uri[R]
destination[R]
ftype[R]
group[R]
mode[R]
owner[R]
path[R]
source_permissions[R]

Public Class Methods

from_data_hash(data) click to toggle source
    # File lib/puppet/file_serving/metadata.rb
164 def self.from_data_hash(data)
165   new(data.delete('path'), data)
166 end
new(path,data={}) click to toggle source
Calls superclass method Puppet::FileServing::Base::new
    # File lib/puppet/file_serving/metadata.rb
126 def initialize(path,data={})
127   @owner       = data.delete('owner')
128   @group       = data.delete('group')
129   @mode        = data.delete('mode')
130   checksum = data.delete('checksum')
131   if checksum
132     @checksum_type = checksum['type']
133     @checksum      = checksum['value']
134   end
135   @checksum_type ||= Puppet[:digest_algorithm]
136   @ftype       = data.delete('type')
137   @destination = data.delete('destination')
138   @source      = data.delete('source')
139   @content_uri = data.delete('content_uri')
140 
141   links = data.fetch('links', nil) || data.fetch(:links, nil)
142   relative_path = data.fetch('relative_path', nil) || data.fetch(:relative_path, nil)
143   source = @source || data.fetch(:source, nil)
144   super(path, links: links, relative_path: relative_path, source: source)
145 end

Public Instance Methods

checksum_type=(type) click to toggle source
   # File lib/puppet/file_serving/metadata.rb
20 def checksum_type=(type)
21   raise(ArgumentError, _("Unsupported checksum type %{type}") % { type: type }) unless Puppet::Util::Checksums.respond_to?("#{type}_file")
22 
23   @checksum_type = type
24 end
collect(source_permissions = nil) click to toggle source

Retrieve the attributes for this file, relative to a base directory. Note that Puppet::FileSystem.stat(path) raises Errno::ENOENT if the file is absent and this method does not catch that exception.

    # File lib/puppet/file_serving/metadata.rb
101 def collect(source_permissions = nil)
102   real_path = full_path
103 
104   stat = collect_stat(real_path)
105   @owner = stat.owner
106   @group = stat.group
107   @ftype = stat.ftype
108 
109   # We have to mask the mode, yay.
110   @mode = stat.mode & 007777
111 
112   case stat.ftype
113   when "file"
114     @checksum = ("{#{@checksum_type}}") + send("#{@checksum_type}_file", real_path).to_s
115   when "directory" # Always just timestamp the directory.
116     @checksum_type = "ctime"
117     @checksum = ("{#{@checksum_type}}") + send("#{@checksum_type}_file", path).to_s
118   when "link"
119     @destination = Puppet::FileSystem.readlink(real_path)
120     @checksum = ("{#{@checksum_type}}") + send("#{@checksum_type}_file", real_path).to_s rescue nil
121   else
122     raise ArgumentError, _("Cannot manage files of type %{file_type}") % { file_type: stat.ftype }
123   end
124 end
collect_stat(path) click to toggle source
   # File lib/puppet/file_serving/metadata.rb
88 def collect_stat(path)
89   stat = stat()
90 
91   if Puppet::Util::Platform.windows?
92     WindowsStat.new(stat, path, @source_permissions)
93   else
94     MetaStat.new(stat, @source_permissions)
95   end
96 end
content_uri=(path) click to toggle source
   # File lib/puppet/file_serving/metadata.rb
32 def content_uri=(path)
33   begin
34     uri = URI.parse(Puppet::Util.uri_encode(path))
35   rescue URI::InvalidURIError => detail
36     raise(ArgumentError, _("Could not understand URI %{path}: %{detail}") % { path: path, detail: detail })
37   end
38   raise(ArgumentError, _("Cannot use opaque URLs '%{path}'") % { path: path }) unless uri.hierarchical?
39   raise(ArgumentError, _("Must use URLs of type puppet as content URI")) if uri.scheme != "puppet"
40 
41   @content_uri = path.encode(Encoding::UTF_8)
42 end
source_permissions=(source_permissions) click to toggle source
   # File lib/puppet/file_serving/metadata.rb
26 def source_permissions=(source_permissions)
27   raise(ArgumentError, _("Unsupported source_permission %{source_permissions}") % { source_permissions: source_permissions }) unless [:use, :use_when_creating, :ignore].include?(source_permissions.intern)
28 
29   @source_permissions = source_permissions.intern
30 end
to_data_hash() click to toggle source
Calls superclass method Puppet::FileServing::Base#to_data_hash
    # File lib/puppet/file_serving/metadata.rb
147 def to_data_hash
148   super.update(
149     {
150       'owner'        => owner,
151       'group'        => group,
152       'mode'         => mode,
153       'checksum'     => {
154         'type'   => checksum_type,
155         'value'  => checksum
156       },
157       'type'         => ftype,
158       'destination'  => destination,
159     }.merge(content_uri ? {'content_uri' => content_uri} : {})
160      .merge(source ? {'source' => source} : {})
161   )
162 end