Commit 331ae182 by Mathieu Lemoine Committed by djcp

[filesystem storage] Create :override_file_permissions option

This allows you to set custom file permissions on files created by
Paperclip.  Set the :override_file_permissions option to the octal file
permission you want - 0666 is the default. If you set
:override_file_permissions to false, then we will skip the explicit
chmod entirely. This makes filesystem storage a bit friendlier to filesystems
that don't support unix file permissions.
parent 4b8dce44
......@@ -35,7 +35,10 @@ module Paperclip
new_file.write(chunk)
end
end
FileUtils.chmod(0666&~File.umask, path(style_name))
unless @options[:override_file_permissions] == false
resolved_chmod = (@options[:override_file_permissions]&~0111) || (0666&~File.umask)
FileUtils.chmod( resolved_chmod, path(style_name) )
end
file.rewind
end
......
......@@ -293,6 +293,35 @@ class IntegrationTest < Test::Unit::TestCase
end
end
[0666,0664,0640].each do |perms|
context "when the perms are #{perms}" do
setup do
rebuild_model :override_file_permissions => perms
@dummy = Dummy.new
@file = File.new(fixture_file("5k.png"), 'rb')
end
teardown do
@file.close
end
should "respect the current perms" do
@dummy.avatar = @file
@dummy.save
assert_equal perms, File.stat(@dummy.avatar.path).mode & 0777
end
end
end
should "skip chmod operation, when override_file_permissions is set to false (e.g. useful when using CIFS mounts)" do
FileUtils.expects(:chmod).never
rebuild_model :override_file_permissions => false
dummy = Dummy.create!
dummy.avatar = @file
dummy.save
end
context "A model with a filesystem attachment" do
setup do
rebuild_model :styles => { :large => "300x300>",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment