Module: SimpleCov::AtomicFile

Defined in:
lib/simplecov/atomic_file.rb

Overview

Replaces an artifact through a collision-safe temporary file in the destination directory, so readers see either the old or complete new file.

Class Method Summary collapse

Class Method Details

.write(path, content, binary: false) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/simplecov/atomic_file.rb', line 13

def self.write(path, content, binary: false)
  directory = File.dirname(path)
  FileUtils.mkdir_p(directory)
  mode = destination_mode(path)

  Tempfile.create([".simplecov-", ".tmp"], directory) do |temp|
    replace(temp, path, content, mode, binary: binary)
  end

  nil
end