chef 0.10.8 → 0.10.10.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. data/distro/arch/etc/rc.d/chef-client +15 -1
  2. data/distro/common/html/chef-client.8.html +4 -4
  3. data/distro/common/html/chef-expander.8.html +4 -4
  4. data/distro/common/html/chef-expanderctl.8.html +4 -4
  5. data/distro/common/html/chef-server-webui.8.html +4 -4
  6. data/distro/common/html/chef-server.8.html +4 -4
  7. data/distro/common/html/chef-solo.8.html +4 -4
  8. data/distro/common/html/chef-solr.8.html +4 -4
  9. data/distro/common/html/knife-bootstrap.1.html +6 -10
  10. data/distro/common/html/knife-client.1.html +4 -4
  11. data/distro/common/html/knife-configure.1.html +4 -4
  12. data/distro/common/html/knife-cookbook-site.1.html +6 -6
  13. data/distro/common/html/knife-cookbook.1.html +4 -4
  14. data/distro/common/html/knife-data-bag.1.html +4 -4
  15. data/distro/common/html/knife-environment.1.html +4 -4
  16. data/distro/common/html/knife-exec.1.html +4 -4
  17. data/distro/common/html/knife-index.1.html +4 -4
  18. data/distro/common/html/knife-node.1.html +5 -5
  19. data/distro/common/html/knife-role.1.html +4 -4
  20. data/distro/common/html/knife-search.1.html +4 -4
  21. data/distro/common/html/knife-ssh.1.html +5 -6
  22. data/distro/common/html/knife-status.1.html +4 -4
  23. data/distro/common/html/knife-tag.1.html +4 -4
  24. data/distro/common/html/knife.1.html +7 -8
  25. data/distro/common/html/shef.1.html +4 -4
  26. data/distro/common/man/man1/knife-bootstrap.1 +4 -4
  27. data/distro/common/man/man1/knife-client.1 +1 -1
  28. data/distro/common/man/man1/knife-configure.1 +1 -1
  29. data/distro/common/man/man1/knife-cookbook-site.1 +4 -4
  30. data/distro/common/man/man1/knife-cookbook.1 +1 -1
  31. data/distro/common/man/man1/knife-data-bag.1 +1 -1
  32. data/distro/common/man/man1/knife-environment.1 +1 -1
  33. data/distro/common/man/man1/knife-exec.1 +1 -1
  34. data/distro/common/man/man1/knife-index.1 +1 -1
  35. data/distro/common/man/man1/knife-node.1 +2 -2
  36. data/distro/common/man/man1/knife-role.1 +1 -1
  37. data/distro/common/man/man1/knife-search.1 +1 -1
  38. data/distro/common/man/man1/knife-ssh.1 +3 -7
  39. data/distro/common/man/man1/knife-status.1 +1 -1
  40. data/distro/common/man/man1/knife-tag.1 +1 -1
  41. data/distro/common/man/man1/knife.1 +5 -9
  42. data/distro/common/man/man1/shef.1 +1 -1
  43. data/distro/common/man/man8/chef-client.8 +1 -1
  44. data/distro/common/man/man8/chef-expander.8 +1 -1
  45. data/distro/common/man/man8/chef-expanderctl.8 +1 -1
  46. data/distro/common/man/man8/chef-server-webui.8 +1 -1
  47. data/distro/common/man/man8/chef-server.8 +1 -1
  48. data/distro/common/man/man8/chef-solo.8 +1 -1
  49. data/distro/common/man/man8/chef-solr.8 +1 -1
  50. data/distro/common/markdown/man1/knife-bootstrap.mkd +3 -7
  51. data/distro/common/markdown/man1/knife-cookbook-site.mkd +3 -3
  52. data/distro/common/markdown/man1/knife-node.mkd +2 -2
  53. data/distro/common/markdown/man1/knife-ssh.mkd +2 -5
  54. data/distro/common/markdown/man1/knife.mkd +7 -9
  55. data/distro/debian/etc/init.d/chef-client +22 -1
  56. data/distro/redhat/etc/init.d/chef-client +12 -1
  57. data/distro/windows/service_manager.rb +164 -0
  58. data/lib/chef/application.rb +12 -6
  59. data/lib/chef/application/client.rb +4 -3
  60. data/lib/chef/application/knife.rb +7 -12
  61. data/lib/chef/application/solo.rb +2 -1
  62. data/lib/chef/application/windows_service.rb +224 -0
  63. data/lib/chef/checksum_cache.rb +1 -0
  64. data/lib/chef/client.rb +3 -16
  65. data/lib/chef/config.rb +42 -13
  66. data/lib/chef/cookbook/metadata.rb +1 -1
  67. data/lib/chef/cookbook/syntax_check.rb +2 -2
  68. data/lib/chef/cookbook_version.rb +5 -0
  69. data/lib/chef/daemon.rb +1 -1
  70. data/lib/chef/exceptions.rb +7 -1
  71. data/lib/chef/file_access_control.rb +13 -87
  72. data/lib/chef/file_access_control/unix.rb +119 -0
  73. data/lib/chef/file_access_control/windows.rb +257 -0
  74. data/lib/chef/handler/json_file.rb +7 -1
  75. data/lib/chef/knife.rb +10 -16
  76. data/lib/chef/knife/bootstrap.rb +15 -8
  77. data/lib/chef/knife/bootstrap/centos5-gems.erb +1 -1
  78. data/lib/chef/knife/bootstrap/chef-full.erb +59 -0
  79. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +1 -0
  80. data/lib/chef/knife/configure.rb +2 -2
  81. data/lib/chef/knife/cookbook_site_download.rb +60 -21
  82. data/lib/chef/knife/cookbook_site_install.rb +16 -21
  83. data/lib/chef/knife/cookbook_upload.rb +77 -48
  84. data/lib/chef/knife/core/bootstrap_context.rb +3 -1
  85. data/lib/chef/knife/core/cookbook_scm_repo.rb +1 -1
  86. data/lib/chef/knife/core/node_editor.rb +1 -1
  87. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  88. data/lib/chef/knife/core/ui.rb +3 -2
  89. data/lib/chef/knife/help_topics.rb +1 -1
  90. data/lib/chef/knife/node_run_list_add.rb +14 -6
  91. data/lib/chef/knife/node_run_list_remove.rb +3 -3
  92. data/lib/chef/knife/ssh.rb +32 -13
  93. data/lib/chef/mash.rb +14 -0
  94. data/lib/chef/mixin/command.rb +1 -0
  95. data/lib/chef/mixin/command/unix.rb +5 -0
  96. data/lib/chef/mixin/convert_to_class_name.rb +2 -0
  97. data/lib/chef/mixin/deep_merge.rb +40 -18
  98. data/lib/chef/mixin/enforce_ownership_and_permissions.rb +39 -0
  99. data/lib/chef/mixin/language.rb +89 -3
  100. data/lib/chef/mixin/language_include_recipe.rb +8 -4
  101. data/lib/chef/mixin/path_sanity.rb +67 -0
  102. data/lib/chef/mixin/recipe_definition_dsl_core.rb +19 -11
  103. data/lib/chef/mixin/securable.rb +152 -0
  104. data/lib/chef/mixin/shell_out.rb +1 -1
  105. data/lib/chef/mixin/template.rb +8 -3
  106. data/lib/chef/mixins.rb +3 -0
  107. data/lib/chef/monkey_patches/moneta.rb +50 -0
  108. data/lib/chef/monkey_patches/string.rb +1 -1
  109. data/lib/chef/node.rb +2 -1
  110. data/lib/chef/platform.rb +34 -0
  111. data/lib/chef/provider.rb +23 -21
  112. data/lib/chef/provider/cron.rb +17 -12
  113. data/lib/chef/provider/cron/solaris.rb +6 -18
  114. data/lib/chef/provider/deploy.rb +14 -15
  115. data/lib/chef/provider/deploy/timestamped.rb +0 -1
  116. data/lib/chef/provider/directory.rb +1 -3
  117. data/lib/chef/provider/execute.rb +2 -2
  118. data/lib/chef/provider/file.rb +1 -75
  119. data/lib/chef/provider/git.rb +11 -9
  120. data/lib/chef/provider/group/gpasswd.rb +14 -9
  121. data/lib/chef/provider/link.rb +28 -59
  122. data/lib/chef/provider/mdadm.rb +2 -2
  123. data/lib/chef/provider/mount/mount.rb +1 -1
  124. data/lib/chef/provider/package.rb +10 -6
  125. data/lib/chef/provider/package/apt.rb +3 -1
  126. data/lib/chef/provider/package/dpkg.rb +1 -1
  127. data/lib/chef/provider/package/portage.rb +6 -3
  128. data/lib/chef/provider/package/rubygems.rb +75 -6
  129. data/lib/chef/provider/package/smartos.rb +84 -0
  130. data/lib/chef/provider/package/yum-dump.py +3 -2
  131. data/lib/chef/provider/package/yum.rb +51 -10
  132. data/lib/chef/provider/remote_directory.rb +24 -3
  133. data/lib/chef/provider/remote_file.rb +0 -6
  134. data/lib/chef/provider/route.rb +3 -3
  135. data/lib/chef/provider/service/debian.rb +2 -2
  136. data/lib/chef/provider/service/freebsd.rb +1 -1
  137. data/lib/chef/provider/service/macosx.rb +125 -0
  138. data/lib/chef/provider/service/windows.rb +5 -1
  139. data/lib/chef/provider/subversion.rb +10 -7
  140. data/lib/chef/providers.rb +3 -0
  141. data/lib/chef/resource.rb +181 -87
  142. data/lib/chef/resource/apt_package.rb +10 -1
  143. data/lib/chef/resource/chef_gem.rb +53 -0
  144. data/lib/chef/resource/conditional.rb +3 -0
  145. data/lib/chef/resource/cookbook_file.rb +12 -6
  146. data/lib/chef/resource/cron.rb +9 -0
  147. data/lib/chef/resource/directory.rb +14 -31
  148. data/lib/chef/resource/execute.rb +11 -9
  149. data/lib/chef/resource/file.rb +9 -33
  150. data/lib/chef/resource/link.rb +13 -8
  151. data/lib/chef/resource/mdadm.rb +10 -1
  152. data/lib/chef/resource/remote_directory.rb +13 -2
  153. data/lib/chef/resource/remote_file.rb +14 -7
  154. data/lib/chef/resource/smartos_package.rb +36 -0
  155. data/lib/chef/resource/template.rb +12 -5
  156. data/lib/chef/resource_platform_map.rb +153 -0
  157. data/lib/chef/resources.rb +2 -0
  158. data/lib/chef/rest.rb +55 -10
  159. data/lib/chef/rest/auth_credentials.rb +1 -0
  160. data/lib/chef/rest/rest_request.rb +24 -8
  161. data/lib/chef/role.rb +8 -2
  162. data/lib/chef/run_list.rb +1 -1
  163. data/lib/chef/run_list/run_list_expansion.rb +2 -2
  164. data/lib/chef/run_list/run_list_item.rb +7 -0
  165. data/lib/chef/runner.rb +4 -0
  166. data/lib/chef/shef.rb +2 -2
  167. data/lib/chef/shef/shef_session.rb +4 -5
  168. data/lib/chef/shell_out.rb +2 -245
  169. data/lib/chef/util/file_edit.rb +99 -89
  170. data/lib/chef/version.rb +1 -1
  171. data/lib/chef/win32/api.rb +349 -0
  172. data/lib/chef/win32/api/error.rb +921 -0
  173. data/lib/chef/win32/api/file.rb +289 -0
  174. data/lib/chef/win32/api/memory.rb +105 -0
  175. data/lib/chef/win32/api/process.rb +40 -0
  176. data/lib/chef/win32/api/psapi.rb +51 -0
  177. data/lib/chef/win32/api/security.rb +341 -0
  178. data/lib/chef/win32/api/system.rb +192 -0
  179. data/lib/chef/win32/api/unicode.rb +178 -0
  180. data/lib/chef/win32/error.rb +73 -0
  181. data/lib/chef/win32/file.rb +117 -0
  182. data/lib/chef/win32/file/info.rb +100 -0
  183. data/lib/chef/win32/handle.rb +48 -0
  184. data/lib/chef/win32/memory.rb +101 -0
  185. data/lib/chef/win32/process.rb +84 -0
  186. data/lib/chef/win32/security.rb +489 -0
  187. data/lib/chef/win32/security/ace.rb +125 -0
  188. data/lib/chef/win32/security/acl.rb +101 -0
  189. data/lib/chef/win32/security/securable_object.rb +109 -0
  190. data/lib/chef/win32/security/security_descriptor.rb +93 -0
  191. data/lib/chef/win32/security/sid.rb +199 -0
  192. data/lib/chef/win32/security/token.rb +64 -0
  193. data/lib/chef/win32/unicode.rb +43 -0
  194. data/lib/chef/win32/version.rb +119 -0
  195. metadata +104 -158
  196. data/lib/chef/shell_out/unix.rb +0 -223
  197. data/lib/chef/shell_out/windows.rb +0 -588
@@ -26,7 +26,6 @@ class Chef
26
26
  def release_slug
27
27
  Time.now.utc.strftime("%Y%m%d%H%M%S")
28
28
  end
29
-
30
29
  end
31
30
  end
32
31
  end
@@ -48,9 +48,7 @@ class Chef
48
48
  @new_resource.updated_by_last_action(true)
49
49
  Chef::Log.info("#{@new_resource} created directory #{@new_resource.path}")
50
50
  end
51
- set_owner if @new_resource.owner != nil
52
- set_group if @new_resource.group != nil
53
- set_mode if @new_resource.mode != nil
51
+ enforce_ownership_and_permissions
54
52
  end
55
53
 
56
54
  def action_delete
@@ -49,8 +49,8 @@ class Chef
49
49
  opts[:group] = @new_resource.group if @new_resource.group
50
50
  opts[:cwd] = @new_resource.cwd if @new_resource.cwd
51
51
  opts[:umask] = @new_resource.umask if @new_resource.umask
52
- opts[:command_log_level] = :info
53
- opts[:command_log_prepend] = @new_resource.to_s
52
+ opts[:log_level] = :info
53
+ opts[:log_tag] = @new_resource.to_s
54
54
  if STDOUT.tty? && !Chef::Config[:daemon] && Chef::Log.info?
55
55
  opts[:live_stream] = STDOUT
56
56
  end
@@ -46,12 +46,6 @@ class Chef
46
46
  @current_resource = Chef::Resource::File.new(@new_resource.name)
47
47
  @new_resource.path.gsub!(/\\/, "/") # for Windows
48
48
  @current_resource.path(@new_resource.path)
49
- if ::File.exist?(@current_resource.path) && ::File.readable?(@current_resource.path)
50
- cstats = ::File.stat(@current_resource.path)
51
- @current_resource.owner(cstats.uid)
52
- @current_resource.group(cstats.gid)
53
- @current_resource.mode(octal_mode(cstats.mode))
54
- end
55
49
  @current_resource
56
50
  end
57
51
 
@@ -70,72 +64,6 @@ class Chef
70
64
  end
71
65
  end
72
66
 
73
- # Compare the ownership of a file. Returns true if they are the same, false if they are not.
74
- def compare_owner
75
- return false if @new_resource.owner.nil?
76
-
77
- @set_user_id = case @new_resource.owner
78
- when /^\d+$/, Integer
79
- @new_resource.owner.to_i
80
- else
81
- # This raises an ArgumentError if you can't find the user
82
- Etc.getpwnam(@new_resource.owner).uid
83
- end
84
-
85
- @set_user_id == @current_resource.owner
86
- end
87
-
88
- # Set the ownership on the file, assuming it is not set correctly already.
89
- def set_owner
90
- unless compare_owner
91
- @set_user_id = negative_complement(@set_user_id)
92
- ::File.chown(@set_user_id, nil, @new_resource.path)
93
- Chef::Log.info("#{@new_resource} owner changed to #{@set_user_id}")
94
- @new_resource.updated_by_last_action(true)
95
- end
96
- end
97
-
98
- # Compares the group of a file. Returns true if they are the same, false if they are not.
99
- def compare_group
100
- return false if @new_resource.group.nil?
101
-
102
- @set_group_id = case @new_resource.group
103
- when /^\d+$/, Integer
104
- @new_resource.group.to_i
105
- else
106
- Etc.getgrnam(@new_resource.group).gid
107
- end
108
-
109
- @set_group_id == @current_resource.group
110
- end
111
-
112
- def set_group
113
- unless compare_group
114
- @set_group_id = negative_complement(@set_group_id)
115
- ::File.chown(nil, @set_group_id, @new_resource.path)
116
- Chef::Log.info("#{@new_resource} group changed to #{@set_group_id}")
117
- @new_resource.updated_by_last_action(true)
118
- end
119
- end
120
-
121
- def compare_mode
122
- case @new_resource.mode
123
- when /^\d+$/, Integer
124
- octal_mode(@new_resource.mode) == octal_mode(@current_resource.mode)
125
- else
126
- false
127
- end
128
- end
129
-
130
- def set_mode
131
- unless compare_mode && @new_resource.mode != nil
132
- # CHEF-174, bad mojo around treating integers as octal. If a string is passed, we try to do the "right" thing
133
- ::File.chmod(octal_mode(@new_resource.mode), @new_resource.path)
134
- Chef::Log.info("#{@new_resource} mode changed to #{sprintf("%o" % octal_mode(@new_resource.mode))}")
135
- @new_resource.updated_by_last_action(true)
136
- end
137
- end
138
-
139
67
  def action_create
140
68
  assert_enclosing_directory_exists!
141
69
  unless ::File.exists?(@new_resource.path)
@@ -145,9 +73,7 @@ class Chef
145
73
  else
146
74
  set_content unless @new_resource.content.nil?
147
75
  end
148
- set_owner unless @new_resource.owner.nil?
149
- set_group unless @new_resource.group.nil?
150
- set_mode unless @new_resource.mode.nil?
76
+ enforce_ownership_and_permissions
151
77
  end
152
78
 
153
79
  def action_create_if_missing
@@ -21,6 +21,7 @@ require 'chef/log'
21
21
  require 'chef/provider'
22
22
  require 'chef/mixin/shell_out'
23
23
  require 'fileutils'
24
+ require 'shellwords'
24
25
 
25
26
  class Chef
26
27
  class Provider
@@ -104,7 +105,7 @@ class Chef
104
105
  @new_resource.additional_remotes.each_pair do |remote_name, remote_url|
105
106
  Chef::Log.info "#{@new_resource} adding git remote #{remote_name} = #{remote_url}"
106
107
  command = "git remote add #{remote_name} #{remote_url}"
107
- if shell_out(command, run_options(:cwd => @new_resource.destination, :command_log_level => :info)).exitstatus != 0
108
+ if shell_out(command, run_options(:cwd => @new_resource.destination, :log_level => :info)).exitstatus != 0
108
109
  @new_resource.updated_by_last_action(true)
109
110
  end
110
111
  end
@@ -120,8 +121,8 @@ class Chef
120
121
 
121
122
  Chef::Log.info "#{@new_resource} cloning repo #{@new_resource.repository} to #{@new_resource.destination}"
122
123
 
123
- clone_cmd = "git clone #{args.join(' ')} #{@new_resource.repository} #{@new_resource.destination}"
124
- shell_out!(clone_cmd, run_options(:command_log_level => :info))
124
+ clone_cmd = "git clone #{args.join(' ')} #{@new_resource.repository} #{Shellwords.escape @new_resource.destination}"
125
+ shell_out!(clone_cmd, run_options(:log_level => :info))
125
126
  end
126
127
 
127
128
  def checkout
@@ -134,8 +135,9 @@ class Chef
134
135
  def enable_submodules
135
136
  if @new_resource.enable_submodules
136
137
  Chef::Log.info "#{@new_resource} enabling git submodules"
137
- command = "git submodule init && git submodule update"
138
- shell_out!(command, run_options(:cwd => @new_resource.destination, :command_log_level => :info))
138
+ # the --recursive flag means we require git 1.6.5+ now, see CHEF-1827
139
+ command = "git submodule update --init --recursive"
140
+ shell_out!(command, run_options(:cwd => @new_resource.destination, :log_level => :info))
139
141
  end
140
142
  end
141
143
 
@@ -144,7 +146,7 @@ class Chef
144
146
 
145
147
  # since we're in a local branch already, just reset to specified revision rather than merge
146
148
  fetch_command = "git fetch #{@new_resource.remote} && git fetch #{@new_resource.remote} --tags && git reset --hard #{target_revision}"
147
- Chef::Log.debug "Fetching updates from #{new_resource.remote} and resetting to revison #{target_revision}"
149
+ Chef::Log.debug "Fetching updates from #{new_resource.remote} and resetting to revision #{target_revision}"
148
150
  shell_out!(fetch_command, run_options(:cwd => @new_resource.destination))
149
151
  end
150
152
 
@@ -195,9 +197,9 @@ class Chef
195
197
  run_opts[:user] = @new_resource.user if @new_resource.user
196
198
  run_opts[:group] = @new_resource.group if @new_resource.group
197
199
  run_opts[:environment] = {"GIT_SSH" => @new_resource.ssh_wrapper} if @new_resource.ssh_wrapper
198
- run_opts[:command_log_prepend] = @new_resource.to_s
199
- run_opts[:command_log_level] ||= :debug
200
- if run_opts[:command_log_level] == :info
200
+ run_opts[:log_tag] = @new_resource.to_s
201
+ run_opts[:log_level] ||= :debug
202
+ if run_opts[:log_level] == :info
201
203
  if STDOUT.tty? && !Chef::Config[:daemon] && Chef::Log.info?
202
204
  run_opts[:live_stream] = STDOUT
203
205
  end
@@ -33,19 +33,24 @@ class Chef
33
33
  end
34
34
 
35
35
  def modify_group_members
36
- unless @new_resource.members.empty?
37
36
  if(@new_resource.append)
38
- @new_resource.members.each do |member|
39
- Chef::Log.debug("#{@new_resource} appending member #{member} to group #{@new_resource.group_name}")
40
- shell_out!("gpasswd -a #{member} #{@new_resource.group_name}")
37
+ unless @new_resource.members.empty?
38
+ @new_resource.members.each do |member|
39
+ Chef::Log.debug("#{@new_resource} appending member #{member} to group #{@new_resource.group_name}")
40
+ shell_out!("gpasswd -a #{member} #{@new_resource.group_name}")
41
+ end
42
+ else
43
+ Chef::Log.debug("#{@new_resource} not changing group members, the group has no members to add")
41
44
  end
42
45
  else
43
- Chef::Log.debug("#{@new_resource} setting group members to #{@new_resource.members.join(', ')}")
44
- shell_out!("gpasswd -M #{@new_resource.members.join(',')} #{@new_resource.group_name}")
46
+ unless @new_resource.members.empty?
47
+ Chef::Log.debug("#{@new_resource} setting group members to #{@new_resource.members.join(', ')}")
48
+ shell_out!("gpasswd -M #{@new_resource.members.join(',')} #{@new_resource.group_name}")
49
+ else
50
+ Chef::Log.debug("#{@new_resource} setting group members to: none")
51
+ shell_out!("gpasswd -M \"\" #{@new_resource.group_name}")
52
+ end
45
53
  end
46
- else
47
- Chef::Log.debug("#{@new_resource} not changing group members, the group has no members")
48
- end
49
54
  end
50
55
  end
51
56
  end
@@ -26,7 +26,15 @@ class Chef
26
26
  class Provider
27
27
  class Link < Chef::Provider
28
28
  include Chef::Mixin::ShellOut
29
- #include Chef::Mixin::Command
29
+
30
+ def file_class
31
+ @host_os_file ||= if Chef::Platform.windows?
32
+ require 'chef/win32/file'
33
+ Chef::Win32::File
34
+ else
35
+ ::File
36
+ end
37
+ end
30
38
 
31
39
  def negative_complement(big)
32
40
  if big > 1073741823 # Fixnum max
@@ -42,9 +50,9 @@ class Chef
42
50
  @current_resource.target_file(@new_resource.target_file)
43
51
  @current_resource.link_type(@new_resource.link_type)
44
52
  if @new_resource.link_type == :symbolic
45
- if ::File.exists?(@current_resource.target_file) && ::File.symlink?(@current_resource.target_file)
53
+ if ::File.exists?(@current_resource.target_file) && file_class.symlink?(@current_resource.target_file)
46
54
  @current_resource.to(
47
- ::File.expand_path(::File.readlink(@current_resource.target_file))
55
+ ::File.expand_path(file_class.readlink(@current_resource.target_file))
48
56
  )
49
57
  cstats = ::File.lstat(@current_resource.target_file)
50
58
  @current_resource.owner(cstats.uid)
@@ -66,81 +74,32 @@ class Chef
66
74
  @current_resource
67
75
  end
68
76
 
69
- # Compare the ownership of a symlink. Returns true if they are the same, false if they are not.
70
- def compare_owner
71
- return false if @new_resource.owner.nil?
72
-
73
- @set_user_id = case @new_resource.owner
74
- when /^\d+$/, Integer
75
- @new_resource.owner.to_i
76
- else
77
- # This raises an ArgumentError if you can't find the user
78
- Etc.getpwnam(@new_resource.owner).uid
79
- end
80
-
81
- @set_user_id == @current_resource.owner
82
- end
83
-
84
- # Set the ownership on the symlink, assuming it is not set correctly already.
85
- def set_owner
86
- unless compare_owner
87
- @set_user_id = negative_complement(@set_user_id)
88
- ::File.lchown(@set_user_id, nil, @new_resource.target_file)
89
- Chef::Log.info("#{@new_resource} owner changed to #{@set_user_id}")
90
- @new_resource.updated_by_last_action(true)
91
- end
92
- end
93
-
94
- # Compares the group of a symlink. Returns true if they are the same, false if they are not.
95
- def compare_group
96
- return false if @new_resource.group.nil?
97
-
98
- @set_group_id = case @new_resource.group
99
- when /^\d+$/, Integer
100
- @new_resource.group.to_i
101
- else
102
- Etc.getgrnam(@new_resource.group).gid
103
- end
104
-
105
- @set_group_id == @current_resource.group
106
- end
107
-
108
- def set_group
109
- unless compare_group
110
- @set_group_id = negative_complement(@set_group_id)
111
- ::File.lchown(nil, @set_group_id, @new_resource.target_file)
112
- Chef::Log.info("#{@new_resource} group changed to #{@set_group_id}")
113
- @new_resource.updated_by_last_action(true)
114
- end
115
- end
116
-
117
77
  def action_create
118
78
  if @current_resource.to != ::File.expand_path(@new_resource.to, @new_resource.target_file)
119
79
  if @new_resource.link_type == :symbolic
120
- unless (::File.symlink?(@new_resource.target_file) && ::File.readlink(@new_resource.target_file) == @new_resource.to)
121
- if ::File.symlink?(@new_resource.target_file) || ::File.exist?(@new_resource.target_file)
80
+ unless (file_class.symlink?(@new_resource.target_file) && file_class.readlink(@new_resource.target_file) == @new_resource.to)
81
+ if file_class.symlink?(@new_resource.target_file) || ::File.exist?(@new_resource.target_file)
122
82
  ::File.unlink(@new_resource.target_file)
123
83
  end
124
- ::File.symlink(@new_resource.to,@new_resource.target_file)
84
+ file_class.symlink(@new_resource.to,@new_resource.target_file)
125
85
  Chef::Log.debug("#{@new_resource} created #{@new_resource.link_type} link from #{@new_resource.to} -> #{@new_resource.target_file}")
126
86
  Chef::Log.info("#{@new_resource} created")
127
87
  end
128
88
  elsif @new_resource.link_type == :hard
129
- ::File.link(@new_resource.to, @new_resource.target_file)
89
+ file_class.link(@new_resource.to, @new_resource.target_file)
130
90
  Chef::Log.debug("#{@new_resource} created #{@new_resource.link_type} link from #{@new_resource.to} -> #{@new_resource.target_file}")
131
91
  Chef::Log.info("#{@new_resource} created")
132
92
  end
133
93
  @new_resource.updated_by_last_action(true)
134
94
  end
135
95
  if @new_resource.link_type == :symbolic
136
- set_owner unless @new_resource.owner.nil?
137
- set_group unless @new_resource.group.nil?
96
+ enforce_ownership_and_permissions
138
97
  end
139
98
  end
140
99
 
141
100
  def action_delete
142
101
  if @new_resource.link_type == :symbolic
143
- if ::File.symlink?(@new_resource.target_file)
102
+ if file_class.symlink?(@new_resource.target_file)
144
103
  ::File.delete(@new_resource.target_file)
145
104
  Chef::Log.info("#{@new_resource} deleted")
146
105
  @new_resource.updated_by_last_action(true)
@@ -149,7 +108,7 @@ class Chef
149
108
  end
150
109
  elsif @new_resource.link_type == :hard
151
110
  if ::File.exists?(@new_resource.target_file)
152
- if ::File.exists?(@new_resource.to) && ::File.stat(@current_resource.target_file).ino == ::File.stat(@new_resource.to).ino
111
+ if ::File.exists?(@new_resource.to) && (file_class.stat(@current_resource.target_file).ino == file_class.stat(@new_resource.to).ino)
153
112
  ::File.delete(@new_resource.target_file)
154
113
  Chef::Log.info("#{@new_resource} deleted")
155
114
  @new_resource.updated_by_last_action(true)
@@ -160,5 +119,15 @@ class Chef
160
119
  end
161
120
  end
162
121
  end
122
+
123
+ # private
124
+ # def hardlink?(target, to)
125
+ # s = file_class()
126
+ # if file_class.respond_to?(:hardlink?)
127
+ # file_class.hardlink?(target)
128
+ # else
129
+ # ::File.stat(target).ino == ::File.stat(to).ino
130
+ # end
131
+ # end
163
132
  end
164
133
  end
@@ -26,7 +26,7 @@ class Chef
26
26
 
27
27
  #include Chef::Mixin::Command
28
28
  include Chef::Mixin::ShellOut
29
-
29
+
30
30
  def popen4
31
31
  raise Exception, "deprecated, bitches"
32
32
  end
@@ -51,7 +51,7 @@ class Chef
51
51
 
52
52
  def action_create
53
53
  unless @current_resource.exists
54
- command = "yes | mdadm --create #{@new_resource.raid_device} --chunk=#{@new_resource.chunk} --level #{@new_resource.level} --raid-devices #{@new_resource.devices.length} #{@new_resource.devices.join(" ")}"
54
+ command = "yes | mdadm --create #{@new_resource.raid_device} --chunk=#{@new_resource.chunk} --level #{@new_resource.level} --metadata=#{@new_resource.metadata} --raid-devices #{@new_resource.devices.length} #{@new_resource.devices.join(" ")}"
55
55
  Chef::Log.debug("#{@new_resource} mdadm command: #{command}")
56
56
  #pid, stdin, stdout, stderr = popen4(command)
57
57
  shell_out!(command)
@@ -173,7 +173,7 @@ class Chef
173
173
  end
174
174
 
175
175
  def device_should_exist?
176
- @new_resource.device !~ /:/ && @new_resource.device !~ /\/\// && @new_resource.device != "tmpfs" && @new_resource.fstype != 'fuse'
176
+ @new_resource.device !~ /:/ && @new_resource.device !~ /\/\// && @new_resource.fstype != "tmpfs" && @new_resource.fstype != 'fuse'
177
177
  end
178
178
 
179
179
  private
@@ -19,7 +19,6 @@
19
19
  require 'chef/mixin/command'
20
20
  require 'chef/log'
21
21
  require 'chef/file_cache'
22
- require 'chef/resource/remote_file'
23
22
  require 'chef/platform'
24
23
 
25
24
  class Chef
@@ -65,15 +64,20 @@ class Chef
65
64
  end
66
65
 
67
66
  def action_upgrade
68
- if @current_resource.version != candidate_version
67
+ # Can't upgrade what we don't have
68
+ if @current_resource.version.nil? && candidate_version.nil?
69
+ raise(Chef::Exceptions::Package, "No candidate version available for #{@new_resource.package_name}")
70
+ elsif candidate_version.nil?
71
+ Chef::Log.debug("#{@new_resource} no candidate version - nothing to do")
72
+ elsif @current_resource.version == candidate_version
73
+ Chef::Log.debug("#{@new_resource} is at the latest version - nothing to do")
74
+ else
69
75
  orig_version = @current_resource.version || "uninstalled"
70
76
  status = upgrade_package(@new_resource.package_name, candidate_version)
71
77
  if status
72
78
  @new_resource.updated_by_last_action(true)
73
79
  end
74
80
  Chef::Log.info("#{@new_resource} upgraded from #{orig_version} to #{candidate_version}")
75
- else
76
- Chef::Log.debug("#{@new_resource} is at the latest version - nothing to do")
77
81
  end
78
82
  end
79
83
 
@@ -186,11 +190,11 @@ class Chef
186
190
  remote_file.cookbook_name = @new_resource.cookbook_name
187
191
  remote_file.source(@new_resource.response_file)
188
192
  remote_file.backup(false)
189
- end
193
+ end
190
194
 
191
195
  remote_file
192
196
  end
193
-
197
+
194
198
  def expand_options(options)
195
199
  options ? " #{options}" : ""
196
200
  end
@@ -40,8 +40,10 @@ class Chef
40
40
  def check_package_state(package)
41
41
  Chef::Log.debug("#{@new_resource} checking package status for #{package}")
42
42
  installed = false
43
+ # Use apt cache release option only if provider was explicitly defined
44
+ aptcache_options = "-o APT::Default-Release=#{@new_resource.default_release}" if @new_resource.provider && @new_resource.default_release
43
45
 
44
- shell_out!("apt-cache policy #{package}").stdout.each_line do |line|
46
+ shell_out!("apt-cache#{expand_options(aptcache_options)} policy #{package}").stdout.each_line do |line|
45
47
  case line
46
48
  when /^\s{2}Installed: (.+)$/
47
49
  installed_version = $1