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.
- data/distro/arch/etc/rc.d/chef-client +15 -1
- data/distro/common/html/chef-client.8.html +4 -4
- data/distro/common/html/chef-expander.8.html +4 -4
- data/distro/common/html/chef-expanderctl.8.html +4 -4
- data/distro/common/html/chef-server-webui.8.html +4 -4
- data/distro/common/html/chef-server.8.html +4 -4
- data/distro/common/html/chef-solo.8.html +4 -4
- data/distro/common/html/chef-solr.8.html +4 -4
- data/distro/common/html/knife-bootstrap.1.html +6 -10
- data/distro/common/html/knife-client.1.html +4 -4
- data/distro/common/html/knife-configure.1.html +4 -4
- data/distro/common/html/knife-cookbook-site.1.html +6 -6
- data/distro/common/html/knife-cookbook.1.html +4 -4
- data/distro/common/html/knife-data-bag.1.html +4 -4
- data/distro/common/html/knife-environment.1.html +4 -4
- data/distro/common/html/knife-exec.1.html +4 -4
- data/distro/common/html/knife-index.1.html +4 -4
- data/distro/common/html/knife-node.1.html +5 -5
- data/distro/common/html/knife-role.1.html +4 -4
- data/distro/common/html/knife-search.1.html +4 -4
- data/distro/common/html/knife-ssh.1.html +5 -6
- data/distro/common/html/knife-status.1.html +4 -4
- data/distro/common/html/knife-tag.1.html +4 -4
- data/distro/common/html/knife.1.html +7 -8
- data/distro/common/html/shef.1.html +4 -4
- data/distro/common/man/man1/knife-bootstrap.1 +4 -4
- data/distro/common/man/man1/knife-client.1 +1 -1
- data/distro/common/man/man1/knife-configure.1 +1 -1
- data/distro/common/man/man1/knife-cookbook-site.1 +4 -4
- data/distro/common/man/man1/knife-cookbook.1 +1 -1
- data/distro/common/man/man1/knife-data-bag.1 +1 -1
- data/distro/common/man/man1/knife-environment.1 +1 -1
- data/distro/common/man/man1/knife-exec.1 +1 -1
- data/distro/common/man/man1/knife-index.1 +1 -1
- data/distro/common/man/man1/knife-node.1 +2 -2
- data/distro/common/man/man1/knife-role.1 +1 -1
- data/distro/common/man/man1/knife-search.1 +1 -1
- data/distro/common/man/man1/knife-ssh.1 +3 -7
- data/distro/common/man/man1/knife-status.1 +1 -1
- data/distro/common/man/man1/knife-tag.1 +1 -1
- data/distro/common/man/man1/knife.1 +5 -9
- data/distro/common/man/man1/shef.1 +1 -1
- data/distro/common/man/man8/chef-client.8 +1 -1
- data/distro/common/man/man8/chef-expander.8 +1 -1
- data/distro/common/man/man8/chef-expanderctl.8 +1 -1
- data/distro/common/man/man8/chef-server-webui.8 +1 -1
- data/distro/common/man/man8/chef-server.8 +1 -1
- data/distro/common/man/man8/chef-solo.8 +1 -1
- data/distro/common/man/man8/chef-solr.8 +1 -1
- data/distro/common/markdown/man1/knife-bootstrap.mkd +3 -7
- data/distro/common/markdown/man1/knife-cookbook-site.mkd +3 -3
- data/distro/common/markdown/man1/knife-node.mkd +2 -2
- data/distro/common/markdown/man1/knife-ssh.mkd +2 -5
- data/distro/common/markdown/man1/knife.mkd +7 -9
- data/distro/debian/etc/init.d/chef-client +22 -1
- data/distro/redhat/etc/init.d/chef-client +12 -1
- data/distro/windows/service_manager.rb +164 -0
- data/lib/chef/application.rb +12 -6
- data/lib/chef/application/client.rb +4 -3
- data/lib/chef/application/knife.rb +7 -12
- data/lib/chef/application/solo.rb +2 -1
- data/lib/chef/application/windows_service.rb +224 -0
- data/lib/chef/checksum_cache.rb +1 -0
- data/lib/chef/client.rb +3 -16
- data/lib/chef/config.rb +42 -13
- data/lib/chef/cookbook/metadata.rb +1 -1
- data/lib/chef/cookbook/syntax_check.rb +2 -2
- data/lib/chef/cookbook_version.rb +5 -0
- data/lib/chef/daemon.rb +1 -1
- data/lib/chef/exceptions.rb +7 -1
- data/lib/chef/file_access_control.rb +13 -87
- data/lib/chef/file_access_control/unix.rb +119 -0
- data/lib/chef/file_access_control/windows.rb +257 -0
- data/lib/chef/handler/json_file.rb +7 -1
- data/lib/chef/knife.rb +10 -16
- data/lib/chef/knife/bootstrap.rb +15 -8
- data/lib/chef/knife/bootstrap/centos5-gems.erb +1 -1
- data/lib/chef/knife/bootstrap/chef-full.erb +59 -0
- data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +1 -0
- data/lib/chef/knife/configure.rb +2 -2
- data/lib/chef/knife/cookbook_site_download.rb +60 -21
- data/lib/chef/knife/cookbook_site_install.rb +16 -21
- data/lib/chef/knife/cookbook_upload.rb +77 -48
- data/lib/chef/knife/core/bootstrap_context.rb +3 -1
- data/lib/chef/knife/core/cookbook_scm_repo.rb +1 -1
- data/lib/chef/knife/core/node_editor.rb +1 -1
- data/lib/chef/knife/core/subcommand_loader.rb +1 -1
- data/lib/chef/knife/core/ui.rb +3 -2
- data/lib/chef/knife/help_topics.rb +1 -1
- data/lib/chef/knife/node_run_list_add.rb +14 -6
- data/lib/chef/knife/node_run_list_remove.rb +3 -3
- data/lib/chef/knife/ssh.rb +32 -13
- data/lib/chef/mash.rb +14 -0
- data/lib/chef/mixin/command.rb +1 -0
- data/lib/chef/mixin/command/unix.rb +5 -0
- data/lib/chef/mixin/convert_to_class_name.rb +2 -0
- data/lib/chef/mixin/deep_merge.rb +40 -18
- data/lib/chef/mixin/enforce_ownership_and_permissions.rb +39 -0
- data/lib/chef/mixin/language.rb +89 -3
- data/lib/chef/mixin/language_include_recipe.rb +8 -4
- data/lib/chef/mixin/path_sanity.rb +67 -0
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +19 -11
- data/lib/chef/mixin/securable.rb +152 -0
- data/lib/chef/mixin/shell_out.rb +1 -1
- data/lib/chef/mixin/template.rb +8 -3
- data/lib/chef/mixins.rb +3 -0
- data/lib/chef/monkey_patches/moneta.rb +50 -0
- data/lib/chef/monkey_patches/string.rb +1 -1
- data/lib/chef/node.rb +2 -1
- data/lib/chef/platform.rb +34 -0
- data/lib/chef/provider.rb +23 -21
- data/lib/chef/provider/cron.rb +17 -12
- data/lib/chef/provider/cron/solaris.rb +6 -18
- data/lib/chef/provider/deploy.rb +14 -15
- data/lib/chef/provider/deploy/timestamped.rb +0 -1
- data/lib/chef/provider/directory.rb +1 -3
- data/lib/chef/provider/execute.rb +2 -2
- data/lib/chef/provider/file.rb +1 -75
- data/lib/chef/provider/git.rb +11 -9
- data/lib/chef/provider/group/gpasswd.rb +14 -9
- data/lib/chef/provider/link.rb +28 -59
- data/lib/chef/provider/mdadm.rb +2 -2
- data/lib/chef/provider/mount/mount.rb +1 -1
- data/lib/chef/provider/package.rb +10 -6
- data/lib/chef/provider/package/apt.rb +3 -1
- data/lib/chef/provider/package/dpkg.rb +1 -1
- data/lib/chef/provider/package/portage.rb +6 -3
- data/lib/chef/provider/package/rubygems.rb +75 -6
- data/lib/chef/provider/package/smartos.rb +84 -0
- data/lib/chef/provider/package/yum-dump.py +3 -2
- data/lib/chef/provider/package/yum.rb +51 -10
- data/lib/chef/provider/remote_directory.rb +24 -3
- data/lib/chef/provider/remote_file.rb +0 -6
- data/lib/chef/provider/route.rb +3 -3
- data/lib/chef/provider/service/debian.rb +2 -2
- data/lib/chef/provider/service/freebsd.rb +1 -1
- data/lib/chef/provider/service/macosx.rb +125 -0
- data/lib/chef/provider/service/windows.rb +5 -1
- data/lib/chef/provider/subversion.rb +10 -7
- data/lib/chef/providers.rb +3 -0
- data/lib/chef/resource.rb +181 -87
- data/lib/chef/resource/apt_package.rb +10 -1
- data/lib/chef/resource/chef_gem.rb +53 -0
- data/lib/chef/resource/conditional.rb +3 -0
- data/lib/chef/resource/cookbook_file.rb +12 -6
- data/lib/chef/resource/cron.rb +9 -0
- data/lib/chef/resource/directory.rb +14 -31
- data/lib/chef/resource/execute.rb +11 -9
- data/lib/chef/resource/file.rb +9 -33
- data/lib/chef/resource/link.rb +13 -8
- data/lib/chef/resource/mdadm.rb +10 -1
- data/lib/chef/resource/remote_directory.rb +13 -2
- data/lib/chef/resource/remote_file.rb +14 -7
- data/lib/chef/resource/smartos_package.rb +36 -0
- data/lib/chef/resource/template.rb +12 -5
- data/lib/chef/resource_platform_map.rb +153 -0
- data/lib/chef/resources.rb +2 -0
- data/lib/chef/rest.rb +55 -10
- data/lib/chef/rest/auth_credentials.rb +1 -0
- data/lib/chef/rest/rest_request.rb +24 -8
- data/lib/chef/role.rb +8 -2
- data/lib/chef/run_list.rb +1 -1
- data/lib/chef/run_list/run_list_expansion.rb +2 -2
- data/lib/chef/run_list/run_list_item.rb +7 -0
- data/lib/chef/runner.rb +4 -0
- data/lib/chef/shef.rb +2 -2
- data/lib/chef/shef/shef_session.rb +4 -5
- data/lib/chef/shell_out.rb +2 -245
- data/lib/chef/util/file_edit.rb +99 -89
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/api.rb +349 -0
- data/lib/chef/win32/api/error.rb +921 -0
- data/lib/chef/win32/api/file.rb +289 -0
- data/lib/chef/win32/api/memory.rb +105 -0
- data/lib/chef/win32/api/process.rb +40 -0
- data/lib/chef/win32/api/psapi.rb +51 -0
- data/lib/chef/win32/api/security.rb +341 -0
- data/lib/chef/win32/api/system.rb +192 -0
- data/lib/chef/win32/api/unicode.rb +178 -0
- data/lib/chef/win32/error.rb +73 -0
- data/lib/chef/win32/file.rb +117 -0
- data/lib/chef/win32/file/info.rb +100 -0
- data/lib/chef/win32/handle.rb +48 -0
- data/lib/chef/win32/memory.rb +101 -0
- data/lib/chef/win32/process.rb +84 -0
- data/lib/chef/win32/security.rb +489 -0
- data/lib/chef/win32/security/ace.rb +125 -0
- data/lib/chef/win32/security/acl.rb +101 -0
- data/lib/chef/win32/security/securable_object.rb +109 -0
- data/lib/chef/win32/security/security_descriptor.rb +93 -0
- data/lib/chef/win32/security/sid.rb +199 -0
- data/lib/chef/win32/security/token.rb +64 -0
- data/lib/chef/win32/unicode.rb +43 -0
- data/lib/chef/win32/version.rb +119 -0
- metadata +104 -158
- data/lib/chef/shell_out/unix.rb +0 -223
- 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
|