diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-13 08:18:03 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-13 08:18:03 +0000 |
commit | d583ee266bf189a8d41ee3a3469ab0334c8643fa (patch) | |
tree | 12db0b931e3890a7dbac647c5b9e8a3d5c3ffae3 /test/fileutils | |
parent | dd3851d2786412de019350a11e749c56fa5a07cc (diff) |
Add FileUtils#cp_lr
* lib/fileutils.rb: Add FileUtils#cp_lr. This method creates hard links
of each file from directory to another directory recursively.
This patch is based on Thomas Sawyers and Zachary Scott.
[Feature #4189] [ruby-core:33820]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62739 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/fileutils')
-rw-r--r-- | test/fileutils/test_fileutils.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb index 584a1f517a..c531af1569 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -449,6 +449,45 @@ class TestFileUtils < Test::Unit::TestCase cp_r 'tmp/src', 'tmp/dest/', remove_destination: true end if have_symlink? + def test_cp_lr + check_singleton :cp_lr + + cp_lr 'data', 'tmp' + TARGETS.each do |fname| + assert_same_file fname, "tmp/#{fname}" + end + + # a/* -> b/* + mkdir 'tmp/cpr_src' + mkdir 'tmp/cpr_dest' + File.open('tmp/cpr_src/a', 'w') {|f| f.puts 'a' } + File.open('tmp/cpr_src/b', 'w') {|f| f.puts 'b' } + File.open('tmp/cpr_src/c', 'w') {|f| f.puts 'c' } + mkdir 'tmp/cpr_src/d' + cp_lr 'tmp/cpr_src/.', 'tmp/cpr_dest' + assert_same_file 'tmp/cpr_src/a', 'tmp/cpr_dest/a' + assert_same_file 'tmp/cpr_src/b', 'tmp/cpr_dest/b' + assert_same_file 'tmp/cpr_src/c', 'tmp/cpr_dest/c' + assert_directory 'tmp/cpr_dest/d' + my_rm_rf 'tmp/cpr_src' + my_rm_rf 'tmp/cpr_dest' + + bug3588 = '[ruby-core:31360]' + mkdir 'tmp2' + assert_nothing_raised(ArgumentError, bug3588) do + cp_lr 'tmp', 'tmp2' + end + assert_directory 'tmp2/tmp' + assert_raise(ArgumentError, bug3588) do + cp_lr 'tmp2', 'tmp2/new_tmp2' + end + + bug12892 = '[ruby-core:77885] [Bug #12892]' + assert_raise(Errno::ENOENT, bug12892) do + cp_lr 'non/existent', 'tmp' + end + end if have_hardlink? + def test_mv check_singleton :mv |