Class: Puppet::FileServing::Metadata Private
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A class that handles retrieving file metadata.
Direct Known Subclasses
Defined Under Namespace
Classes: MetaStat, WindowsStat
Constant Summary collapse
- PARAM_ORDER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[:mode, :ftype, :owner, :group]
Constants included from Indirector
Constants included from Util::Checksums
Util::Checksums::KNOWN_CHECKSUMS
Instance Attribute Summary collapse
- #checksum ⇒ Object readonly private
- #checksum_type ⇒ Object private
- #content_uri ⇒ Object private
- #destination ⇒ Object readonly private
- #ftype ⇒ Object readonly private
- #group ⇒ Object readonly private
- #mode ⇒ Object readonly private
- #owner ⇒ Object readonly private
- #path ⇒ Object readonly private
- #source_permissions ⇒ Object private
Attributes inherited from Base
#links, #relative_path, #source
Class Method Summary collapse
- .from_data_hash(data) ⇒ Object private
Instance Method Summary collapse
-
#collect(source_permissions = nil) ⇒ Object
private
Retrieve the attributes for this file, relative to a base directory.
- #collect_stat(path) ⇒ Object private
-
#initialize(path, data = {}) ⇒ Metadata
constructor
private
A new instance of Metadata.
- #to_data_hash ⇒ Object private
Methods included from Indirector
Methods included from Util::Checksums
checksum?, checksum_file, checksum_stream, ctime, ctime?, ctime_file, ctime_stream, known_checksum_types, md5, md5?, md5_file, md5_hex_length, md5_stream, md5lite, md5lite?, md5lite_file, md5lite_hex_length, md5lite_stream, mtime, mtime?, mtime_file, mtime_stream, none, none?, none_file, none_stream, sha1, sha1?, sha1_file, sha1_hex_length, sha1_stream, sha1lite, sha1lite?, sha1lite_file, sha1lite_hex_length, sha1lite_stream, sha224, sha224?, sha224_file, sha224_hex_length, sha224_stream, sha256, sha256?, sha256_file, sha256_hex_length, sha256_stream, sha256lite, sha256lite?, sha256lite_file, sha256lite_hex_length, sha256lite_stream, sha384, sha384?, sha384_file, sha384_hex_length, sha384_stream, sha512, sha512?, sha512_file, sha512_hex_length, sha512_stream, sumdata, sumtype, valid_checksum?
Methods inherited from Base
absolute?, #exist?, #full_path, #stat
Constructor Details
#initialize(path, data = {}) ⇒ Metadata
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Metadata.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/puppet/file_serving/metadata.rb', line 129 def initialize(path,data={}) @owner = data.delete('owner') @group = data.delete('group') @mode = data.delete('mode') checksum = data.delete('checksum') if checksum @checksum_type = checksum['type'] @checksum = checksum['value'] end @checksum_type ||= Puppet[:digest_algorithm] @ftype = data.delete('type') @destination = data.delete('destination') @source = data.delete('source') @content_uri = data.delete('content_uri') links = data.fetch('links', nil) || data.fetch(:links, nil) relative_path = data.fetch('relative_path', nil) || data.fetch(:relative_path, nil) source = @source || data.fetch(:source, nil) super(path, links: links, relative_path: relative_path, source: source) end |
Instance Attribute Details
#checksum ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/puppet/file_serving/metadata.rb', line 16 def checksum @checksum end |
#checksum_type ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/puppet/file_serving/metadata.rb', line 16 def checksum_type @checksum_type end |
#content_uri ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/puppet/file_serving/metadata.rb', line 16 def content_uri @content_uri end |
#destination ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/puppet/file_serving/metadata.rb', line 16 def destination @destination end |
#ftype ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/puppet/file_serving/metadata.rb', line 16 def ftype @ftype end |
#group ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/puppet/file_serving/metadata.rb', line 16 def group @group end |
#mode ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/puppet/file_serving/metadata.rb', line 16 def mode @mode end |
#owner ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/puppet/file_serving/metadata.rb', line 16 def owner @owner end |
#path ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/puppet/file_serving/metadata.rb', line 16 def path @path end |
#source_permissions ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/puppet/file_serving/metadata.rb', line 16 def @source_permissions end |
Class Method Details
.from_data_hash(data) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
167 168 169 |
# File 'lib/puppet/file_serving/metadata.rb', line 167 def self.from_data_hash(data) new(data.delete('path'), data) end |
Instance Method Details
#collect(source_permissions = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/puppet/file_serving/metadata.rb', line 101 def collect( = nil) real_path = full_path stat = collect_stat(real_path) @owner = stat.owner @group = stat.group @ftype = stat.ftype # We have to mask the mode, yay. @mode = stat.mode & 007777 case stat.ftype when "file" @checksum = ("{#{@checksum_type}}") + send("#{@checksum_type}_file", real_path).to_s when "directory" # Always just timestamp the directory. @checksum_type = "ctime" @checksum = ("{#{@checksum_type}}") + send("#{@checksum_type}_file", path).to_s when "link" @destination = Puppet::FileSystem.readlink(real_path) @checksum = ("{#{@checksum_type}}") + send("#{@checksum_type}_file", real_path).to_s rescue nil when "fifo", "socket" @checksum_type = "none" @checksum = ("{#{@checksum_type}}") + send("#{@checksum_type}_file", real_path).to_s else raise ArgumentError, _("Cannot manage files of type %{file_type}") % { file_type: stat.ftype } end end |
#collect_stat(path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
88 89 90 91 92 93 94 95 96 |
# File 'lib/puppet/file_serving/metadata.rb', line 88 def collect_stat(path) stat = stat() if Puppet::Util::Platform.windows? WindowsStat.new(stat, path, @source_permissions) else MetaStat.new(stat, @source_permissions) end end |
#to_data_hash ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/puppet/file_serving/metadata.rb', line 150 def to_data_hash super.update( { 'owner' => owner, 'group' => group, 'mode' => mode, 'checksum' => { 'type' => checksum_type, 'value' => checksum }, 'type' => ftype, 'destination' => destination, }.merge(content_uri ? {'content_uri' => content_uri} : {}) .merge(source ? {'source' => source} : {}) ) end |