- # 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)
- #
- 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
-