ruby-changes:26963
From: mame <ko1@a...>
Date: Sat, 2 Feb 2013 12:54:11 +0900 (JST)
Subject: [ruby-changes:26963] mame:r39015 (trunk): * lib/fileutils.rb (copy_entry, wrap_traverse): preserve attributes of
mame 2013-02-02 12:54:00 +0900 (Sat, 02 Feb 2013) New Revision: 39015 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39015 Log: * 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. Modified files: trunk/ChangeLog trunk/lib/fileutils.rb trunk/test/fileutils/test_fileutils.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 39014) +++ ChangeLog (revision 39015) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Feb 2 12:36:54 2013 Yusuke Endoh <mame@t...> + + * 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. + Sat Feb 2 12:30:00 2013 Zachary Scott <zachary@z...> * lib/uri/ftp.rb (URI::FTP.new2): nodoc method from r39013 [Bug #7301] Index: lib/fileutils.rb =================================================================== --- lib/fileutils.rb (revision 39014) +++ lib/fileutils.rb (revision 39015) @@ -526,12 +526,14 @@ public https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L526 # 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 https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L1542 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 Index: test/fileutils/test_fileutils.rb =================================================================== --- test/fileutils/test_fileutils.rb (revision 39014) +++ test/fileutils/test_fileutils.rb (revision 39015) @@ -239,6 +239,22 @@ class TestFileUtils https://github.com/ruby/ruby/blob/trunk/test/fileutils/test_fileutils.rb#L239 bug4507) end + def test_cp_preserve_permissions_dir + bug7246 = '[ruby-core:48603]' + mkdir 'tmp/cptmp' + mkdir 'tmp/cptmp/d1' + chmod 0745, 'tmp/cptmp/d1' + mkdir 'tmp/cptmp/d2' + chmod 0700, 'tmp/cptmp/d2' + cp_r 'tmp/cptmp', 'tmp/cptmp2', :preserve => true + assert_equal(File.stat('tmp/cptmp/d1').mode, + File.stat('tmp/cptmp2/d1').mode, + bug7246) + assert_equal(File.stat('tmp/cptmp/d2').mode, + File.stat('tmp/cptmp2/d2').mode, + bug7246) + end + def test_cp_symlink touch 'tmp/cptmp' # src==dest (2) symlink and its target -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/