diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-02-02 03:54:00 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-02-02 03:54:00 +0000 |
commit | 7dc77be29960a965363a55d33feb537bf55aee7e (patch) | |
tree | cfd40b4516cfbcfdda2e3f207b000d56da07ad44 /lib | |
parent | 87d3c2d6d47e36223d7a6cccf1991b72dc307865 (diff) | |
download | ruby-7dc77be29960a965363a55d33feb537bf55aee7e.tar.gz |
* 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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fileutils.rb | 16 |
1 files changed, 14 insertions, 2 deletions
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 |