mirror of https://github.com/rails/rails
atomic write race condition
This commit is contained in:
parent
83a4fa414b
commit
44a2971e5c
|
@ -1,3 +1,5 @@
|
|||
* Improve `File.atomic_write` error handling
|
||||
|
||||
* Fix `Class#descendants` and `DescendantsTracker#descendants` compatibility with Ruby 3.1.
|
||||
|
||||
[The native `Class#descendants` was reverted prior to Ruby 3.1 release](https://bugs.ruby-lang.org/issues/14394#note-33),
|
||||
|
|
|
@ -64,6 +64,8 @@ class File
|
|||
file_name = join(dir, basename)
|
||||
FileUtils.touch(file_name)
|
||||
stat(file_name)
|
||||
rescue Errno::ENOENT
|
||||
file_name = nil
|
||||
ensure
|
||||
FileUtils.rm_f(file_name) if file_name
|
||||
end
|
||||
|
|
|
@ -83,6 +83,10 @@ class AtomicWriteTest < ActiveSupport::TestCase
|
|||
File.unlink(file_name) rescue nil
|
||||
end
|
||||
|
||||
def test_probe_stat_in_when_no_dir
|
||||
assert_nil File.probe_stat_in("/dir/does/not/exist")
|
||||
end
|
||||
|
||||
private
|
||||
def file_name
|
||||
"atomic-#{Process.pid}.file"
|
||||
|
|
Loading…
Reference in New Issue