Class: Puppet::FileServing::Metadata
Overview
A class that handles retrieving file metadata.
Defined Under Namespace
Classes: MetaStat, WindowsStat
Constant Summary
collapse
- PARAM_ORDER =
[:mode, :ftype, :owner, :group]
Constants included
from Indirector
Indirector::BadNameRegexp
Instance Attribute Summary collapse
Attributes inherited from Base
#links, #relative_path, #source
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Indirector
configure_routes, indirects
#checksum?, #ctime, #ctime_file, #md5, #md5_file, #md5_stream, #md5lite, #md5lite_file, #mtime, #mtime_file, #mtime_stream, #none, #none_file, #none_stream, #sha1, #sha1_file, #sha1_stream, #sha1lite, #sha1lite_file, #sumdata, #sumtype
Methods inherited from Base
absolute?, #exist?, #full_path, #stat
#requiredopts, #set_options, #symbolize_options
Constructor Details
#initialize(path, data = {}) ⇒ Metadata
Returns a new instance of Metadata.
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/puppet/file_serving/metadata.rb', line 95
def initialize(path,data={})
@owner = data.delete('owner')
@group = data.delete('group')
@mode = data.delete('mode')
if checksum = data.delete('checksum')
@checksum_type = checksum['type']
@checksum = checksum['value']
end
@checksum_type ||= "md5"
@ftype = data.delete('type')
@destination = data.delete('destination')
super(path,data)
end
|
Instance Attribute Details
15
16
17
|
# File 'lib/puppet/file_serving/metadata.rb', line 15
def checksum
@checksum
end
|
#checksum_type ⇒ Object
15
16
17
|
# File 'lib/puppet/file_serving/metadata.rb', line 15
def checksum_type
@checksum_type
end
|
#destination ⇒ Object
15
16
17
|
# File 'lib/puppet/file_serving/metadata.rb', line 15
def destination
@destination
end
|
15
16
17
|
# File 'lib/puppet/file_serving/metadata.rb', line 15
def ftype
@ftype
end
|
15
16
17
|
# File 'lib/puppet/file_serving/metadata.rb', line 15
def group
@group
end
|
15
16
17
|
# File 'lib/puppet/file_serving/metadata.rb', line 15
def mode
@mode
end
|
15
16
17
|
# File 'lib/puppet/file_serving/metadata.rb', line 15
def owner
@owner
end
|
15
16
17
|
# File 'lib/puppet/file_serving/metadata.rb', line 15
def path
@path
end
|
Class Method Details
.from_pson(data) ⇒ Object
141
142
143
|
# File 'lib/puppet/file_serving/metadata.rb', line 141
def self.from_pson(data)
new(data.delete('path'), data)
end
|
Instance Method Details
Retrieve the attributes for this file, relative to a base directory. Note that Puppet::FileSystem::File.new(path).stat raises Errno::ENOENT if the file is absent and this method does not catch that exception.
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/puppet/file_serving/metadata.rb', line 70
def collect
real_path = full_path
stat = collect_stat(real_path)
@owner = stat.owner
@group = stat.group
@ftype = stat.ftype
@mode = stat.mode & 007777
case stat.ftype
when "file"
@checksum = ("{#{@checksum_type}}") + send("#{@checksum_type}_file", real_path).to_s
when "directory"
@checksum_type = "ctime"
@checksum = ("{#{@checksum_type}}") + send("#{@checksum_type}_file", path).to_s
when "link"
@destination = Puppet::FileSystem::File.new(real_path).readlink
@checksum = ("{#{@checksum_type}}") + send("#{@checksum_type}_file", real_path).to_s rescue nil
else
raise ArgumentError, "Cannot manage files of type #{stat.ftype}"
end
end
|
#collect_stat(path) ⇒ Object
57
58
59
60
61
62
63
64
65
|
# File 'lib/puppet/file_serving/metadata.rb', line 57
def collect_stat(path)
stat = stat()
if Puppet.features.microsoft_windows?
WindowsStat.new(stat, path)
else
MetaStat.new(stat)
end
end
|
#to_data_hash ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/puppet/file_serving/metadata.rb', line 109
def to_data_hash
super.update(
{
'owner' => owner,
'group' => group,
'mode' => mode,
'checksum' => {
'type' => checksum_type,
'value' => checksum
},
'type' => ftype,
'destination' => destination,
}
)
end
|
#to_pson(*args) ⇒ Object
137
138
139
|
# File 'lib/puppet/file_serving/metadata.rb', line 137
def to_pson(*args)
to_pson_data_hash.to_pson(*args)
end
|
#to_pson_data_hash ⇒ Object
127
128
129
130
131
132
133
134
135
|
# File 'lib/puppet/file_serving/metadata.rb', line 127
def to_pson_data_hash
{
'document_type' => 'FileMetadata',
'data' => to_data_hash,
'metadata' => {
'api_version' => 1
}
}
end
|