Project

General

Profile

Actions

Backport #3588

closed

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

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

Status:
Closed
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

Actions #1

Updated by latasoy (Levent Atasoy) over 13 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

Actions #2

Updated by nobu (Nobuyoshi Nakada) over 13 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

Actions

Also available in: Atom PDF

Like0
Like0Like0