Errno::EACCES in Controller#upload rails roo carri

2019-06-02 16:25发布

I am using roo to parse some excelx files on my rails app on ubuntu. These are uploaded with Carrierwave.

Here are my actual controller lines:

excelx_file = params[:excel_file]
filex = MetadataUploader.new
filex.store!(excelx_file)
workbook = Excelx.new("#{filex.store_path}")

Here are the permissions on public/uploads:

drwxrwxr-x 2 pirames pirames 4096 Jun 13 14:03 metadata_ingestion
drwxrwxr-x 2 pirames pirames 4096 Jun 13 14:24 tmp

Here are the permission on the file:

ls -l public/uploads/metadata_ingestion/
total 608
-rw-r--r-- 1 pirames pirames 621504 Jun 13 14:24 Bozza_Pirames_Distribuito.xlsx

Here is instead the actual trace:

Errno::EACCES in IngestionController#upload

Permission denied - oo_2895_1872934321
Rails.root: /var/www/mascarino

Application Trace | Framework Trace | Full Trace
/home/pirames/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:247:in `mkdir'
/home/pirames/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:247:in `fu_mkdir'
/home/pirames/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:176:in `block in mkdir'
/home/pirames/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:175:in `each'
/home/pirames/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:175:in `mkdir'
roo (1.10.1) lib/roo/excelx.rb:95:in `initialize'
app/controllers/ingestion_controller.rb:24:in `new'
app/controllers/ingestion_controller.rb:24:in `upload'
actionpack (3.2.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.3) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.3) lib/action_controller/metal/rendering.rb:10:in `process_action'

The actual line on roo that is called before throwing the error is the following: @filename = filename

On https://github.com/hmcgowan/roo/blob/master/lib/roo/excelx.rb

Now the same code works perfectly on dev on my mac. The server running is puma on ubuntu on dev as well. I have checked permissions and I have the same on my mac. I have checked that the user owning the folder is the same running the server.

Any ideas? Am I missing something?

Edit: I have also noticed in the error message in the trace:

Permission denied - oo_2895_1872934321

2895 is the PID of the Puma server running. And if I pass the actual path of the uploaded file instead of #{filex.store_path} the result doesn't change.

Thanks!

1条回答
够拽才男人
2楼-- · 2019-06-02 17:29

Yep! My assumptions were right...

I have looked on: https://github.com/hmcgowan/roo/blob/master/lib/roo/excelx.rb to find out what roo does when processing a excel file. So this is what I found out:

def initialize(filename, packed=nil, file_warning = :error) #, create = false)
super()
@file_warning = file_warning
@tmpdir = "oo_"+$$.to_s
@tmpdir = File.join(ENV['ROO_TMP'], @tmpdir) if ENV['ROO_TMP'] 
unless File.exists?(@tmpdir)
  FileUtils::mkdir(@tmpdir)
end
filename = open_from_uri(filename) if filename[0,7] == "http://"
filename = unzip(filename) if packed and packed == :zip

@tmpdir calls ENV['ROO_TMP']. ROO_TMP was introduced in releases >1.1.0 of roo, this is why it was previously working.

In my case ENV['ROO_TMP'] would return nil.

So I did export ROO_TMP=/var/www/tmp to test. Then chown -R username /var/www/tmp.

And now:

1.9.3p194 :001 > ENV['ROO_TMP']
=> "/var/www/tmp"

This made everything works and I was able to process my file :)

Kudos to me!

查看更多
登录 后发表回答