Guest User

Untitled

a guest
Apr 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. sacrifice:~/chef/chef# git diff
  2. diff --git a/chef/lib/chef/config.rb b/chef/lib/chef/config.rb
  3. index 83b28d3..b02054e 100644
  4. --- a/chef/lib/chef/config.rb
  5. +++ b/chef/lib/chef/config.rb
  6. @@ -96,6 +96,7 @@ class Chef
  7. executable_path ENV['PATH'] ? ENV['PATH'].split(File::PATH_SEPARATOR) : []
  8. file_cache_path "/var/chef/cache"
  9. file_store_path "/var/chef/store"
  10. + file_backup_path nil
  11. group nil
  12. http_retry_count 5
  13. http_retry_delay 5
  14. diff --git a/chef/lib/chef/provider/file.rb b/chef/lib/chef/provider/file.rb
  15. index 4b6cc7c..e8955d6 100644
  16. --- a/chef/lib/chef/provider/file.rb
  17. +++ b/chef/lib/chef/provider/file.rb
  18. @@ -165,12 +165,16 @@ class Chef
  19. time = Time.now
  20. savetime = time.strftime("%Y%m%d%H%M%S")
  21. backup_filename = "#{@new_resource.path}.chef-#{savetime}"
  22. + prefix = Chef::Config[:file_backup_path] || ""
  23. + if Chef::Config[:file_backup_path]
  24. + FileUtils.mkdir_p(::File.dirname(Chef::Config[:file_backup_path] + backup_filename))
  25. + end
  26. Chef::Log.info("Backing up #{@new_resource} to #{backup_filename}")
  27. - FileUtils.cp(file, backup_filename)
  28. + FileUtils.cp(file, prefix + backup_filename)
  29.  
  30. # Clean up after the number of backups
  31. slice_number = @new_resource.backup - 1
  32. - backup_files = Dir["#{@new_resource.path}.chef-*"].sort { |a,b| b <=> a }
  33. + backup_files = Dir[prefix + "#{@new_resource.path}.chef-*"].sort { |a,b| b <=> a }
  34. if backup_files.length >= @new_resource.backup
  35. remainder = backup_files.slice(slice_number..-1)
  36. remainder.each do |backup_to_delete|
  37. diff --git a/chef/spec/unit/provider/file_spec.rb b/chef/spec/unit/provider/file_spec.rb
  38. index ceff5b7..e8e0d5d 100644
  39. --- a/chef/spec/unit/provider/file_spec.rb
  40. +++ b/chef/spec/unit/provider/file_spec.rb
  41. @@ -246,6 +246,19 @@ describe Chef::Provider::File do
  42. FileUtils.should_not_receive(:cp)
  43. @provider.backup
  44. end
  45. + it "should put the backup backup file in the directory specified by Chef::Config[:file_backup_path]" do
  46. + @provider.load_current_resource
  47. + @provider.new_resource.stub!(:path).and_return("/tmp/s-20080705111233")
  48. + @provider.new_resource.stub!(:backup).and_return(2)
  49. + Chef::Config.stub!(:[]).with(:file_backup_path).and_return("/some_prefix")
  50. + Dir.stub!(:[]).and_return([ "/some_prefix/tmp/s-20080705111233", "/some_prefix/tmp/s-20080705111232", "/som
  51. + FileUtils.should_receive(:mkdir_p).with("/some_prefix/tmp").once
  52. + FileUtils.should_receive(:rm).with("/some_prefix/tmp/s-20080705111232").once.and_return(true)
  53. + FileUtils.should_receive(:rm).with("/some_prefix/tmp/s-20080705111223").once.and_return(true)
  54. + FileUtils.stub!(:cp).and_return(true)
  55. + File.stub!(:exist?).and_return(true)
  56. + @provider.backup
  57. + end
  58. end
  59.  
  60. describe Chef::Provider::File, "action_create_if_missing" do
Add Comment
Please, Sign In to add comment