toy / image_optim

Optimize images using multiple utilities
https://github.com/toy/image_optim
MIT License
1.52k stars 109 forks source link

what are the permissions for here? #187

Closed floodico closed 3 years ago

floodico commented 3 years ago

I'm getting this error when trying to optimize my GIF: Permission denied @ apply2files - /home/vagrant/shared/assets/3_STORAGE/9RJX86Ep99p6_preview.gif20201201-18447-usagqr.tmp

Stacktrace:

 ERROR -- : /usr/local/lib/ruby/gems/2.7.0/gems/image_optim-0.27.1/lib/image_optim/path.rb:43:in `chown'
    /usr/local/lib/ruby/gems/2.7.0/gems/image_optim-0.27.1/lib/image_optim/path.rb:43:in `chown'
    /usr/local/lib/ruby/gems/2.7.0/gems/image_optim-0.27.1/lib/image_optim/path.rb:43:in `copy_metadata'
    /usr/local/lib/ruby/gems/2.7.0/gems/image_optim-0.27.1/lib/image_optim/path.rb:86:in `block in replace_using_tmp_file'
    /usr/local/lib/ruby/gems/2.7.0/gems/fspath-3.1.2/lib/fspath.rb:74:in `block in temp_file_path'
    /usr/local/lib/ruby/gems/2.7.0/gems/fspath-3.1.2/lib/fspath.rb:34:in `open'
    /usr/local/lib/ruby/gems/2.7.0/gems/fspath-3.1.2/lib/fspath.rb:64:in `temp_file'
    /usr/local/lib/ruby/gems/2.7.0/gems/fspath-3.1.2/lib/fspath.rb:72:in `temp_file_path'
    /usr/local/lib/ruby/gems/2.7.0/gems/image_optim-0.27.1/lib/image_optim/path.rb:92:in `temp_path_with_tmp_ext'
    /usr/local/lib/ruby/gems/2.7.0/gems/image_optim-0.27.1/lib/image_optim/path.rb:84:in `replace_using_tmp_file'
    /usr/local/lib/ruby/gems/2.7.0/gems/image_optim-0.27.1/lib/image_optim/path.rb:62:in `replace'
    /usr/local/lib/ruby/2.7.0/delegate.rb:336:in `block in delegating_block'
    /usr/local/lib/ruby/gems/2.7.0/gems/image_optim-0.27.1/lib/image_optim.rb:133:in `optimize_image!'
oblakeerickson commented 3 years ago

I believe image_optim writes to the /tmp directory for caching. It's possible vagrant doesn't have permission to write to that directory?

toy commented 3 years ago

Sadly the error class is not visible, if you are running this from ruby code it could be helpful if you can wrap it with following code to see the error class:

begin
  …
rescue => e
  p e.class
end

Anyway one type of permission errors is already rescued by code that was adapted from fileutils, but in recent ruby version another type is rescued, so maybe that can be the culprit. Can you please try the version from branch https://github.com/toy/image_optim/compare/update-copy_metadata-method?

toy commented 3 years ago

Merged in e9d4f57ca19273bb91a9ecad121371a9d54533f8, please reopen this or open a new issue if the problem is not resolved