diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-05-26 14:00:03 -0700 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2015-05-27 14:15:54 -0400 |
commit | 9f27eebc869c589a246e8080c8d90165d1b95a44 (patch) | |
tree | 32a0acd9ecc7b52db99657e1b2dfcf0ad2e76588 /lib/chef/util/backup.rb | |
parent | fae1bbcf4262dd550f1c411fdb5546828a708bdb (diff) | |
download | chef-9f27eebc869c589a246e8080c8d90165d1b95a44.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.
Diffstat (limited to 'lib/chef/util/backup.rb')
-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 |