mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ensure correct permission when tmpdir
is the same as dirname
.
This commit is contained in:
parent
96e69b5a33
commit
c08272ac24
2 changed files with 15 additions and 1 deletions
|
@ -29,7 +29,7 @@ class File
|
|||
old_stat = if exist?(file_name)
|
||||
# Get original file permissions
|
||||
stat(file_name)
|
||||
elsif temp_dir != dirname(file_name)
|
||||
else
|
||||
# If not possible, probe which are the default permissions in the
|
||||
# destination directory.
|
||||
probe_stat_in(dirname(file_name))
|
||||
|
|
|
@ -59,6 +59,20 @@ class AtomicWriteTest < ActiveSupport::TestCase
|
|||
File.unlink(file_name) rescue nil
|
||||
end
|
||||
|
||||
def test_atomic_write_preserves_file_permissions_same_directory
|
||||
Dir.mktmpdir do |temp_dir|
|
||||
File.chmod 0700, temp_dir
|
||||
|
||||
probed_permissions = File.probe_stat_in(temp_dir).mode.to_s(8)
|
||||
|
||||
File.atomic_write(File.join(temp_dir, file_name), &:close)
|
||||
|
||||
actual_permissions = File.stat(File.join(temp_dir, file_name)).mode.to_s(8)
|
||||
|
||||
assert_equal actual_permissions, probed_permissions
|
||||
end
|
||||
end
|
||||
|
||||
def test_atomic_write_returns_result_from_yielded_block
|
||||
block_return_value = File.atomic_write(file_name, Dir.pwd) do |file|
|
||||
"Hello world!"
|
||||
|
|
Loading…
Reference in a new issue