knife-windows 0.8.4.rc.2 → 0.8.4.rc.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 312e69c1a7545c48db33da4833dc277bfebbdd65
4
- data.tar.gz: 22c3c072c251f3448e386a18fdc61ca79d4e6657
3
+ metadata.gz: d0315c18b0b15a1b2bef30c1d7935bc581c8eb63
4
+ data.tar.gz: 6b55ca37b9a9d34a058fe8e0681f495edbc7daca
5
5
  SHA512:
6
- metadata.gz: d954be96b22329b9fd4fde3fe771d54356a1d9f72cee838f9d0a6645c327665a3fc82917abe7cd2a4f17abcd2d9c630ccf299fdf5540450a538390506ff42628
7
- data.tar.gz: eac28d271deb924f600d06314a324187532870c403d2da96153f3fe5bd23666c6fe0ebff0fb14c36fda9fb682ee05668ee7e0e4628d9f3fb4f45e169a34d342a
6
+ metadata.gz: 8de8c57ca0dae78ece565213c613a79b53b847595ee1348c5d4e6b5cb28a29e17dc3b51b3b9f8f929f796d18367ef6d17f1840078047312f07362cb672202cb4
7
+ data.tar.gz: 4409481339c29a8d5aaeca58b612105a3c6c467af2a6b52030dbd852016be480dfdba90f4dc496ac8e17a9c76b860d20f72fb7947acf81aa2a5b0a2f47e7184c
@@ -18,6 +18,10 @@
18
18
 
19
19
  require 'chef/knife/core/bootstrap_context'
20
20
 
21
+ # Chef::Util::PathHelper in Chef 11 is a bit juvenile still
22
+ require 'knife-windows/path_helper'
23
+ # require 'chef/util/path_helper'
24
+
21
25
  class Chef
22
26
  class Knife
23
27
  module Core
@@ -28,6 +32,7 @@ class Chef
28
32
  # * @run_list - the run list for the node to boostrap
29
33
  #
30
34
  class WindowsBootstrapContext < BootstrapContext
35
+ PathHelper = ::Knife::Windows::PathHelper
31
36
 
32
37
  def initialize(config, run_list, chef_config)
33
38
  @config = config
@@ -0,0 +1,157 @@
1
+ #
2
+ # Author:: Bryan McLellan <btm@loftninjas.org>
3
+ # Copyright:: Copyright (c) 2014 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
+ # Sourced from Chef::Util::PathHelper.
20
+ # Should be removed when Chef 11 catches up or we stop supporting Chef 11
21
+
22
+ module Knife
23
+ module Windows
24
+ class PathHelper
25
+ # Maximum characters in a standard Windows path (260 including drive letter and NUL)
26
+ WIN_MAX_PATH = 259
27
+
28
+ def self.dirname(path)
29
+ if Chef::Platform.windows?
30
+ # Find the first slash, not counting trailing slashes
31
+ end_slash = path.size
32
+ while true
33
+ slash = path.rindex(/[#{Regexp.escape(File::SEPARATOR)}#{Regexp.escape(path_separator)}]/, end_slash - 1)
34
+ if !slash
35
+ return end_slash == path.size ? '.' : path_separator
36
+ elsif slash == end_slash - 1
37
+ end_slash = slash
38
+ else
39
+ return path[0..slash-1]
40
+ end
41
+ end
42
+ else
43
+ ::File.dirname(path)
44
+ end
45
+ end
46
+
47
+ BACKSLASH = '\\'.freeze
48
+
49
+ def self.path_separator
50
+ if Chef::Platform.windows?
51
+ File::ALT_SEPARATOR || BACKSLASH
52
+ else
53
+ File::SEPARATOR
54
+ end
55
+ end
56
+
57
+ def self.join(*args)
58
+ args.flatten.inject do |joined_path, component|
59
+ # Joined path ends with /
60
+ joined_path = joined_path.sub(/[#{Regexp.escape(File::SEPARATOR)}#{Regexp.escape(path_separator)}]+$/, '')
61
+ component = component.sub(/^[#{Regexp.escape(File::SEPARATOR)}#{Regexp.escape(path_separator)}]+/, '')
62
+ joined_path += "#{path_separator}#{component}"
63
+ end
64
+ end
65
+
66
+ def self.validate_path(path)
67
+ if Chef::Platform.windows?
68
+ unless printable?(path)
69
+ msg = "Path '#{path}' contains non-printable characters. Check that backslashes are escaped with another backslash (e.g. C:\\\\Windows) in double-quoted strings."
70
+ Chef::Log.error(msg)
71
+ raise Chef::Exceptions::ValidationFailed, msg
72
+ end
73
+
74
+ if windows_max_length_exceeded?(path)
75
+ Chef::Log.debug("Path '#{path}' is longer than #{WIN_MAX_PATH}, prefixing with'\\\\?\\'")
76
+ path.insert(0, "\\\\?\\")
77
+ end
78
+ end
79
+
80
+ path
81
+ end
82
+
83
+ def self.windows_max_length_exceeded?(path)
84
+ # Check to see if paths without the \\?\ prefix are over the maximum allowed length for the Windows API
85
+ # http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx
86
+ unless path =~ /^\\\\?\\/
87
+ if path.length > WIN_MAX_PATH
88
+ return true
89
+ end
90
+ end
91
+
92
+ false
93
+ end
94
+
95
+ def self.printable?(string)
96
+ # returns true if string is free of non-printable characters (escape sequences)
97
+ # this returns false for whitespace escape sequences as well, e.g. \n\t
98
+ if string =~ /[^[:print:]]/
99
+ false
100
+ else
101
+ true
102
+ end
103
+ end
104
+
105
+ # Produces a comparable path.
106
+ def self.canonical_path(path, add_prefix=true)
107
+ # Rather than find an equivalent for File.absolute_path on 1.8.7, just bail out
108
+ raise NotImplementedError, "This feature is not supported on Ruby versions < 1.9" if RUBY_VERSION.to_f < 1.9
109
+
110
+ # First remove extra separators and resolve any relative paths
111
+ abs_path = File.absolute_path(path)
112
+
113
+ if Chef::Platform.windows?
114
+ # Add the \\?\ API prefix on Windows unless add_prefix is false
115
+ # Downcase on Windows where paths are still case-insensitive
116
+ abs_path.gsub!(::File::SEPARATOR, path_separator)
117
+ if add_prefix && abs_path !~ /^\\\\?\\/
118
+ abs_path.insert(0, "\\\\?\\")
119
+ end
120
+
121
+ abs_path.downcase!
122
+ end
123
+
124
+ abs_path
125
+ end
126
+
127
+ def self.cleanpath(path)
128
+ path = Pathname.new(path).cleanpath.to_s
129
+ # ensure all forward slashes are backslashes
130
+ if Chef::Platform.windows?
131
+ path = path.gsub(File::SEPARATOR, path_separator)
132
+ end
133
+ path
134
+ end
135
+
136
+ def self.paths_eql?(path1, path2)
137
+ canonical_path(path1) == canonical_path(path2)
138
+ end
139
+
140
+ # Paths which may contain glob-reserved characters need
141
+ # to be escaped before globbing can be done.
142
+ # http://stackoverflow.com/questions/14127343
143
+ def self.escape_glob(*parts)
144
+ path = cleanpath(join(*parts))
145
+ path.gsub(/[\\\{\}\[\]\*\?]/) { |x| "\\"+x }
146
+ end
147
+
148
+ def self.relative_path_from(from, to)
149
+ pathname = Pathname.new(Chef::Util::PathHelper.cleanpath(to)).relative_path_from(Pathname.new(Chef::Util::PathHelper.cleanpath(from)))
150
+ end
151
+ end
152
+ end
153
+ end
154
+
155
+ # Break a require loop when require chef/util/path_helper
156
+ require 'chef/platform'
157
+ require 'chef/exceptions'
@@ -1,6 +1,6 @@
1
1
  module Knife
2
2
  module Windows
3
- VERSION = "0.8.4.rc.2"
3
+ VERSION = "0.8.4.rc.3"
4
4
  MAJOR, MINOR, TINY = VERSION.split('.')
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-windows
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4.rc.2
4
+ version: 0.8.4.rc.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Chisamore
@@ -81,6 +81,7 @@ files:
81
81
  - lib/chef/knife/windows_helper.rb
82
82
  - lib/chef/knife/winrm.rb
83
83
  - lib/chef/knife/winrm_base.rb
84
+ - lib/knife-windows/path_helper.rb
84
85
  - lib/knife-windows/version.rb
85
86
  - spec/functional/bootstrap_download_spec.rb
86
87
  - spec/spec_helper.rb