Skip to content

Instantly share code, notes, and snippets.

@jaisingh
Forked from scottedsa/file_provider_copy.rb
Created January 27, 2012 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jaisingh/1687301 to your computer and use it in GitHub Desktop.
Save jaisingh/1687301 to your computer and use it in GitHub Desktop.
Stick this in a library file...
class Chef
class Provider
class File
class Copy < Chef::Provider::File
def compare_content
checksum(@current_resource.path) == checksum(@new_resource.content)
end
def set_content
unless compare_content
backup @new_resource.path if ::File.exists?(@new_resource.path)
::FileUtils.cp_r(@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