Issue #13914 has been reported by mzp (Hiroki MIZUNO).

----------------------------------------
Bug #13914: FileUtis.cp_r with remove_destination cannot overwrite a symlink of directory
https://bugs.ruby-lang.org/issues/13914

* Author: mzp (Hiroki MIZUNO)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin17], ruby 2.5.0dev (2017-09-17 trunk 59946) [x86_64-darwin17]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
## Reproduce code

~~~
require 'fileutils'
# setup directory like following:
#
#   tmp
#   изибиб dest
#   ижибиб src
#       изибиб a -> dir
#           ижибиб dir
#
FileUtils.rm_rf 'tmp'
%w(tmp/src tmp/dest tmp/src/dir).each do|path|
  FileUtils.mkdir_p path
end
File.symlink 'dir', 'tmp/src/a'

# copy dual
FileUtils.cp_r 'tmp/src', 'tmp/dest/', remove_destination: true
FileUtils.cp_r 'tmp/src', 'tmp/dest/', remove_destination: true # <- Errno::EEXIST exception is raised
~~~

## Actual behavior
~~~
$ ruby bug.rb
/usr/local/Cellar/ruby/2.4.2/lib/ruby/2.4.0/fileutils.rb:1268:in `symlink': File exists @ syserr_fail2_in - tmp/dest/src/a (Errno::EEXIST)
        from /usr/local/Cellar/ruby/2.4.2/lib/ruby/2.4.0/fileutils.rb:1268:in `copy'
        from /usr/local/Cellar/ruby/2.4.2/lib/ruby/2.4.0/fileutils.rb:416:in `block in copy_entry'
        from /usr/local/Cellar/ruby/2.4.2/lib/ruby/2.4.0/fileutils.rb:1388:in `wrap_traverse'
        from /usr/local/Cellar/ruby/2.4.2/lib/ruby/2.4.0/fileutils.rb:1391:in `block in wrap_traverse'
        from /usr/local/Cellar/ruby/2.4.2/lib/ruby/2.4.0/fileutils.rb:1390:in `each'
        from /usr/local/Cellar/ruby/2.4.2/lib/ruby/2.4.0/fileutils.rb:1390:in `wrap_traverse'
        from /usr/local/Cellar/ruby/2.4.2/lib/ruby/2.4.0/fileutils.rb:413:in `copy_entry'
        from /usr/local/Cellar/ruby/2.4.2/lib/ruby/2.4.0/fileutils.rb:391:in `block in cp_r'
        from /usr/local/Cellar/ruby/2.4.2/lib/ruby/2.4.0/fileutils.rb:1461:in `block in fu_each_src_dest'
        from /usr/local/Cellar/ruby/2.4.2/lib/ruby/2.4.0/fileutils.rb:1475:in `fu_each_src_dest0'
        from /usr/local/Cellar/ruby/2.4.2/lib/ruby/2.4.0/fileutils.rb:1459:in `fu_each_src_dest'
        from /usr/local/Cellar/ruby/2.4.2/lib/ruby/2.4.0/fileutils.rb:390:in `cp_r'
        from bug.rb:18:in `<main>'
~~~

## Except behavior
This exception should not happen, and `tmp/src` is copied in a `tmp/dest`.

## Affect of this
Fastlane, major macOS/iOS /Android build tool, is affected by this problem. (https://github.com/fastlane/fastlane/issues/9537)

---Files--------------------------------
PATCH (1.72 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>