Method: FileEdit#write_file
- Defined in:
- lib/chef/util/fileedit.rb
#write_file ⇒ Object
Make a copy of old_file and write new file out (only if file changed)
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/chef/util/fileedit.rb', line 69 def write_file # file_edited is false when there was no match in the whole file and thus no contents have changed. if file_edited backup_pathname = original_pathname + ".old" File.copy(original_pathname, backup_pathname) Tempfile.open("w") do |newfile| contents.each do |line| newfile.puts(line) end newfile.flush FileUtils.mv(newfile.path, original_pathname) end end self.file_edited = false end |