diff options
Diffstat (limited to 'chef-config/lib/chef-config/path_helper.rb')
-rw-r--r-- | chef-config/lib/chef-config/path_helper.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/chef-config/lib/chef-config/path_helper.rb b/chef-config/lib/chef-config/path_helper.rb index 7fc79ba4a9..10384974c7 100644 --- a/chef-config/lib/chef-config/path_helper.rb +++ b/chef-config/lib/chef-config/path_helper.rb @@ -141,6 +141,7 @@ module ChefConfig canonical_path(path1) == canonical_path(path2) end + # Note: this method is deprecated. Please use escape_glob_dirs # Paths which may contain glob-reserved characters need # to be escaped before globbing can be done. # http://stackoverflow.com/questions/14127343 @@ -149,6 +150,13 @@ module ChefConfig path.gsub(/[\\\{\}\[\]\*\?]/) { |x| "\\" + x } end + # This function does not switch to backslashes for windows + # This is because only forwardslashes should be used with dir (even for windows) + def self.escape_glob_dir(*parts) + path = Pathname.new(join(*parts)).cleanpath.to_s + path.gsub(/[\\\{\}\[\]\*\?]/) { |x| "\\" + x } + end + def self.relative_path_from(from, to) Pathname.new(cleanpath(to)).relative_path_from(Pathname.new(cleanpath(from))) end |