simplecov-html icon indicating copy to clipboard operation
simplecov-html copied to clipboard

Avoid "permission denied" errors copying assets

Open tomeon opened this issue 1 year ago • 1 comments

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 https://github.com/simplecov-ruby/simplecov/issues/741.

Thanks!

tomeon avatar Apr 18 '24 03:04 tomeon

Note that this should solve #133.

tomeon avatar Apr 18 '24 14:04 tomeon

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!

amatsuda avatar Sep 01 '24 21:09 amatsuda