Permalink
Browse files

Merge pull request #8027 from daenney/master

Atomic.rb assumes it may chown/chmod a file but doesn't handle the EPERM error.

Conflicts:
	activesupport/CHANGELOG.md
	guides/source/active_support_core_extensions.md
  • Loading branch information...
1 parent 5222a33 commit 3d25292ae3da2e8cf7a501c69b331a8d08344c59 @fxn fxn committed with carlosantoniodasilva Oct 29, 2012
@@ -1,3 +1,10 @@
+## Rails 3.2.10 (unreleased)
+
+* Handle the possible Permission Denied errors atomic.rb might trigger due to
+ its chown and chmod calls. [Backport #8027]
+
+ *Daniele Sluijters*
+
## Rails 3.2.9 (unreleased)
* Add logger.push_tags and .pop_tags to complement logger.tagged:
@@ -36,7 +36,12 @@ def self.atomic_write(file_name, temp_dir = Dir.tmpdir)
FileUtils.mv(temp_file.path, file_name)
# Set correct permissions on new file
- chown(old_stat.uid, old_stat.gid, file_name)
- chmod(old_stat.mode, file_name)
+ begin
+ chown(old_stat.uid, old_stat.gid, file_name)
+ # This operation will affect filesystem ACL's
+ chmod(old_stat.mode, file_name)
+ rescue Errno::EPERM
+ # Changing file ownership failed, moving on.
+ end
end
end
@@ -3615,7 +3615,9 @@ File.atomic_write(joined_asset_path) do |cache|
end
</ruby>
-To accomplish this +atomic_write+ creates a temporary file. That's the file the code in the block actually writes to. On completion, the temporary file is renamed, which is an atomic operation on POSIX systems. If the target file exists +atomic_write+ overwrites it and keeps owners and permissions.
+To accomplish this `atomic_write` creates a temporary file. That's the file the code in the block actually writes to. On completion, the temporary file is renamed, which is an atomic operation on POSIX systems. If the target file exists `atomic_write` overwrites it and keeps owners and permissions. However there are a few cases where `atomic_write` cannot change the file ownership or permissions, this error is caught and skipped over trusting in the user/filesystem to ensure the file is accessible to the processes that need it.
+
+NOTE. Due to the chmod operation `atomic_write` performs, if the target file has an ACL set on it this ACL will be recalculated/modified.
WARNING. Note you can't append with +atomic_write+.

0 comments on commit 3d25292

Please sign in to comment.