diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2020-08-17 14:26:15 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2020-08-17 14:26:15 -0700 |
commit | 4901e5117d1eed5c76736a1ea5a5279e87aee079 (patch) | |
tree | 75123d96b1d4160b56dcdc9fd88985811f518f8c | |
parent | b2acd574f7273b823789dfd3dfbc626474dbae67 (diff) | |
download | chef-4901e5117d1eed5c76736a1ea5a5279e87aee079.tar.gz |
fix to render file_cache_path more "windows-native"
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r-- | chef-config/lib/chef-config/path_helper.rb | 20 | ||||
-rw-r--r-- | lib/chef/knife/core/windows_bootstrap_context.rb | 6 | ||||
-rw-r--r-- | spec/unit/knife/core/windows_bootstrap_context_spec.rb | 6 |
3 files changed, 26 insertions, 6 deletions
diff --git a/chef-config/lib/chef-config/path_helper.rb b/chef-config/lib/chef-config/path_helper.rb index 9d3db7621d..8fe45febfc 100644 --- a/chef-config/lib/chef-config/path_helper.rb +++ b/chef-config/lib/chef-config/path_helper.rb @@ -156,6 +156,26 @@ module ChefConfig end end + # This is not just escaping for something like use in Regexps, or in globs. For the former + # just use Regexp.escape. For the latter, use escape_glob_dir below. + # + # This is escaping where the path to be rendered is being put into a ruby file which will + # later be read back by ruby (or something similar) so we need quadruple backslashes. + # + # In order to print: + # + # file_cache_path "C:\\chef" + # + # We need to convert "C:\chef" to "C:\\\\chef" to interpolate into a string which is rendered + # into the output file with that line in it. + # + # @param path [String] the path to escape + # @return [String] the escaped path + # + def self.escapepath(path) + path.gsub(BACKSLASH, BACKSLASH * 4) + end + def self.paths_eql?(path1, path2, windows: ChefUtils.windows?) canonical_path(path1, windows: windows) == canonical_path(path2, windows: windows) end diff --git a/lib/chef/knife/core/windows_bootstrap_context.rb b/lib/chef/knife/core/windows_bootstrap_context.rb index 0b66c7f00e..7b4d517237 100644 --- a/lib/chef/knife/core/windows_bootstrap_context.rb +++ b/lib/chef/knife/core/windows_bootstrap_context.rb @@ -70,9 +70,9 @@ class Chef client_rb = <<~CONFIG chef_server_url "#{chef_config[:chef_server_url]}" validation_client_name "#{chef_config[:validation_client_name]}" - file_cache_path "#{ChefConfig::PathHelper.cleanpath(ChefConfig::Config.var_chef_dir(windows: true), windows: false)}/cache" - file_backup_path "#{ChefConfig::PathHelper.cleanpath(ChefConfig::Config.var_chef_dir(windows: true), windows: false)}/backup" - cache_options ({:path => "#{ChefConfig::PathHelper.cleanpath(ChefConfig::Config.etc_chef_dir(windows: true), windows: false)}/cache/checksums", :skip_expires => true}) + file_cache_path "#{ChefConfig::PathHelper.escapepath(ChefConfig::Config.var_chef_dir(windows: true))}\\\\cache" + file_backup_path "#{ChefConfig::PathHelper.escapepath(ChefConfig::Config.var_chef_dir(windows: true))}\\\\backup" + cache_options ({:path => "#{ChefConfig::PathHelper.escapepath(ChefConfig::Config.etc_chef_dir(windows: true))}\\\\cache\\\\checksums", :skip_expires => true}) CONFIG unless chef_config[:chef_license].nil? diff --git a/spec/unit/knife/core/windows_bootstrap_context_spec.rb b/spec/unit/knife/core/windows_bootstrap_context_spec.rb index aab351536d..76b90c955e 100644 --- a/spec/unit/knife/core/windows_bootstrap_context_spec.rb +++ b/spec/unit/knife/core/windows_bootstrap_context_spec.rb @@ -165,9 +165,9 @@ describe Chef::Knife::Core::WindowsBootstrapContext do expected = <<~EXPECTED echo.chef_server_url "http://chef.example.com:4444" echo.validation_client_name "chef-validator-testing" - echo.file_cache_path "C:/chef/cache" - echo.file_backup_path "C:/chef/backup" - echo.cache_options ^({:path =^> "C:/chef/cache/checksums", :skip_expires =^> true}^) + echo.file_cache_path "C:\\\\chef\\\\cache" + echo.file_backup_path "C:\\\\chef\\\\backup" + echo.cache_options ^({:path =^> "C:\\\\chef\\\\cache\\\\checksums", :skip_expires =^> true}^) echo.# Using default node name ^(fqdn^) echo.log_level :auto echo.log_location STDOUT |