Skip to content

Instantly share code, notes, and snippets.

@adamhjk
Created August 31, 2011 23:16
Show Gist options
  • Save adamhjk/1185022 to your computer and use it in GitHub Desktop.
Save adamhjk/1185022 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)
::File.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
@mkantor
Copy link

mkantor commented Nov 14, 2013

A safer solution would be to add a new attribute instead of re-using content for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment