Errno::EACCES in Controller#upload rails roo carrierwave on ubuntu

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 

Here are the permission on the file:

ls -l public/uploads/metadata_ingestion/ 
-rw-r--r-- 1 pirames pirames 621504 Jun 13 14:24 summary.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 
/ruby-1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:247:in `mkdir' 
/ruby-1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:247:in `fu_mkdir' 
/ruby-1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:176:in `block in mkdir' 
/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:175:in `each' 
/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'  

The actual line on roo that is called before throwing the error is the following: @filename = filename as I could see from:

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.

Wait a sec!

Let’s have a look at: https://github.com/hmcgowan/roo/blob/master/lib/roo/excelx.rb to find out what roo does when processing a excel file:

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!