diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-05-26 14:00:03 -0700 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-05-26 16:03:04 -0700 |
commit | 1e1df2a33ded08d5c6ae7c0986f72b7057bebd4b (patch) | |
tree | d08cbb95989eda8a43ac72c7ee2a4c51ff1a32a7 | |
parent | e7d90f9c1cf3cc587d643a25cb74acd209ebcfdb (diff) | |
download | chef-1e1df2a33ded08d5c6ae7c0986f72b7057bebd4b.tar.gz |
Fix backups on windows for the file resource
The backup utility was using Dir.[], which on breaks with \ in
the path name. This code is replaces with listing the directory and
matching the correct files
This should solve #3394.
-rw-r--r-- | lib/chef/util/backup.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/chef/util/backup.rb b/lib/chef/util/backup.rb index 0cc009ca1f..6c95cedad7 100644 --- a/lib/chef/util/backup.rb +++ b/lib/chef/util/backup.rb @@ -78,8 +78,16 @@ class Chef Chef::Log.info("#{@new_resource} removed backup at #{backup_file}") end + def unsorted_backup_files + # If you replace this with Dir[], you will probably break Windows. + fn = Regexp.escape(::File.basename(path)) + Dir.entries(::File.dirname(backup_path)).select do |f| + !!(f =~ /\A#{fn}.chef-[0-9.]*\B/) + end.map {|f| ::File.join(::File.dirname(backup_path), f)} + end + def sorted_backup_files - Dir[Chef::Util::PathHelper.escape_glob(prefix, ".#{path}") + ".chef-*"].sort { |a,b| b <=> a } + unsorted_backup_files.sort { |a,b| b <=> a } end end end |