From 4901e5117d1eed5c76736a1ea5a5279e87aee079 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Mon, 17 Aug 2020 14:26:15 -0700 Subject: fix to render file_cache_path more "windows-native" Signed-off-by: Lamont Granquist --- chef-config/lib/chef-config/path_helper.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'chef-config/lib/chef-config/path_helper.rb') 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 -- cgit v1.2.1