Skip to content

Instantly share code, notes, and snippets.

@hh
Forked from adamhjk/file_provider_copy.rb
Last active December 10, 2015 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hh/4384614 to your computer and use it in GitHub Desktop.
Save hh/4384614 to your computer and use it in GitHub Desktop.
require 'fileutils'
class Chef
class Provider
class File
class Copy < Chef::Provider::File
def content_differs
checksum(@current_resource.path) != checksum(@new_resource.content)
end
def set_content
if content_differs
backup @new_resource.path if ::File.exists?(@new_resource.path)
::FileUtils.cp(@new_resource.content, @new_resource.path)
Chef::Log.info("#{@new_resource.content} copied to #{@new_resource.path}")
@new_resource.updated_by_last_action(true)
end
end
end
end
end
end
file "/tmp/foo" do
content "/tmp/bar"
provider Chef::Provider::File::Copy
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment