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
168 def self.from_data_hash(data)
169   new(data.delete('path'), data)
170 end
new(path,data={}) click to toggle source
Calls superclass method Puppet::FileServing::Base::new
    # File lib/puppet/file_serving/metadata.rb
130 def initialize(path,data={})
131   @owner       = data.delete('owner')
132   @group       = data.delete('group')
133   @mode        = data.delete('mode')
134   checksum = data.delete('checksum')
135   if checksum
136     @checksum_type = checksum['type']
137     @checksum      = checksum['value']
138   end
139   @checksum_type ||= Puppet[:digest_algorithm]
140   @ftype       = data.delete('type')
141   @destination = data.delete('destination')
142   @source      = data.delete('source')
143   @content_uri = data.delete('content_uri')
144 
145   links = data.fetch('links', nil) || data.fetch(:links, nil)
146   relative_path = data.fetch('relative_path', nil) || data.fetch(:relative_path, nil)
147   source = @source || data.fetch(:source, nil)
148   super(path, links: links, relative_path: relative_path, source: source)
149 end

Public Instance Methods

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