本文介绍了Errno :: EACCES在ubuntu上的Controller#upload rails roo carrierwave中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用roo在ubuntu的rails应用上解析一些excelx文件.这些是通过Carrierwave上传的.

这是我实际的控制器行:

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

以下是公开/上传的权限:

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

以下是文件的权限:

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

以下是实际的跟踪记录:

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'

在引发错误之前调用的roo上的实际行如下: @filename =文件名

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

现在,相同的代码可以在Mac上的dev上完美运行.运行的服务器在开发人员的ubuntu上也是puma.我已经检查了权限,并且在Mac上也有相同的权限.我检查了拥有该文件夹的用户与运行服务器的用户是否相同.

有什么想法吗?我想念什么吗?

我也注意到跟踪中的错误消息:

Permission denied - oo_2895_1872934321

2895是正在运行的Puma服务器的PID.而且,如果我通过上传文件的实际路径而不是#{filex.store_path},结果不会改变.

谢谢!

解决方案

是的!我的假设是正确的...

我看过: https://github.com /hmcgowan/roo/blob/master/lib/roo/excelx.rb 来查找处理Excel文件时roo的作用.这就是我发现的:

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调用ENV ['ROO_TMP']. ROO_TMP是在roo的1..1.0版本中引入的,这就是为什么它以前可以正常工作的原因.

在我的情况下,ENV ['ROO_TMP']返回nil.

所以我确实导出了ROO_TMP =/var/www/tmp进行测试.然后按chown -R用户名/var/www/tmp.

现在:

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

这使一切正常,我能够处理我的文件了:)

对我表示敬意!

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!

解决方案

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!

这篇关于Errno :: EACCES在ubuntu上的Controller#upload rails roo carrierwave中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-20 08:54