Project

General

Profile

Backport #3588

Fileutils.cp_r issues error if destination folder name contains input folder name

Added by latasoy (Levent Atasoy) over 8 years ago. Updated almost 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
[ruby-core:31360]

Description

=begin
My application copies /results to /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
=end

History

#1

Updated by latasoy (Levent Atasoy) over 8 years ago

=begin
The following change seems to fix the case I need, and still preventing recursive copying:
if !File.exist?(dest) and /#{Regexp.quote(path)}\// =~ File.dirname(dest)+'/'
=end

#2

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Category set to lib
  • Status changed from Open to Closed

=begin
This issue was solved with changeset r28685.
Levent, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
=end

Also available in: Atom PDF