summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-05-26 14:00:03 -0700
committerBryan McLellan <btm@loftninjas.org>2015-05-27 14:15:54 -0400
commit9f27eebc869c589a246e8080c8d90165d1b95a44 (patch)
tree32a0acd9ecc7b52db99657e1b2dfcf0ad2e76588
parentfae1bbcf4262dd550f1c411fdb5546828a708bdb (diff)
downloadchef-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.
-rw-r--r--lib/chef/util/backup.rb10
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