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

Avoid "permission denied" errors copying assets #135

Merged

Conversation

tomeon
Copy link
Contributor

@tomeon tomeon commented Apr 18, 2024

by running FileUtils#cp_r with the :remove_destination option enabled. This makes asset copying more robust in the face of restrictive permissions on asset file destination paths. This should be safe and backward-compatible given that the destination files (or their contents) will be fully replaced anyway.

Example case:

irb(main):001:0> FileUtils.touch('foo')
=> ["foo"]
irb(main):002:0> FileUtils.touch('bar')
=> ["bar"]
irb(main):003:0> FileUtils.chmod(0o444, 'bar')
=> ["bar"]
irb(main):004:0> FileUtils.cp_r('foo', 'bar')
Errno::EACCES: Permission denied @ rb_sysopen - bar from /nix/store/2kw126cy93rix4pmh9lcl120njnb6r7r-ruby-3.1.4/lib/ruby/3.1.0/fileutils.rb:1395:in `initialize' 
irb(main):005:0> FileUtils.cp_r('foo', 'bar', remove_destination: true) 
=> nil

Addresses simplecov-ruby/simplecov#741.

Thanks!

by running `FileUtils#cp_r` with the `:remove_destination` option
enabled.  This makes asset copying more robust in the face of
restrictive permissions on asset file destination paths.  This should be
safe and backward-compatible given that the destination files (or their
contents) will be fully replaced anyway.

Example case:

irb(main):001:0> FileUtils.touch('foo')
=> ["foo"]
irb(main):002:0> FileUtils.touch('bar')
=> ["bar"]
irb(main):003:0> FileUtils.chmod(0o444, 'bar')
=> ["bar"]
irb(main):004:0> FileUtils.cp_r('foo', 'bar')
Errno::EACCES: Permission denied @ rb_sysopen - bar
from /nix/store/2kw126cy93rix4pmh9lcl120njnb6r7r-ruby-3.1.4/lib/ruby/3.1.0/fileutils.rb:1395:in `initialize'
irb(main):005:0> FileUtils.cp_r('foo', 'bar', remove_destination: true)
=> nil

Addresses simplecov-ruby/simplecov#741.
@tomeon
Copy link
Contributor Author

tomeon commented Apr 18, 2024

Note that this should solve #133.

@amatsuda amatsuda merged commit a10a3a9 into simplecov-ruby:main Sep 1, 2024
8 checks passed
@amatsuda
Copy link
Member

amatsuda commented Sep 1, 2024

While I haven't hit such a situation in my life, your description was understandable, and your patch seems simple and reasonable. Thank you @tomeon!

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

Successfully merging this pull request may close these issues.

2 participants