Merge pull request #5127 from lembacon/atomic_write-sticky

pathname: `atomic_write` shouldn't make dir sticky unless world writable
This commit is contained in:
Markus Reiter 2018-10-21 03:24:53 +02:00 committed by GitHub
commit 8b3228ad8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -165,13 +165,14 @@ class Pathname
# The enclosing `mktmpdir` and the `chmod` are a workaround # The enclosing `mktmpdir` and the `chmod` are a workaround
# for https://github.com/rails/rails/pull/34037. # for https://github.com/rails/rails/pull/34037.
Dir.mktmpdir(".d", dirname) do |tmpdir| Dir.mktmpdir(".d", dirname) do |tmpdir|
should_fix_sticky_bit = dirname.world_writable? && !dirname.sticky?
FileUtils.chmod "+t", dirname if should_fix_sticky_bit
begin begin
FileUtils.chmod "+t", dirname File.atomic_write(self, tmpdir) do |file|
rescue Errno::EPERM file.write(content)
:ignore end
end ensure
File.atomic_write(self, tmpdir) do |file| FileUtils.chmod "-t", dirname if should_fix_sticky_bit
file.write(content)
end end
end end
end end