From c7837ed8d3ec3a74382927df7c2fae19862b78ea Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 17 Mar 2011 23:48:13 +0000 Subject: [PATCH] * lib/fileutils.rb (FileUtils::Entry_#copy_file): updated FileUtils.cp to still copy file permissions when :preserve is false (as cp does this even when -p isn't set). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31123 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ lib/fileutils.rb | 2 +- test/fileutils/test_fileutils.rb | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index add0d6960a..0ceff5df6f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Mar 18 08:48:06 2011 Oleg Shaldybin + + * lib/fileutils.rb (FileUtils::Entry_#copy_file): updated FileUtils.cp + to still copy file permissions when :preserve is false (as cp does + this even when -p isn't set). + Fri Mar 18 00:59:38 2011 Nobuyoshi Nakada * ext/win32ole/extconf.rb (create_docfile): removed. should not diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 9cd1a7cc76..f2a61970b4 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -1276,7 +1276,7 @@ module FileUtils def copy_file(dest) File.open(path()) do |s| - File.open(dest, 'wb') do |f| + File.open(dest, 'wb', s.stat.mode) do |f| IO.copy_stream(s, f) end end diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb index 3ec8dce2d5..290ba21f0d 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -230,6 +230,16 @@ class TestFileUtils } end + def test_cp_preserve_permissions + bug4507 = '[ruby-core:35518]' + touch 'tmp/cptmp' + chmod 0755, 'tmp/cptmp' + cp 'tmp/cptmp', 'tmp/cptmp2' + assert_equal(File.stat('tmp/cptmp').mode, + File.stat('tmp/cptmp2').mode, + bug4507) + end + def test_cp_symlink touch 'tmp/cptmp' # src==dest (2) symlink and its target