Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission denied @ unlink_internal #133

Closed
bodrovis opened this issue Jan 28, 2015 · 17 comments
Closed

Permission denied @ unlink_internal #133

bodrovis opened this issue Jan 28, 2015 · 17 comments

Comments

@bodrovis
Copy link

Hello.

I've just integrated the gem into my project and I am getting the Permission denied @ unlink_internal error while trying to upload the file. I have a very basic setup: a User model (with Devise) that has an avatar column. Model:

  attachment :avatar

View:

    <%= f.label :avatar %>
    <%= f.attachment_field :avatar, class: 'form-control' %>

I've also added the avatar to the list of permitted params.

Full stack trace:

F:/Ruby21/lib/ruby/2.1.0/fileutils.rb:1460:in `unlink'
F:/Ruby21/lib/ruby/2.1.0/fileutils.rb:1460:in `block in remove_file'
F:/Ruby21/lib/ruby/2.1.0/fileutils.rb:1468:in `platform_support'
F:/Ruby21/lib/ruby/2.1.0/fileutils.rb:1459:in `remove_file'
F:/Ruby21/lib/ruby/2.1.0/fileutils.rb:791:in `remove_file'
F:/Ruby21/lib/ruby/2.1.0/fileutils.rb:569:in `block in rm'
F:/Ruby21/lib/ruby/2.1.0/fileutils.rb:568:in `each'
F:/Ruby21/lib/ruby/2.1.0/fileutils.rb:568:in `rm'
refile (0.5.3) lib/refile/backend/file_system.rb:59:in `delete'
refile (0.5.3) lib/refile/backend_macros.rb:11:in `block (2 levels) in verify_id'
refile (0.5.3) lib/refile/attacher.rb:133:in `delete!'
refile (0.5.3) lib/refile/attacher.rb:125:in `store!'
refile (0.5.3) lib/refile/attachment/active_record.rb:23:in `block in attachment'
activesupport (4.1.8) lib/active_support/callbacks.rb:438:in `instance_exec'
activesupport (4.1.8) lib/active_support/callbacks.rb:438:in `block in make_lambda'
activesupport (4.1.8) lib/active_support/callbacks.rb:160:in `call'
activesupport (4.1.8) lib/active_support/callbacks.rb:160:in `block in halting'
activesupport (4.1.8) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.1.8) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.8) lib/active_support/callbacks.rb:86:in `call'
activesupport (4.1.8) lib/active_support/callbacks.rb:86:in `run_callbacks'
activerecord (4.1.8) lib/active_record/callbacks.rb:302:in `create_or_update'
activerecord (4.1.8) lib/active_record/persistence.rb:103:in `save'
activerecord (4.1.8) lib/active_record/validations.rb:51:in `save'
activerecord (4.1.8) lib/active_record/attribute_methods/dirty.rb:21:in `save'
activerecord (4.1.8) lib/active_record/transactions.rb:268:in `block (2 levels) in save'
activerecord (4.1.8) lib/active_record/transactions.rb:329:in `block in with_transaction_returning_status'
activerecord (4.1.8) lib/active_record/connection_adapters/abstract/database_statements.rb:199:in `transaction'
activerecord (4.1.8) lib/active_record/transactions.rb:208:in `transaction'
activerecord (4.1.8) lib/active_record/transactions.rb:326:in `with_transaction_returning_status'
activerecord (4.1.8) lib/active_record/transactions.rb:268:in `block in save'
activerecord (4.1.8) lib/active_record/transactions.rb:283:in `rollback_active_record_state!'
activerecord (4.1.8) lib/active_record/transactions.rb:267:in `save'
activerecord (4.1.8) lib/active_record/persistence.rb:232:in `block in update'
activerecord (4.1.8) lib/active_record/transactions.rb:329:in `block in with_transaction_returning_status'
activerecord (4.1.8) lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `block in transaction'
activerecord (4.1.8) lib/active_record/connection_adapters/abstract/database_statements.rb:209:in `within_new_transaction'
activerecord (4.1.8) lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `transaction'
activerecord (4.1.8) lib/active_record/transactions.rb:208:in `transaction'
activerecord (4.1.8) lib/active_record/transactions.rb:326:in `with_transaction_returning_status'
activerecord (4.1.8) lib/active_record/persistence.rb:230:in `update'
devise (3.4.1) lib/devise/models/database_authenticatable.rb:74:in `update_with_password'
devise (3.4.1) app/controllers/devise/registrations_controller.rb:99:in `update_resource'
devise (3.4.1) app/controllers/devise/registrations_controller.rb:53:in `update'
actionpack (4.1.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.1.8) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.1.8) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.1.8) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.1.8) lib/active_support/callbacks.rb:113:in `call'
activesupport (4.1.8) lib/active_support/callbacks.rb:113:in `call'
activesupport (4.1.8) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
activesupport (4.1.8) lib/active_support/callbacks.rb:229:in `call'
activesupport (4.1.8) lib/active_support/callbacks.rb:229:in `block in halting'
activesupport (4.1.8) lib/active_support/callbacks.rb:229:in `call'
activesupport (4.1.8) lib/active_support/callbacks.rb:229:in `block in halting'
activesupport (4.1.8) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.1.8) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.8) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.1.8) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.8) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.1.8) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.8) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.1.8) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.8) lib/active_support/callbacks.rb:149:in `call'
activesupport (4.1.8) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
activesupport (4.1.8) lib/active_support/callbacks.rb:149:in `call'
activesupport (4.1.8) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
activesupport (4.1.8) lib/active_support/callbacks.rb:86:in `call'
activesupport (4.1.8) lib/active_support/callbacks.rb:86:in `run_callbacks'
actionpack (4.1.8) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.1.8) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.1.8) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.1.8) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.1.8) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.1.8) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.1.8) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.1.8) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.1.8) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.1.8) lib/abstract_controller/base.rb:136:in `process'
actionview (4.1.8) lib/action_view/rendering.rb:30:in `process'
actionpack (4.1.8) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.1.8) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.1.8) lib/action_controller/metal.rb:232:in `block in action'
actionpack (4.1.8) lib/action_dispatch/routing/route_set.rb:82:in `call'
actionpack (4.1.8) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
actionpack (4.1.8) lib/action_dispatch/routing/route_set.rb:50:in `call'
actionpack (4.1.8) lib/action_dispatch/routing/mapper.rb:45:in `call'
actionpack (4.1.8) lib/action_dispatch/journey/router.rb:73:in `block in call'
actionpack (4.1.8) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.1.8) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.1.8) lib/action_dispatch/routing/route_set.rb:678:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/flash.rb:254:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.1.8) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.1.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
activerecord (4.1.8) lib/active_record/migration.rb:380:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.1.8) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.8) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.8) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.8) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.8) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.8) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.8) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/static.rb:84:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.1.8) lib/rails/engine.rb:514:in `call'
railties (4.1.8) lib/rails/application.rb:144:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
thin (1.6.3) lib/thin/connection.rb:86:in `block in pre_process'
thin (1.6.3) lib/thin/connection.rb:84:in `catch'
thin (1.6.3) lib/thin/connection.rb:84:in `pre_process'
thin (1.6.3) lib/thin/connection.rb:53:in `process'
thin (1.6.3) lib/thin/connection.rb:39:in `receive_data'
eventmachine (1.0.4) lib/eventmachine.rb:187:in `run_machine'
eventmachine (1.0.4) lib/eventmachine.rb:187:in `run'
thin (1.6.3) lib/thin/backends/base.rb:73:in `start'
thin (1.6.3) lib/thin/server.rb:162:in `start'
rack (1.5.2) lib/rack/handler/thin.rb:16:in `run'
rack (1.5.2) lib/rack/server.rb:264:in `start'
railties (4.1.8) lib/rails/commands/server.rb:69:in `start'
railties (4.1.8) lib/rails/commands/commands_tasks.rb:81:in `block in server'
railties (4.1.8) lib/rails/commands/commands_tasks.rb:76:in `tap'
railties (4.1.8) lib/rails/commands/commands_tasks.rb:76:in `server'
railties (4.1.8) lib/rails/commands/commands_tasks.rb:40:in `run_command!'
railties (4.1.8) lib/rails/commands.rb:17:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'

So the error seems to appear when the gem tries to remove the cache file F:/rails/my/sitepoint/Synergy/tmp/uploads/cache/3051ff6b0198659c654e52df592264d7bce83341723f5b35c629fee2a3f0

The file 3051ff6b0198659c654e52df592264d7bce83341723f5b35c629fee2a3f0 does exist in the directory and I have even provided all permissions for everyone on this directory.

Using Ruby 2.1.5, Rails 4.2.0. Working on Windows 7 x64.

@bodrovis
Copy link
Author

I've used an interactive console and called the FileUtils.rm(path(id)) (from the lib/refile/backend/file_system.rb, line 59) directly and for some strange reason it did remove the file.

@jnicklas
Copy link
Contributor

Sounds like a file permissions issue. Unfortunately I know absolutely nothing about file permissions on Windows, so I'm of no help to you here :(

@bodrovis
Copy link
Author

Yeah, seems so. I am just wondering why the FileUtils.rm(path(id)) does work, the line that does not work is File.unlink.

@jnicklas
Copy link
Contributor

Could it be that you're running the console process as a different user/group or something than the server?

@bodrovis
Copy link
Author

My setup is much simpler than that: the app is running on my local Windows machine. I've added the better_errors gem (https://github.com/charliesome/better_errors) that provides an interactive console in the browser so it should work as the same user (as it is the same Ruby process).

I've found an even stranger thing. Here is the output from the console:

>> FileUtils.rm(path(id)) if exists?(id)
!! #<Errno::EACCES: Permission denied @ unlink_internal - F:/rails/my/sitepoint/Synergy/tmp/uploads/cache/7f0dc68940e056db183806f1c144f4b0488369ff4d89526659afb2ceffc2>
>> FileUtils.rm(path(id)) if exists?(id)
!! #<Errno::EACCES: Permission denied @ unlink_internal - F:/rails/my/sitepoint/Synergy/tmp/uploads/cache/7f0dc68940e056db183806f1c144f4b0488369ff4d89526659afb2ceffc2>
>> FileUtils.rm(path(id))
!! #<Errno::EACCES: Permission denied @ unlink_internal - F:/rails/my/sitepoint/Synergy/tmp/uploads/cache/289c9fe239cbf0fb42bf7896f5c2d6296a60b86033d330209aa6bdc642e8>
>> FileUtils.rm(path(id))
=> ["F:/rails/my/sitepoint/Synergy/tmp/uploads/cache/7f0dc68940e056db183806f1c144f4b0488369ff4d89526659afb2ceffc2"]

so it works from time to time.... Will try to research that further.

@jnicklas
Copy link
Contributor

Any progress on this? Would be nice to see a resolution on this issue, but I don't know how we can proceed from here.

@bodrovis
Copy link
Author

@jnicklas Unfortunately, no. If you have time to hack on this, there are free VMs with Windows here: https://www.modern.ie/en-us/virtualization-tools#downloads

@jnicklas
Copy link
Contributor

jnicklas commented Mar 1, 2015

I'm closing this issue for now. I have neither the time nor the expertise to look into this. I'll reopen this if it becomes evident that other people are having the same problem. Please comment here if you feel this needs to be reopened.

@jnicklas jnicklas closed this as completed Mar 1, 2015
@orlade
Copy link

orlade commented May 26, 2015

Not sure if this is helpful, but I had the same problem using Jekyll on Windows when trying to build a file with no extension (called LICENSE). Every other file worked fine. I notice those files from your console also have no extension, so it could be somehow related?

@bodrovis
Copy link
Author

Hm, maybe. However manual creation of such files works and what bothers me is that it also works from time to time in the console...

@smashind
Copy link

smashind commented Sep 6, 2015

I'm also getting this error using Devise and Refile.

Using Ruby 2.1.5, Rails 4.2.3, Windows 7 x64 (aka RoR on hard mode)

@luthfianto
Copy link

I'm also getting this error on Refile.

Using Ruby 2.1.5 32-bit (RailsInstaller 3.1.0), Rails 4.2.4, Windows 10 x64

@Eric-Guo
Copy link

Same, don't known why but change file_system.rb in windows like below will at least temp solve it by leaving some tmp file at C:\git\RAILS_ROOT\tmp\uploads\cache

# Delete a file from this backend
#
# @param [Sring] id           The id of the file
# @return [void]
verify_id def delete(id)
  FileUtils.rm(path(id)) if exists?(id) && !Gem.win_platform?
end

@Eric-Guo
Copy link

Eric-Guo commented Dec 5, 2015

More elegent solution maybe for ruby 2.3 is using new File::SHARE_DELETE when open file.

@Lexvum
Copy link

Lexvum commented Feb 28, 2016

Hi, unfortunately I'm having the same issue.
@Eric-Guo How do you change file_system.rb?

@Eric-Guo
Copy link

@Lexvum running gem content refile, locate the file_system.rb and change it, usually, it's located at:

C:/Ruby22/lib/ruby/gems/2.2.0/gems/refile-0.6.2/lib/refile/backend/file_system.rb

@Lexvum
Copy link

Lexvum commented Feb 28, 2016

@Eric-Guo It works, thanks for your direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants