method
atomic_write

Ruby on Rails latest stable (v5.2.3)
-
0 notes -
Class: File
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3 (0)
- 2.1.0 (1)
- 2.2.1
- 2.3.2
- 2.3.8
- 3.0.0 (0)
- 3.0.9 (-2)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (0)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (11)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- What's this?
atomic_write(file_name, temp_dir = dirname(file_name))
public
Write to a file atomically. Useful for situations where you don’t want other processes or threads to see half-written files.
File.atomic_write('important.file') do |file| file.write('hello') end
This method needs to create a temporary file. By default it will create it in the same directory as the destination file. If you don’t like this behavior you can provide a different directory but it must be on the same physical filesystem as the file you’re trying to write.
File.atomic_write('/data/something.important', '/data/tmp') do |file| file.write('hello') end