aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorMarkus Reiter <me@reitermark.us>2018-10-01 15:32:52 +0200
committerMarkus Reiter <me@reitermark.us>2018-10-02 16:40:39 +0200
commitc08272ac2469e6982f81d4e61cecae46f89fed7b (patch)
treef1d67d51a7548813953178a47de73bdff2ecf740 /activesupport
parent96e69b5a33f44e5339345ef3c4871aba51a1e938 (diff)
downloadrails-c08272ac2469e6982f81d4e61cecae46f89fed7b.tar.gz
rails-c08272ac2469e6982f81d4e61cecae46f89fed7b.tar.bz2
rails-c08272ac2469e6982f81d4e61cecae46f89fed7b.zip
Ensure correct permission when `tmpdir` is the same as `dirname`.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/file/atomic.rb2
-rw-r--r--activesupport/test/core_ext/file_test.rb14
2 files changed, 15 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/file/atomic.rb b/activesupport/lib/active_support/core_ext/file/atomic.rb
index 8e288833b6..9deceb1bb4 100644
--- a/activesupport/lib/active_support/core_ext/file/atomic.rb
+++ b/activesupport/lib/active_support/core_ext/file/atomic.rb
@@ -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))
diff --git a/activesupport/test/core_ext/file_test.rb b/activesupport/test/core_ext/file_test.rb
index 9c97700e5d..186c863f91 100644
--- a/activesupport/test/core_ext/file_test.rb
+++ b/activesupport/test/core_ext/file_test.rb
@@ -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!"