Method: Irc::Utils.safe_save
- Defined in:
- lib/rbot/core/utils/utils.rb
.safe_save(file) {|temp| ... } ⇒ Object
Safely (atomically) save to file, by passing a tempfile to the block and then moving the tempfile to its final location when done.
call-seq: Utils.safe_save(file, &block)
321 322 323 324 325 326 327 328 329 |
# File 'lib/rbot/core/utils/utils.rb', line 321 def Utils.safe_save(file) raise 'No safe save directory defined!' if @@safe_save_dir.nil? basename = File.basename(file) temp = Tempfile.new(basename,@@safe_save_dir) temp.binmode yield temp if block_given? temp.close File.rename(temp.path, file) end |