Bug #3588: Fileutils.cp_r issues error if destination folder name contains input folder name
http://redmine.ruby-lang.org/issues/show/3588

Author: Levent Atasoy
Status: Open, Priority: Normal
Category: lib
ruby -v: ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-mingw32]

My application copies <dir>/results to <dir>/results_archive.
This works fine in 1.8, but 1.9 prevents this legitimate usage case.

--- sample code
src ="c:/qa/tmp"
dest ="c:/qa/tmp2"
FileUtils.cp_r(src, dest)
---
Causes: C:/Ruby/lib/ruby/1.9.1/fileutils.rb:1235:in `copy': cannot copy directory c:/qa/tmp to itself c:/qa/tmp2/tmp (ArgumentError)
It works fine if I use 
dest ="c:/qa/tm2"

The offending code is in the regexp comparison, at fileutils.rb, line 1234, shown below

def copy(dest)
      case
      when file?
        copy_file dest
      when directory?
        if !File.exist?(dest) and /^#{Regexp.quote(path)}/ =~ File.dirname(dest)
          raise ArgumentError, "cannot copy directory %s to itself %s" % [path, dest]
        end
        begin


----------------------------------------
http://redmine.ruby-lang.org