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
@@ -0,0 +1,178 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright 2011 Opscode, 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/api'
20
+
21
+ class Chef
22
+ module Win32
23
+ module API
24
+ module Unicode
25
+ extend Chef::Win32::API
26
+
27
+ ###############################################
28
+ # Win32 API Constants
29
+ ###############################################
30
+
31
+ CP_ACP = 0
32
+ CP_OEMCP = 1
33
+ CP_MACCP = 2
34
+ CP_THREAD_ACP = 3
35
+ CP_SYMBOL = 42
36
+ CP_UTF7 = 65000
37
+ CP_UTF8 = 65001
38
+
39
+ MB_PRECOMPOSED = 0x00000001
40
+ MB_COMPOSITE = 0x00000002
41
+ MB_USEGLYPHCHARS = 0x00000004
42
+ MB_ERR_INVALID_CHARS = 0x00000008
43
+
44
+ WC_COMPOSITECHECK = 0x00000200
45
+ WC_DISCARDNS = 0x00000010
46
+ WC_SEPCHARS = 0x00000020
47
+ WC_DEFAULTCHAR = 0x00000040
48
+ WC_NO_BEST_FIT_CHARS = 0x00000400
49
+
50
+ ANSI_CHARSET = 0
51
+ DEFAULT_CHARSET = 1
52
+ SYMBOL_CHARSET = 2
53
+ SHIFTJIS_CHARSET = 128
54
+ HANGEUL_CHARSET = 129
55
+ HANGUL_CHARSET = 129
56
+ GB2312_CHARSET = 134
57
+ CHINESEBIG5_CHARSET = 136
58
+ OEM_CHARSET = 255
59
+ JOHAB_CHARSET = 130
60
+ HEBREW_CHARSET = 177
61
+ ARABIC_CHARSET = 178
62
+ GREEK_CHARSET = 161
63
+ TURKISH_CHARSET = 162
64
+ VIETNAMESE_CHARSET = 163
65
+ THAI_CHARSET = 222
66
+ EASTEUROPE_CHARSET = 238
67
+ RUSSIAN_CHARSET = 204
68
+
69
+ IS_TEXT_UNICODE_ASCII16 = 0x0001
70
+ IS_TEXT_UNICODE_REVERSE_ASCII16 = 0x0010
71
+ IS_TEXT_UNICODE_STATISTICS = 0x0002
72
+ IS_TEXT_UNICODE_REVERSE_STATISTICS = 0x0020
73
+ IS_TEXT_UNICODE_CONTROLS = 0x0004
74
+ IS_TEXT_UNICODE_REVERSE_CONTROLS = 0x0040
75
+ IS_TEXT_UNICODE_SIGNATURE = 0x0008
76
+ IS_TEXT_UNICODE_REVERSE_SIGNATURE = 0x0080
77
+ IS_TEXT_UNICODE_ILLEGAL_CHARS = 0x0100
78
+ IS_TEXT_UNICODE_ODD_LENGTH = 0x0200
79
+ IS_TEXT_UNICODE_DBCS_LEADBYTE = 0x0400
80
+ IS_TEXT_UNICODE_NULL_BYTES = 0x1000
81
+ IS_TEXT_UNICODE_UNICODE_MASK = 0x000F
82
+ IS_TEXT_UNICODE_REVERSE_MASK = 0x00F0
83
+ IS_TEXT_UNICODE_NOT_UNICODE_MASK = 0x0F00
84
+ IS_TEXT_UNICODE_NOT_ASCII_MASK = 0xF000
85
+
86
+ TCI_SRCCHARSET = 1
87
+ TCI_SRCCODEPAGE = 2
88
+ TCI_SRCFONTSIG = 3
89
+ TCI_SRCLOCALE = 0x100
90
+
91
+ ###############################################
92
+ # Win32 API Bindings
93
+ ###############################################
94
+
95
+ ffi_lib 'kernel32', 'advapi32'
96
+
97
+ =begin
98
+ BOOL IsTextUnicode(
99
+ __in const VOID *lpv,
100
+ __in int iSize,
101
+ __inout LPINT lpiResult
102
+ );
103
+ =end
104
+ attach_function :IsTextUnicode, [:pointer, :int, :LPINT], :BOOL
105
+
106
+ =begin
107
+ int MultiByteToWideChar(
108
+ __in UINT CodePage,
109
+ __in DWORD dwFlags,
110
+ __in LPCSTR lpMultiByteStr,
111
+ __in int cbMultiByte,
112
+ __out LPWSTR lpWideCharStr,
113
+ __in int cchWideChar
114
+ );
115
+ =end
116
+ attach_function :MultiByteToWideChar, [:UINT, :DWORD, :LPCSTR, :int, :LPWSTR, :int], :int
117
+
118
+ =begin
119
+ int WideCharToMultiByte(
120
+ __in UINT CodePage,
121
+ __in DWORD dwFlags,
122
+ __in LPCWSTR lpWideCharStr,
123
+ __in int cchWideChar,
124
+ __out LPSTR lpMultiByteStr,
125
+ __in int cbMultiByte,
126
+ __in LPCSTR lpDefaultChar,
127
+ __out LPBOOL lpUsedDefaultChar
128
+ );
129
+ =end
130
+ attach_function :WideCharToMultiByte, [:UINT, :DWORD, :LPCWSTR, :int, :LPSTR, :int, :LPCSTR, :LPBOOL], :int
131
+
132
+ ###############################################
133
+ # Helpers
134
+ ###############################################
135
+
136
+ def utf8_to_wide(ustring)
137
+ # ensure it is actually UTF-8
138
+ # Ruby likes to mark binary data as ASCII-8BIT
139
+ ustring = (ustring + "").force_encoding('UTF-8') if ustring.respond_to?(:force_encoding) && ustring.encoding.name != "UTF-8"
140
+
141
+ # ensure we have the double-null termination Windows Wide likes
142
+ ustring = ustring << "\000\000" if ustring[-1].chr != "\000"
143
+
144
+ # encode it all as UTF-16LE AKA Windows Wide Character AKA Windows Unicode
145
+ ustring = begin
146
+ if ustring.respond_to?(:encode)
147
+ ustring.encode('UTF-16LE')
148
+ else
149
+ require 'iconv'
150
+ Iconv.conv("UTF-16LE", "UTF-8", ustring)
151
+ end
152
+ end
153
+ ustring
154
+ end
155
+
156
+ def wide_to_utf8(wstring)
157
+ # ensure it is actually UTF-16LE
158
+ # Ruby likes to mark binary data as ASCII-8BIT
159
+ wstring = wstring.force_encoding('UTF-16LE') if wstring.respond_to?(:force_encoding)
160
+
161
+ # encode it all as UTF-8
162
+ wstring = begin
163
+ if wstring.respond_to?(:encode)
164
+ wstring.encode('UTF-8')
165
+ else
166
+ require 'iconv'
167
+ Iconv.conv("UTF-8", "UTF-16LE", wstring)
168
+ end
169
+ end
170
+ # remove trailing CRLF and NULL characters
171
+ wstring.strip!
172
+ wstring
173
+ end
174
+
175
+ end
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,73 @@
1
+ #
2
+ # Author:: John Keiser (<jkeiser@opscode.com>)
3
+ # Copyright:: Copyright 2011 Opscode, 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/api/error'
20
+ require 'chef/win32/memory'
21
+ require 'chef/win32/unicode'
22
+ require 'chef/exceptions'
23
+
24
+ class Chef
25
+ module Win32
26
+ class Error
27
+ include Chef::Win32::API::Error
28
+ extend Chef::Win32::API::Error
29
+
30
+ def self.format_message(message_id = 0, args = {})
31
+ flags = args[:flags] || FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY
32
+ source = args[:source]
33
+ language_id = args[:language_id] || 0
34
+ varargs = args[:varargs] || [:int, 0]
35
+ buffer = FFI::MemoryPointer.new :pointer
36
+ num_chars = FormatMessageW(flags | FORMAT_MESSAGE_ALLOCATE_BUFFER, source, message_id, language_id, buffer, 0, *varargs)
37
+ if num_chars == 0
38
+ raise!
39
+ end
40
+
41
+ # Extract the string
42
+ begin
43
+ return buffer.read_pointer.read_wstring(num_chars)
44
+ ensure
45
+ Chef::Win32::Memory.local_free(buffer.read_pointer)
46
+ end
47
+ end
48
+
49
+ def self.get_last_error
50
+ GetLastError()
51
+ end
52
+
53
+ # Raises the last error. This should only be called by
54
+ # Win32 API wrapper functions, and then only when wrapped
55
+ # in an if() statement (since it unconditionally exits)
56
+ # === Returns
57
+ # nil::: always returns nil when it does not raise
58
+ # === Raises
59
+ # Chef::Exceptions::Win32APIError:::
60
+ def self.raise!(message = nil)
61
+ code = get_last_error
62
+ msg = format_message(code).strip
63
+ formatted_message = ""
64
+ formatted_message << message if message
65
+ formatted_message << "---- Begin Win32 API output ----\n"
66
+ formatted_message << "System Error Code: #{code}\n"
67
+ formatted_message << "System Error Message: #{msg}\n"
68
+ formatted_message << "---- End Win32 API output ----\n"
69
+ raise Chef::Exceptions::Win32APIError, msg + "\n" + formatted_message
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,117 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Author:: Mark Mzyk (<mmzyk@ospcode.com>)
4
+ # Copyright:: Copyright 2011 Opscode, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require 'chef/win32/api/file'
21
+ require 'chef/win32/api/security'
22
+ require 'chef/win32/error'
23
+
24
+ class Chef
25
+ module Win32
26
+ class File
27
+ include Chef::Win32::API::File
28
+ extend Chef::Win32::API::File
29
+
30
+ # Creates a symbolic link called +new_name+ for the file or directory
31
+ # +old_name+.
32
+ #
33
+ # This method requires Windows Vista or later to work. Otherwise, it
34
+ # returns nil as per MRI.
35
+ #
36
+ def self.link(old_name, new_name)
37
+ raise Errno::ENOENT, "(#{old_name}, #{new_name})" unless ::File.exist?(old_name)
38
+ # TODO do a check for CreateHardLinkW and
39
+ # raise NotImplemented exception on older Windows
40
+ old_name = encode_path(old_name)
41
+ new_name = encode_path(new_name)
42
+ unless CreateHardLinkW(new_name, old_name, nil)
43
+ Chef::Win32::Error.raise!
44
+ end
45
+ end
46
+
47
+ # Creates a symbolic link called +new_name+ for the file or directory
48
+ # +old_name+.
49
+ #
50
+ # This method requires Windows Vista or later to work. Otherwise, it
51
+ # returns nil as per MRI.
52
+ #
53
+ def self.symlink(old_name, new_name)
54
+ raise Errno::ENOENT, "(#{old_name}, #{new_name})" unless ::File.exist?(old_name)
55
+ # TODO do a check for CreateSymbolicLinkW and
56
+ # raise NotImplemented exception on older Windows
57
+ flags = ::File.directory?(old_name) ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0
58
+ old_name = encode_path(old_name)
59
+ new_name = encode_path(new_name)
60
+ unless CreateSymbolicLinkW(new_name, old_name, flags)
61
+ Chef::Win32::Error.raise!
62
+ end
63
+ end
64
+
65
+ # Return true if the named file is a symbolic link, false otherwise.
66
+ #
67
+ # This method requires Windows Vista or later to work. Otherwise, it
68
+ # always returns false as per MRI.
69
+ #
70
+ def self.symlink?(file_name)
71
+ is_symlink = false
72
+ path = encode_path(file_name)
73
+ if ::File.exists?(file_name)
74
+ if ((GetFileAttributesW(path) & FILE_ATTRIBUTE_REPARSE_POINT) > 0)
75
+ file_search_handle(file_name) do |handle, find_data|
76
+ if find_data[:dw_reserved_0] == IO_REPARSE_TAG_SYMLINK
77
+ is_symlink = true
78
+ end
79
+ end
80
+ end
81
+ end
82
+ is_symlink
83
+ end
84
+
85
+ # Returns the path of the of the symbolic link referred to by +file+.
86
+ #
87
+ # Requires Windows Vista or later. On older versions of Windows it
88
+ # will raise a NotImplementedError, as per MRI.
89
+ #
90
+ def self.readlink(link_name)
91
+ raise Errno::ENOENT, link_name unless ::File.exist?(link_name)
92
+ # TODO do a check for GetFinalPathNameByHandleW and
93
+ # raise NotImplemented exception on older Windows
94
+ file_handle(link_name) do |handle|
95
+ buffer = FFI::MemoryPointer.new(0.chr * MAX_PATH)
96
+ num_chars = GetFinalPathNameByHandleW(handle, buffer, buffer.size, FILE_NAME_NORMALIZED)
97
+ if num_chars == 0
98
+ Chef::Win32::Error.raise! #could be misleading if problem is too small buffer size as GetLastError won't report failure
99
+ end
100
+ buffer.read_wstring(num_chars).sub(path_prepender, "")
101
+ end
102
+ end
103
+
104
+ def self.info(file_name)
105
+ Info.new(file_name)
106
+ end
107
+
108
+ # ::File compat
109
+ class << self
110
+ alias :stat :info
111
+ end
112
+
113
+ end
114
+ end
115
+ end
116
+
117
+ require 'chef/win32/file/info'
@@ -0,0 +1,100 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright 2011 Opscode, 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 Win32
23
+ class File
24
+
25
+ # Objects of class Chef::Win32::File::Stat encapsulate common status
26
+ # information for Chef::Win32::File objects. The information
27
+ # is recorded at the moment the Chef::Win32::File::Stat object is
28
+ # created; changes made to the file after that point will not be reflected.
29
+ class Info
30
+
31
+ include Chef::Win32::API::File
32
+ include Chef::Win32::API
33
+
34
+ # http://msdn.microsoft.com/en-us/library/windows/desktop/aa363788(v=vs.85).aspx
35
+ def initialize(file_name)
36
+ raise Errno::ENOENT, file_name unless ::File.exist?(file_name)
37
+ @file_info = retrieve_file_info(file_name)
38
+ end
39
+
40
+ def volume_serial_number
41
+ @file_info[:dw_volume_serial_number]
42
+ end
43
+
44
+ def index
45
+ make_uint64(@file_info[:n_file_index_low], @file_info[:n_file_index_high])
46
+ end
47
+
48
+ def last_access_time
49
+ parse_time(@file_info[:ft_last_access_time])
50
+ end
51
+
52
+ def creation_time
53
+ parse_time(@file_info[:ft_creation_time])
54
+ end
55
+
56
+ def last_write_time
57
+ parse_time(@file_info[:ft_last_write_time])
58
+ end
59
+
60
+ def links
61
+ @file_info[:n_number_of_links]
62
+ end
63
+
64
+ def size
65
+ make_uint64(@file_info[:n_file_size_low], @file_info[:n_file_size_high])
66
+ end
67
+
68
+ ##############################
69
+ # ::File::Stat compat
70
+ alias :atime :last_access_time
71
+ alias :mtime :last_write_time
72
+ alias :ctime :creation_time
73
+
74
+ # we're faking it here, but this is in the spirit of ino in *nix
75
+ #
76
+ # from MSDN:
77
+ #
78
+ # "The identifier (low and high parts) and the volume serial number
79
+ # uniquely identify a file on a single computer. To determine whether
80
+ # two open handles represent the same file, combine the identifier
81
+ # and the volume serial number for each file and compare them.""
82
+ #
83
+ def ino
84
+ volume_serial_number + index
85
+ end
86
+ ##############################
87
+
88
+ # given a +Chef::Win32::API::File::FILETIME+ structure convert into a
89
+ # Ruby +Time+ object.
90
+ #
91
+ def parse_time(file_time_struct)
92
+ wtime_to_time(make_uint64(file_time_struct[:dw_low_date_time],
93
+ file_time_struct[:dw_high_date_time]))
94
+ end
95
+
96
+
97
+ end
98
+ end
99
+ end
100
+ end