From 7dc77be29960a965363a55d33feb537bf55aee7e Mon Sep 17 00:00:00 2001 From: mame Date: Sat, 2 Feb 2013 03:54:00 +0000 Subject: * lib/fileutils.rb (copy_entry, wrap_traverse): preserve attributes of directories on FileUtils.cp_r. The fix was proposed by Jan Wedekind. [Bug #7246] * test/fileutils/test_fileutils.rb: add a test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/fileutils.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'lib/fileutils.rb') diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 57ab0cf77a..7bc852ea91 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -526,12 +526,14 @@ public # If +remove_destination+ is true, this method removes each destination file before copy. # def copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false) - Entry_.new(src, nil, dereference_root).traverse do |ent| + Entry_.new(src, nil, dereference_root).wrap_traverse(proc do |ent| destent = Entry_.new(dest, ent.rel, false) File.unlink destent.path if remove_destination && File.file?(destent.path) ent.copy destent.path + end, proc do |ent| + destent = Entry_.new(dest, ent.rel, false) ent.copy_metadata destent.path if preserve - end + end) end define_command(:copy_entry) @@ -1540,6 +1542,16 @@ private yield self end + def wrap_traverse(pre, post) + pre.call self + if directory? + entries.each do |ent| + ent.wrap_traverse pre, post + end + end + post.call self + end + private $fileutils_rb_have_lchmod = nil -- cgit v1.2.3