chef 12.5.1 → 12.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -1
  3. data/README.md +6 -4
  4. data/Rakefile +1 -4
  5. data/chef-windows.gemspec +21 -0
  6. data/chef.gemspec +58 -0
  7. data/lib/chef/api_client/registration.rb +9 -4
  8. data/lib/chef/application.rb +3 -84
  9. data/lib/chef/application/apply.rb +9 -2
  10. data/lib/chef/application/client.rb +8 -3
  11. data/lib/chef/application/solo.rb +7 -1
  12. data/lib/chef/application/windows_service.rb +21 -6
  13. data/lib/chef/application/windows_service_manager.rb +2 -3
  14. data/lib/chef/audit/runner.rb +1 -0
  15. data/lib/chef/chef_class.rb +1 -11
  16. data/lib/chef/chef_fs/chef_fs_data_store.rb +181 -2
  17. data/lib/chef/chef_fs/file_system/cookbook_subdir.rb +5 -0
  18. data/lib/chef/chef_fs/file_system/file_system_entry.rb +11 -7
  19. data/lib/chef/client.rb +28 -1
  20. data/lib/chef/cookbook/cookbook_collection.rb +14 -1
  21. data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
  22. data/lib/chef/cookbook/metadata.rb +115 -9
  23. data/lib/chef/cookbook/remote_file_vendor.rb +1 -1
  24. data/lib/chef/cookbook_version.rb +6 -2
  25. data/lib/chef/data_bag.rb +1 -1
  26. data/lib/chef/data_bag_item.rb +1 -1
  27. data/lib/chef/digester.rb +5 -1
  28. data/lib/chef/dsl/chef_provisioning.rb +57 -0
  29. data/lib/chef/dsl/cheffish.rb +64 -0
  30. data/lib/chef/dsl/declare_resource.rb +108 -0
  31. data/lib/chef/dsl/platform_introspection.rb +3 -3
  32. data/lib/chef/dsl/recipe.rb +3 -73
  33. data/lib/chef/dsl/resources.rb +27 -1
  34. data/lib/chef/event_dispatch/base.rb +3 -0
  35. data/lib/chef/event_dispatch/dispatcher.rb +5 -0
  36. data/lib/chef/event_dispatch/events_output_stream.rb +8 -0
  37. data/lib/chef/exceptions.rb +21 -1
  38. data/lib/chef/file_access_control/unix.rb +12 -12
  39. data/lib/chef/file_content_management/deploy/cp.rb +2 -2
  40. data/lib/chef/file_content_management/deploy/mv_unix.rb +4 -4
  41. data/lib/chef/file_content_management/deploy/mv_windows.rb +1 -1
  42. data/lib/chef/formatters/base.rb +7 -0
  43. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +2 -2
  44. data/lib/chef/formatters/indentable_output_stream.rb +5 -0
  45. data/lib/chef/http.rb +19 -3
  46. data/lib/chef/http/decompressor.rb +2 -2
  47. data/lib/chef/json_compat.rb +1 -0
  48. data/lib/chef/knife.rb +16 -2
  49. data/lib/chef/knife/bootstrap.rb +55 -10
  50. data/lib/chef/knife/cookbook_site_install.rb +5 -1
  51. data/lib/chef/knife/core/bootstrap_context.rb +2 -1
  52. data/lib/chef/knife/core/node_presenter.rb +1 -1
  53. data/lib/chef/knife/ssh.rb +30 -16
  54. data/lib/chef/knife/ssl_check.rb +4 -2
  55. data/lib/chef/knife/ssl_fetch.rb +3 -2
  56. data/lib/chef/knife/status.rb +14 -1
  57. data/lib/chef/log.rb +14 -0
  58. data/lib/chef/mixin/get_source_from_package.rb +7 -2
  59. data/lib/chef/mixin/properties.rb +302 -0
  60. data/lib/chef/mixin/proxified_socket.rb +38 -0
  61. data/lib/chef/mixin/subclass_directive.rb +37 -0
  62. data/lib/chef/node.rb +13 -5
  63. data/lib/chef/platform/query_helpers.rb +14 -3
  64. data/lib/chef/platform/service_helpers.rb +20 -38
  65. data/lib/chef/policy_builder/expand_node_object.rb +3 -0
  66. data/lib/chef/policy_builder/policyfile.rb +1 -0
  67. data/lib/chef/property.rb +51 -12
  68. data/lib/chef/provider.rb +40 -35
  69. data/lib/chef/provider/deploy.rb +1 -1
  70. data/lib/chef/provider/dsc_resource.rb +54 -20
  71. data/lib/chef/provider/execute.rb +25 -4
  72. data/lib/chef/provider/group.rb +1 -1
  73. data/lib/chef/provider/lwrp_base.rb +1 -0
  74. data/lib/chef/provider/package.rb +76 -30
  75. data/lib/chef/provider/package/dpkg.rb +152 -69
  76. data/lib/chef/provider/package/openbsd.rb +6 -8
  77. data/lib/chef/provider/package/solaris.rb +2 -0
  78. data/lib/chef/provider/package/windows.rb +95 -14
  79. data/lib/chef/provider/package/windows/exe.rb +129 -0
  80. data/lib/chef/provider/package/windows/msi.rb +37 -13
  81. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +89 -0
  82. data/lib/chef/provider/package/yum.rb +13 -3
  83. data/lib/chef/provider/powershell_script.rb +3 -0
  84. data/lib/chef/provider/remote_file/cache_control_data.rb +37 -4
  85. data/lib/chef/provider/remote_file/http.rb +1 -1
  86. data/lib/chef/provider/script.rb +1 -0
  87. data/lib/chef/provider/service.rb +13 -10
  88. data/lib/chef/provider/service/solaris.rb +43 -17
  89. data/lib/chef/provider/service/upstart.rb +3 -3
  90. data/lib/chef/provider/user.rb +1 -1
  91. data/lib/chef/provider/user/dscl.rb +111 -100
  92. data/lib/chef/provider/user/windows.rb +5 -3
  93. data/lib/chef/recipe.rb +3 -5
  94. data/lib/chef/resource.rb +77 -320
  95. data/lib/chef/resource/action_class.rb +4 -0
  96. data/lib/chef/resource/dpkg_package.rb +4 -3
  97. data/lib/chef/resource/dsc_resource.rb +40 -2
  98. data/lib/chef/resource/execute.rb +9 -1
  99. data/lib/chef/resource/ksh.rb +32 -0
  100. data/lib/chef/resource/lwrp_base.rb +6 -10
  101. data/lib/chef/resource/package.rb +8 -9
  102. data/lib/chef/resource/registry_key.rb +1 -1
  103. data/lib/chef/resource/resource_notification.rb +14 -1
  104. data/lib/chef/resource/script.rb +1 -1
  105. data/lib/chef/resource/windows_package.rb +1 -1
  106. data/lib/chef/resource_builder.rb +14 -7
  107. data/lib/chef/resource_reporter.rb +6 -0
  108. data/lib/chef/resources.rb +1 -7
  109. data/lib/chef/rest.rb +1 -1
  110. data/lib/chef/run_context.rb +45 -2
  111. data/lib/chef/run_list/run_list_expansion.rb +47 -0
  112. data/lib/chef/runner.rb +25 -0
  113. data/lib/chef/search/query.rb +16 -2
  114. data/lib/chef/util/diff.rb +2 -2
  115. data/lib/chef/util/powershell/ps_credential.rb +2 -3
  116. data/lib/chef/version.rb +1 -1
  117. data/lib/chef/win32/api/file.rb +51 -1
  118. data/lib/chef/win32/file.rb +5 -0
  119. data/lib/chef/win32/file/version_info.rb +93 -0
  120. data/lib/chef/win32/mutex.rb +1 -1
  121. data/spec/data/apt/chef-integration-test2-1.0/debian/changelog +5 -0
  122. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.debhelper.log +45 -0
  123. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.substvars +1 -0
  124. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/conffiles +1 -0
  125. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/control +10 -0
  126. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/md5sums +1 -0
  127. data/spec/data/apt/chef-integration-test2-1.0/debian/compat +1 -0
  128. data/spec/data/apt/chef-integration-test2-1.0/debian/conffiles +1 -0
  129. data/spec/data/apt/chef-integration-test2-1.0/debian/control +13 -0
  130. data/spec/data/apt/chef-integration-test2-1.0/debian/copyright +34 -0
  131. data/spec/data/apt/chef-integration-test2-1.0/debian/files +1 -0
  132. data/spec/data/apt/chef-integration-test2-1.0/debian/rules +13 -0
  133. data/spec/data/apt/chef-integration-test2-1.0/debian/source/format +1 -0
  134. data/spec/data/apt/chef-integration-test2_1.0-1.debian.tar.gz +0 -0
  135. data/spec/data/apt/chef-integration-test2_1.0-1.dsc +18 -0
  136. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.build +91 -0
  137. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.changes +31 -0
  138. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.deb +0 -0
  139. data/spec/data/apt/chef-integration-test2_1.0.orig.tar.gz +0 -0
  140. data/spec/functional/application_spec.rb +1 -1
  141. data/spec/functional/audit/runner_spec.rb +4 -0
  142. data/spec/functional/knife/ssh_spec.rb +5 -5
  143. data/spec/functional/notifications_spec.rb +74 -4
  144. data/spec/functional/resource/aix_service_spec.rb +2 -2
  145. data/spec/functional/resource/dpkg_package_spec.rb +339 -0
  146. data/spec/functional/resource/ifconfig_spec.rb +3 -1
  147. data/spec/functional/resource/mount_spec.rb +5 -2
  148. data/spec/functional/resource/package_spec.rb +1 -1
  149. data/spec/functional/resource/user/windows_spec.rb +8 -0
  150. data/spec/functional/resource/windows_package_spec.rb +177 -0
  151. data/spec/functional/win32/version_info_spec.rb +50 -0
  152. data/spec/integration/client/client_spec.rb +80 -0
  153. data/spec/integration/knife/download_spec.rb +9 -0
  154. data/spec/integration/knife/upload_spec.rb +28 -1
  155. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +93 -23
  156. data/spec/integration/recipes/resource_action_spec.rb +211 -116
  157. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +72 -0
  158. data/spec/integration/solo/solo_spec.rb +34 -0
  159. data/spec/spec_helper.rb +11 -1
  160. data/spec/support/platform_helpers.rb +8 -0
  161. data/spec/support/shared/integration/integration_helper.rb +6 -0
  162. data/spec/support/shared/unit/execute_resource.rb +5 -0
  163. data/spec/support/shared/unit/platform_introspector.rb +7 -0
  164. data/spec/tiny_server.rb +6 -2
  165. data/spec/unit/api_client/registration_spec.rb +5 -4
  166. data/spec/unit/application_spec.rb +1 -181
  167. data/spec/unit/chef_fs/file_system/cookbook_subdir_spec.rb +34 -0
  168. data/spec/unit/cookbook/metadata_spec.rb +122 -2
  169. data/spec/unit/http_spec.rb +102 -0
  170. data/spec/unit/knife/bootstrap_spec.rb +55 -13
  171. data/spec/unit/knife/core/bootstrap_context_spec.rb +10 -3
  172. data/spec/unit/knife/ssl_check_spec.rb +7 -3
  173. data/spec/unit/knife/ssl_fetch_spec.rb +2 -2
  174. data/spec/unit/knife/status_spec.rb +13 -13
  175. data/spec/unit/knife_spec.rb +26 -2
  176. data/spec/unit/lwrp_spec.rb +1 -1
  177. data/spec/unit/mixin/properties_spec.rb +97 -0
  178. data/spec/unit/mixin/proxified_socket_spec.rb +94 -0
  179. data/spec/unit/mixin/subclass_directive_spec.rb +45 -0
  180. data/spec/unit/node_spec.rb +9 -1
  181. data/spec/unit/policy_builder/policyfile_spec.rb +2 -0
  182. data/spec/unit/property/validation_spec.rb +14 -12
  183. data/spec/unit/property_spec.rb +56 -0
  184. data/spec/unit/provider/deploy_spec.rb +1 -1
  185. data/spec/unit/provider/dsc_resource_spec.rb +63 -24
  186. data/spec/unit/provider/execute_spec.rb +95 -28
  187. data/spec/unit/provider/package/dpkg_spec.rb +185 -96
  188. data/spec/unit/provider/package/windows/exe_spec.rb +251 -0
  189. data/spec/unit/provider/package/windows/msi_spec.rb +94 -10
  190. data/spec/unit/provider/package/windows_spec.rb +227 -26
  191. data/spec/unit/provider/package/yum_spec.rb +6 -0
  192. data/spec/unit/provider/package_spec.rb +495 -366
  193. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +62 -36
  194. data/spec/unit/provider/script_spec.rb +2 -2
  195. data/spec/unit/provider/service/solaris_smf_service_spec.rb +110 -39
  196. data/spec/unit/provider/service/upstart_service_spec.rb +19 -0
  197. data/spec/unit/provider/user/dscl_spec.rb +14 -0
  198. data/spec/unit/provider/user/windows_spec.rb +2 -2
  199. data/spec/unit/provider/user_spec.rb +9 -0
  200. data/spec/unit/provider_resolver_spec.rb +6 -30
  201. data/spec/unit/recipe_spec.rb +46 -20
  202. data/spec/unit/resource/chef_gem_spec.rb +1 -1
  203. data/spec/unit/resource/dsc_resource_spec.rb +14 -3
  204. data/spec/unit/resource/ksh_spec.rb +40 -0
  205. data/spec/unit/resource/registry_key_spec.rb +2 -2
  206. data/spec/unit/resource/resource_notification_spec.rb +44 -45
  207. data/spec/unit/resource_reporter_spec.rb +7 -0
  208. data/spec/unit/resource_spec.rb +268 -253
  209. data/spec/unit/rest_spec.rb +2 -2
  210. data/spec/unit/run_list/run_list_expansion_spec.rb +18 -3
  211. data/spec/unit/search/query_spec.rb +19 -1
  212. data/spec/unit/util/powershell/ps_credential_spec.rb +8 -1
  213. data/spec/unit/windows_service_spec.rb +83 -38
  214. data/tasks/external_tests.rb +19 -9
  215. data/tasks/rspec.rb +1 -1
  216. metadata +64 -15
  217. data/spec/support/pedant/Gemfile +0 -3
  218. data/spec/support/pedant/pedant_config.rb +0 -129
  219. data/spec/support/pedant/run_pedant.rb +0 -63
  220. data/spec/support/pedant/stickywicket.pem +0 -27
  221. data/spec/unit/provider/package_spec.rbe +0 -0
@@ -22,6 +22,7 @@ require 'chef/mixin/deep_merge'
22
22
 
23
23
  require 'chef/role'
24
24
  require 'chef/rest'
25
+ require 'chef/json_compat'
25
26
 
26
27
  class Chef
27
28
  class RunList
@@ -54,6 +55,13 @@ class Chef
54
55
  # * Duplicate roles are not shown.
55
56
  attr_reader :run_list_trace
56
57
 
58
+ # Like run list trace but instead of saving the entries as strings it saves their objects
59
+ # The to_json method uses this list to construct json.
60
+ attr_reader :better_run_list_trace
61
+
62
+ attr_reader :all_missing_roles
63
+ attr_reader :role_errors
64
+
57
65
  def initialize(environment, run_list_items, source=nil)
58
66
  @environment = environment
59
67
  @missing_roles_with_including_role = Array.new
@@ -68,6 +76,9 @@ class Chef
68
76
 
69
77
  @applied_roles = {}
70
78
  @run_list_trace = Hash.new {|h, key| h[key] = [] }
79
+ @better_run_list_trace = Hash.new {|h, key| h[key] = [] }
80
+ @all_missing_roles = {}
81
+ @role_errors = {}
71
82
  end
72
83
 
73
84
  # Did we find any errors (expanding roles)?
@@ -124,6 +135,7 @@ class Chef
124
135
  def role_not_found(name, included_by)
125
136
  Chef::Log.error("Role #{name} (included by '#{included_by}') is in the runlist but does not exist. Skipping expand.")
126
137
  @missing_roles_with_including_role << [name, included_by]
138
+ @all_missing_roles[name] = true
127
139
  nil
128
140
  end
129
141
 
@@ -131,6 +143,15 @@ class Chef
131
143
  @missing_roles_with_including_role.map {|item| item.first }
132
144
  end
133
145
 
146
+ def to_json(*a)
147
+ Chef::JSONCompat.to_json(to_hash, *a)
148
+ end
149
+
150
+ def to_hash
151
+ seen_items = {:recipe => {}, :role => {}}
152
+ {:id => @environment, :run_list => convert_run_list_trace('top level', seen_items)}
153
+ end
154
+
134
155
  private
135
156
 
136
157
  # these methods modifies internal state based on arguments, so hide it.
@@ -140,8 +161,10 @@ class Chef
140
161
  end
141
162
 
142
163
  def expand_run_list_items(items, included_by="top level")
164
+
143
165
  if entry = items.shift
144
166
  @run_list_trace[included_by.to_s] << entry.to_s
167
+ @better_run_list_trace[included_by.to_s] << entry
145
168
 
146
169
  case entry.type
147
170
  when :recipe
@@ -156,8 +179,26 @@ class Chef
156
179
  end
157
180
  end
158
181
 
182
+ # Recursive helper to decode the non-nested hash form back into a tree
183
+ def convert_run_list_trace(base, seen_items)
184
+ @better_run_list_trace[base].map do |item|
185
+ skipped = seen_items[item.type][item.name]
186
+ seen_items[item.type][item.name] = true
187
+ case item.type
188
+ when :recipe
189
+ {:type => 'recipe', :name => item.name, :version => item.version, :skipped => !!skipped}
190
+ when :role
191
+ error = @role_errors[item.name]
192
+ missing = @all_missing_roles[item.name]
193
+ {:type => :role, :name => item.name, :children => (missing || error || skipped) ? [] : convert_run_list_trace(item.to_s, seen_items),
194
+ :missing => missing, :error => error, :skipped => skipped}
195
+ end
196
+ end
197
+ end
198
+
159
199
  end
160
200
 
201
+
161
202
  # Expand a run list from disk. Suitable for chef-solo
162
203
  class RunListExpansionFromDisk < RunListExpansion
163
204
 
@@ -184,8 +225,14 @@ class Chef
184
225
  else
185
226
  raise
186
227
  end
228
+ rescue Exception => e
229
+ @role_errors[name] = e.to_s
230
+ raise
187
231
  end
232
+
188
233
  end
189
234
 
190
235
  end
191
236
  end
237
+
238
+
@@ -46,6 +46,31 @@ class Chef
46
46
  # Determine the appropriate provider for the given resource, then
47
47
  # execute it.
48
48
  def run_action(resource, action, notification_type=nil, notifying_resource=nil)
49
+
50
+ # If there are any before notifications, why-run the resource
51
+ # and notify anyone who needs notifying
52
+ # TODO cheffish has a bug where it passes itself instead of the run_context to us, so doesn't have before_notifications. Fix there, update dependency requirement, and remove this if statement.
53
+ before_notifications = run_context.before_notifications(resource) if run_context.respond_to?(:before_notifications)
54
+ if before_notifications && !before_notifications.empty?
55
+ whyrun_before = Chef::Config[:why_run]
56
+ begin
57
+ Chef::Config[:why_run] = true
58
+ Chef::Log.info("#{resource} running why-run #{action} action to support before action")
59
+ resource.run_action(action, notification_type, notifying_resource)
60
+ ensure
61
+ Chef::Config[:why_run] = whyrun_before
62
+ end
63
+
64
+ if resource.updated_by_last_action?
65
+ before_notifications.each do |notification|
66
+ Chef::Log.info("#{resource} sending #{notification.action} action to #{notification.resource} (before)")
67
+ run_action(notification.resource, notification.action, :before, resource)
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ # Actually run the action for realsies
49
74
  resource.run_action(action, notification_type, notifying_resource)
50
75
 
51
76
  # Execute any immediate and queue up any delayed notifications
@@ -88,8 +88,21 @@ WARNDEP
88
88
 
89
89
  if block
90
90
  response["rows"].each { |row| block.call(row) if row }
91
- unless (response["start"] + response["rows"].length) >= response["total"]
92
- args_h[:start] = response["start"] + response["rows"].length
91
+ #
92
+ # args_h[:rows] and args_h[:start] are the page size and
93
+ # start position requested of the search index backing the
94
+ # search API.
95
+ #
96
+ # The response may contain fewer rows than arg_h[:rows] if
97
+ # the page of index results included deleted nodes which
98
+ # have been filtered from the returned data. In this case,
99
+ # we still want to start the next page at start +
100
+ # args_h[:rows] to avoid asking the search backend for
101
+ # overlapping pages (which could result in duplicates).
102
+ #
103
+ next_start = response["start"] + (args_h[:rows] || response["rows"].length)
104
+ unless next_start >= response["total"]
105
+ args_h[:start] = next_start
93
106
  search(type, query, args_h, &block)
94
107
  end
95
108
  true
@@ -99,6 +112,7 @@ WARNDEP
99
112
  end
100
113
 
101
114
  private
115
+
102
116
  def validate_type(t)
103
117
  unless t.kind_of?(String) || t.kind_of?(Symbol)
104
118
  msg = "Invalid search object type #{t.inspect} (#{t.class}), must be a String or Symbol." +
@@ -64,7 +64,7 @@ class Chef
64
64
  def use_tempfile_if_missing(file)
65
65
  tempfile = nil
66
66
  unless File.exists?(file)
67
- Chef::Log.debug("file #{file} does not exist to diff against, using empty tempfile")
67
+ Chef::Log.debug("File #{file} does not exist to diff against, using empty tempfile")
68
68
  tempfile = Tempfile.new("chef-diff")
69
69
  file = tempfile.path
70
70
  end
@@ -139,7 +139,7 @@ class Chef
139
139
  return "(new content is binary, diff output suppressed)" if is_binary?(new_file)
140
140
 
141
141
  begin
142
- Chef::Log.debug("running: diff -u #{old_file} #{new_file}")
142
+ Chef::Log.debug("Running: diff -u #{old_file} #{new_file}")
143
143
  diff_str = udiff(old_file, new_file)
144
144
 
145
145
  rescue Exception => e
@@ -29,9 +29,8 @@ class Chef::Util::Powershell
29
29
  "New-Object System.Management.Automation.PSCredential('#{@username}',('#{encrypt(@password)}' | ConvertTo-SecureString))"
30
30
  end
31
31
 
32
- def to_s
33
- to_psobject
34
- end
32
+ alias to_s to_psobject
33
+ alias to_text to_psobject
35
34
 
36
35
  private
37
36
 
@@ -21,7 +21,7 @@
21
21
 
22
22
  class Chef
23
23
  CHEF_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
24
- VERSION = '12.5.1'
24
+ VERSION = '12.6.0'
25
25
  end
26
26
 
27
27
  #
@@ -182,7 +182,14 @@ class Chef
182
182
  # Win32 API Bindings
183
183
  ###############################################
184
184
 
185
- ffi_lib 'kernel32'
185
+ ffi_lib 'kernel32', 'version'
186
+
187
+ # Does not map directly to a win32 struct
188
+ # see https://msdn.microsoft.com/en-us/library/windows/desktop/ms647464(v=vs.85).aspx
189
+ class Translation < FFI::Struct
190
+ layout :w_lang, :WORD,
191
+ :w_code_page, :WORD
192
+ end
186
193
 
187
194
  =begin
188
195
  typedef struct _FILETIME {
@@ -470,6 +477,34 @@ BOOL WINAPI DeviceIoControl(
470
477
  #);
471
478
  safe_attach_function :GetVolumeNameForVolumeMountPointW, [:LPCTSTR, :LPTSTR, :DWORD], :BOOL
472
479
 
480
+ =begin
481
+ BOOL WINAPI GetFileVersionInfo(
482
+ _In_ LPCTSTR lptstrFilename,
483
+ _Reserved_ DWORD dwHandle,
484
+ _In_ DWORD dwLen,
485
+ _Out_ LPVOID lpData
486
+ );
487
+ =end
488
+ safe_attach_function :GetFileVersionInfoW, [:LPCTSTR, :DWORD, :DWORD, :LPVOID], :BOOL
489
+
490
+ =begin
491
+ DWORD WINAPI GetFileVersionInfoSize(
492
+ _In_ LPCTSTR lptstrFilename,
493
+ _Out_opt_ LPDWORD lpdwHandle
494
+ );
495
+ =end
496
+ safe_attach_function :GetFileVersionInfoSizeW, [:LPCTSTR, :LPDWORD], :DWORD
497
+
498
+ =begin
499
+ BOOL WINAPI VerQueryValue(
500
+ _In_ LPCVOID pBlock,
501
+ _In_ LPCTSTR lpSubBlock,
502
+ _Out_ LPVOID *lplpBuffer,
503
+ _Out_ PUINT puLen
504
+ );
505
+ =end
506
+ safe_attach_function :VerQueryValueW, [:LPCVOID, :LPCTSTR, :LPVOID, :PUINT], :BOOL
507
+
473
508
  ###############################################
474
509
  # Helpers
475
510
  ###############################################
@@ -565,6 +600,21 @@ BOOL WINAPI DeviceIoControl(
565
600
  file_information
566
601
  end
567
602
 
603
+ def retrieve_file_version_info(file_name)
604
+ file_name = encode_path(file_name)
605
+ file_size = GetFileVersionInfoSizeW(file_name, nil)
606
+ if file_size == 0
607
+ Chef::ReservedNames::Win32::Error.raise!
608
+ end
609
+
610
+ version_info = FFI::MemoryPointer.new(file_size)
611
+ unless GetFileVersionInfoW(file_name, 0, file_size, version_info)
612
+ Chef::ReservedNames::Win32::Error.raise!
613
+ end
614
+
615
+ version_info
616
+ end
617
+
568
618
  end
569
619
  end
570
620
  end
@@ -150,6 +150,10 @@ class Chef
150
150
  Info.new(file_name)
151
151
  end
152
152
 
153
+ def self.version_info(file_name)
154
+ VersionInfo.new(file_name)
155
+ end
156
+
153
157
  def self.verify_links_supported!
154
158
  begin
155
159
  CreateSymbolicLinkW(nil)
@@ -211,3 +215,4 @@ class Chef
211
215
  end
212
216
 
213
217
  require 'chef/win32/file/info'
218
+ require 'chef/win32/file/version_info'
@@ -0,0 +1,93 @@
1
+ #
2
+ # Author:: Matt Wrock (<matt@mattwrock.com>)
3
+ # Copyright:: Copyright 2015 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/win32/file'
20
+
21
+ class Chef
22
+ module ReservedNames::Win32
23
+ class File
24
+
25
+ class VersionInfo
26
+
27
+ include Chef::ReservedNames::Win32::API::File
28
+
29
+ def initialize(file_name)
30
+ raise Errno::ENOENT, file_name unless ::File.exist?(file_name)
31
+ @file_version_info = retrieve_file_version_info(file_name)
32
+ end
33
+
34
+ # defining method for each predefined version resource string
35
+ # see https://msdn.microsoft.com/en-us/library/windows/desktop/ms647464(v=vs.85).aspx
36
+ [
37
+ :Comments,
38
+ :CompanyName,
39
+ :FileDescription,
40
+ :FileVersion,
41
+ :InternalName,
42
+ :LegalCopyright,
43
+ :LegalTrademarks,
44
+ :OriginalFilename,
45
+ :ProductName,
46
+ :ProductVersion,
47
+ :PrivateBuild,
48
+ :SpecialBuild
49
+ ].each do |method|
50
+ define_method method do
51
+ begin
52
+ get_version_info_string(method.to_s)
53
+ rescue Chef::Exceptions::Win32APIError
54
+ return nil
55
+ end
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def translation
62
+ @translation ||= begin
63
+ info_ptr = FFI::MemoryPointer.new(:pointer)
64
+ unless VerQueryValueW(@file_version_info, "\\VarFileInfo\\Translation".to_wstring, info_ptr, FFI::MemoryPointer.new(:int))
65
+ Chef::ReservedNames::Win32::Error.raise!
66
+ end
67
+
68
+ # there can potentially be multiple translations but most installers just have one
69
+ # we use the first because we use this for the version strings which are language
70
+ # agnostic. If/when we need other fields, we should we should add logic to find
71
+ # the "best" translation
72
+ trans = Translation.new(info_ptr.read_pointer)
73
+ to_hex(trans[:w_lang]) + to_hex(trans[:w_code_page])
74
+ end
75
+ end
76
+
77
+ def to_hex(integer)
78
+ integer.to_s(16).rjust(4,"0")
79
+ end
80
+
81
+ def get_version_info_string(string_key)
82
+ info_ptr = FFI::MemoryPointer.new(:pointer)
83
+ size_ptr = FFI::MemoryPointer.new(:int)
84
+ unless VerQueryValueW(@file_version_info, "\\StringFileInfo\\#{translation}\\#{string_key}".to_wstring, info_ptr, size_ptr)
85
+ Chef::ReservedNames::Win32::Error.raise!
86
+ end
87
+
88
+ info_ptr.read_pointer.read_wstring(size_ptr.read_uint)
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -79,7 +79,7 @@ class Chef
79
79
  # of the process goes away and this class is only being used
80
80
  # to synchronize chef-clients runs on a node.
81
81
  Chef::Log.error("Can not release mutex '#{name}'. This might cause issues \
82
- if the mutex is attempted to be acquired by other threads.")
82
+ if other threads attempt to acquire the mutex.")
83
83
  Chef::ReservedNames::Win32::Error.raise!
84
84
  end
85
85
  end
@@ -0,0 +1,5 @@
1
+ chef-integration-test2 (1.0-1) unstable; urgency=low
2
+
3
+ * Initial release (Closes: #CHEF-1718)
4
+
5
+ -- Joshua Timberman <joshua@opscode.com> Thu, 30 Sep 2010 09:53:45 -0600
@@ -0,0 +1,45 @@
1
+ dh_auto_configure
2
+ dh_auto_build
3
+ dh_auto_test
4
+ dh_prep
5
+ dh_installdirs
6
+ dh_auto_install
7
+ dh_install
8
+ dh_installdocs
9
+ dh_installchangelogs
10
+ dh_installexamples
11
+ dh_installman
12
+ dh_installcatalogs
13
+ dh_installcron
14
+ dh_installdebconf
15
+ dh_installemacsen
16
+ dh_installifupdown
17
+ dh_installinfo
18
+ dh_pysupport
19
+ dh_installinit
20
+ dh_installmenu
21
+ dh_installmime
22
+ dh_installmodules
23
+ dh_installlogcheck
24
+ dh_installlogrotate
25
+ dh_installpam
26
+ dh_installppp
27
+ dh_installudev
28
+ dh_installwm
29
+ dh_installxfonts
30
+ dh_bugfiles
31
+ dh_lintian
32
+ dh_gconf
33
+ dh_icons
34
+ dh_perl
35
+ dh_usrlocal
36
+ dh_link
37
+ dh_compress
38
+ dh_fixperms
39
+ dh_strip
40
+ dh_makeshlibs
41
+ dh_shlibdeps
42
+ dh_installdeb
43
+ dh_gencontrol
44
+ dh_md5sums
45
+ dh_builddeb