Skip to content

Commit 7359cef

Browse files
committed
Fix cp_r with symlink root on Windows
Previously this would copy the symlink root as a symlink instead of creating a new root directory. This modifies the source to expand it using File.realpath before starting the copy. Fixes Ruby Bug 12123
1 parent 0ce0fef commit 7359cef

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/fileutils.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,11 @@ def cp_r(src, dest, preserve: nil, noop: nil, verbose: nil,
488488
# If +remove_destination+ is true, this method removes each destination file before copy.
489489
#
490490
def copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
491-
Entry_.new(src, nil, dereference_root).wrap_traverse(proc do |ent|
491+
if dereference_root
492+
src = File.realpath(src)
493+
end
494+
495+
Entry_.new(src, nil, false).wrap_traverse(proc do |ent|
492496
destent = Entry_.new(dest, ent.rel, false)
493497
File.unlink destent.path if remove_destination && (File.file?(destent.path) || File.symlink?(destent.path))
494498
ent.copy destent.path

0 commit comments

Comments
 (0)