summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2020-05-20 13:17:42 -0400
committerBryan McLellan <btm@loftninjas.org>2020-05-20 13:41:25 -0400
commit5c3fcc525332a45e80fc3cc5d550ae7866eb9364 (patch)
tree1372f682aa71c9eac3736805727fd42b3f071019
parentc5c9916d6a293f0a45831d07bf8fa00d3e845c40 (diff)
downloadchef-5c3fcc525332a45e80fc3cc5d550ae7866eb9364.tar.gz
Force the bootstrap_directory to use the right separator on Windowsbtm/fix-cannot-find-the-batch-label
ChefConfig::Config.etc_chef_dir and c_chef_dir would normally replace the standard forward slash separator with the backslash separator for Windows using PathHelper.cleanpath. However that has conditionals checking the platform and there's no clean way to modify those conditionals to take into account connection.platform in knife bootstrap when appropriate. This is a simple solution without mucking up the method definition of any more methods in chef-config. Signed-off-by: Bryan McLellan <btm@loftninjas.org>
-rw-r--r--lib/chef/knife/core/windows_bootstrap_context.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/chef/knife/core/windows_bootstrap_context.rb b/lib/chef/knife/core/windows_bootstrap_context.rb
index d2b9bc5636..f0b9021843 100644
--- a/lib/chef/knife/core/windows_bootstrap_context.rb
+++ b/lib/chef/knife/core/windows_bootstrap_context.rb
@@ -41,6 +41,21 @@ class Chef
super(config, run_list, chef_config, secret)
end
+ # This is a duplicate of ChefConfig::PathHelper.cleanpath, however
+ # this presumes Windows so we can avoid changing the method definitions
+ # across Chef, ChefConfig, and ChefUtils for the circumstance where
+ # the methods are being run for a system other than the one Ruby is
+ # executing on.
+ #
+ # We only need to cleanpath the paths that we are passing to cmd.exe,
+ # anything written to a configuration file or passed as an argument
+ # will be interpreted by ruby later and do the right thing.
+ def cleanpath(path)
+ path = Pathname.new(path).cleanpath.to_s
+ path = path.gsub(File::SEPARATOR, '\\')
+ path
+ end
+
def validation_key
if File.exist?(File.expand_path(chef_config[:validation_key]))
IO.read(File.expand_path(chef_config[:validation_key]))
@@ -262,7 +277,7 @@ class Chef
end
def bootstrap_directory
- ChefConfig::Config.etc_chef_dir(true)
+ cleanpath(ChefConfig::Config.etc_chef_dir(true))
end
def local_download_path