Module: Puppet::DataSync
Constant Summary
Util::Execution::NoOptionsSpecified
Instance Method Summary
collapse
Methods included from Util::Diff
diff, #lcs_diff, #string_file_diff
execfail, execpipe, execute, ruby_path
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
Instance Method Details
#checksum_insync?(param, is, has_contents, &block) ⇒ Boolean
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/puppet/type/file/data_sync.rb', line 24
def checksum_insync?(param, is, has_contents, &block)
resource = param.resource
if resource.should_be_file?
return false if is == :absent
else
if resource[:ensure] == :present && has_contents && (s = resource.stat)
resource.warning _("Ensure set to :present but file type is %{file_type} so no content will be synced") % { file_type: s.ftype}
end
return true
end
return true if ! resource.replace?
is_insync = yield(is)
if show_diff?(!is_insync)
if param.sensitive
send resource[:loglevel], "[diff redacted]"
else
write_temporarily(param) do |path|
send resource[:loglevel], "\n" + diff(resource[:path], path)
end
end
end
is_insync
end
|
#contents_sync(param) ⇒ Object
86
87
88
89
90
|
# File 'lib/puppet/type/file/data_sync.rb', line 86
def contents_sync(param)
return_event = param.resource.stat ? :file_changed : :file_created
resource.write(param)
return_event
end
|
#date_matches?(checksum_type, current, desired) ⇒ Boolean
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/puppet/type/file/data_sync.rb', line 56
def date_matches?(checksum_type, current, desired)
time_types = [:mtime, :ctime]
return false if !time_types.include?(checksum_type)
return false unless current && desired
begin
if checksum?(current) || checksum?(desired)
raise if !time_types.include?(sumtype(current).to_sym) || !time_types.include?(sumtype(desired).to_sym)
current = sumdata(current)
desired = sumdata(desired)
end
DateTime.parse(current) >= DateTime.parse(desired)
rescue => detail
self.fail Puppet::Error, "Resource with checksum_type #{checksum_type} didn't contain a date in #{current} or #{desired}", detail.backtrace
end
end
|
#retrieve_checksum(resource) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/puppet/type/file/data_sync.rb', line 73
def retrieve_checksum(resource)
return :absent unless stat = resource.stat
ftype = stat.ftype
return nil if ["directory","link"].include?(ftype)
begin
resource.parameter(:checksum).sum_file(resource[:path])
rescue => detail
raise Puppet::Error, "Could not read #{ftype} #{resource.title}: #{detail}", detail.backtrace
end
end
|
#show_diff?(has_changes) ⇒ Boolean
52
53
54
|
# File 'lib/puppet/type/file/data_sync.rb', line 52
def show_diff?(has_changes)
has_changes && Puppet[:show_diff] && resource.show_diff?
end
|
#write_temporarily(param) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/puppet/type/file/data_sync.rb', line 11
def write_temporarily(param)
tempfile = Tempfile.new("puppet-file")
tempfile.open
param.write(tempfile)
tempfile.close
yield tempfile.path
ensure
tempfile.delete if tempfile
end
|