diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/fileutils.rb | 6 | ||||
-rw-r--r-- | test/fileutils/test_fileutils.rb | 5 |
3 files changed, 14 insertions, 2 deletions
@@ -1,3 +1,8 @@ +Wed Sep 9 22:02:02 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * lib/fileutils.rb (FileUtils::Entry_#copy_file): open the source + file first to ensure it can be copied. [ruby-core:25498] + Wed Sep 9 21:20:49 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> * ext/bigdecimal/bigdecimal.c (BigDecimal_data_type): typed. diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 2a6b248585..58e3f1d684 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -1261,8 +1261,10 @@ module FileUtils end def copy_file(dest) - File.open(dest, 'wb') do |f| - IO.copy_stream(path(), f) + File.open(path()) do |s| + File.open(dest, 'wb') do |f| + IO.copy_stream(s, f) + end end end diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb index 3117193385..13df0fc133 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -223,6 +223,11 @@ end assert_same_entry srcpath, destpath end + assert_raise(Errno::ENOENT) { + cp 'tmp/cptmp', 'tmp/cptmp_new' + } + assert_file_not_exist('tmp/cptmp_new') + # src==dest (1) same path touch 'tmp/cptmp' assert_raise(ArgumentError) { |