summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2020-05-20 13:17:42 -0400
committerTim Smith <tsmith84@gmail.com>2020-05-22 09:36:46 -0700
commit51e79f5501dad23a074ed8188e93a46484880e70 (patch)
tree035fa2099f0a85e1914c9ed51fae0062d71571eb
parentc104baee48bed170ed5b656d1277a6056c047636 (diff)
downloadchef-51e79f5501dad23a074ed8188e93a46484880e70.tar.gz
Force the bootstrap_directory to use the right separator on Windows
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 aa2c61f1f5..3cd4dcece0 100644
--- a/lib/chef/knife/core/windows_bootstrap_context.rb
+++ b/lib/chef/knife/core/windows_bootstrap_context.rb
@@ -39,6 +39,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]))
@@ -260,7 +275,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