-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
module FilePatch
def file(target, options={})
options[:source] ||= begin
source_file = Tempfile.new('generate')
yield(source_file) if block_given?
source_file.close
source_file.path
end
source = options[:source]
target = path(target)
copy_file = true
msg = case
when !File.exists?(target)
:create
when FileUtils.cmp(source, target)
:exists
when force_file_collision?(target)
:force
else
copy_file = false
:skip
end
log_relative msg, target
if copy_file && !pretend
dir = File.dirname(target)
FileUtils.mkdir_p(dir, :mode => 0755) unless File.exists?(dir)
FileUtils.mv(source, target, :force => true)
FileUtils.chmod(0644, target)
end
target
end
end
Metadata
Metadata
Assignees
Labels
No labels