Fix atomic_write inside non-sticky directory.

This commit is contained in:
Markus Reiter 2018-10-01 10:40:36 +02:00
parent 38287e6309
commit 071108b868

View File

@ -160,9 +160,16 @@ class Pathname
open("a", *open_args) { |f| f.puts(content) }
end
# NOTE always overwrites
# NOTE: This always overwrites.
def atomic_write(content)
# The enclosing `mktmpdir` and the `chmod` are a workaround
# for https://github.com/rails/rails/pull/34037.
Dir.mktmpdir(".d", dirname) do |tmpdir|
begin
FileUtils.chmod "+t", dirname
rescue Errno::EPERM
:ignore
end
File.atomic_write(self, tmpdir) do |file|
file.write(content)
end