Class: Itamae::Resource::RemoteDirectory
- Inherits:
-
Base
- Object
- Base
- Itamae::Resource::RemoteDirectory
show all
- Defined in:
- lib/itamae/resource/remote_directory.rb
Instance Attribute Summary
Attributes inherited from Base
#attributes, #current_attributes, #notifications, #recipe, #resource_name, #subscriptions, #updated
Instance Method Summary
collapse
Methods inherited from Base
#action_nothing, define_attribute, #do_not_run_because_of_not_if?, #do_not_run_because_of_only_if?, inherited, #initialize, #resource_type, #run
Instance Method Details
#action_create(options) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/itamae/resource/remote_directory.rb', line 55
def action_create(options)
if attributes.mode
run_specinfra(:change_file_mode, @temppath, attributes.mode)
end
if attributes.owner || attributes.group
run_specinfra(:change_file_owner, @temppath, attributes.owner, attributes.group)
end
if run_specinfra(:check_file_is_file, attributes.path)
unless check_command(["diff", "-q", @temppath, attributes.path])
updated!
end
else
updated!
end
run_specinfra(:remove_file, attributes.path)
run_specinfra(:move_file, @temppath, attributes.path)
end
|
#action_delete(options) ⇒ Object
75
76
77
78
79
|
# File 'lib/itamae/resource/remote_directory.rb', line 75
def action_delete(options)
if run_specinfra(:check_file_is_directory, attributes.path)
run_specinfra(:remove_file, attributes.path)
end
end
|
#pre_action ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/itamae/resource/remote_directory.rb', line 11
def pre_action
directory = ::File.expand_path(attributes.source, ::File.dirname(@recipe.path))
src = ::File.expand_path(directory, ::File.dirname(@recipe.path))
@temppath = ::File.join(runner.tmpdir, Time.now.to_f.to_s)
backend.send_directory(src, @temppath)
case @current_action
when :create
attributes.exist = true
end
end
|
#set_current_attributes ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/itamae/resource/remote_directory.rb', line 24
def set_current_attributes
current.exist = run_specinfra(:check_file_is_directory, attributes.path)
if current.exist
current.mode = run_specinfra(:get_file_mode, attributes.path).stdout.chomp
current.owner = run_specinfra(:get_file_owner_user, attributes.path).stdout.chomp
current.group = run_specinfra(:get_file_owner_group, attributes.path).stdout.chomp
else
current.mode = nil
current.owner = nil
current.group = nil
end
end
|
#show_differences ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/itamae/resource/remote_directory.rb', line 38
def show_differences
super
if current.exist
diff = run_command(["diff", "-u", "-r", attributes.path, @temppath], error: false)
if diff.exit_status == 0
Itamae.logger.debug "directory content will not change"
else
Itamae.logger.info "diff:"
diff.stdout.each_line do |line|
Itamae.logger.info "#{line.strip}"
end
end
end
end
|