diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-07-09 20:41:51 -0700 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-09-27 11:39:02 +0900 |
commit | 1d99163aa59b637f1c14287135f26480df447e49 (patch) | |
tree | 55886c24c8b60761b33d9aceed24d6b81f406cb8 /test/fileutils | |
parent | 366dd9d80308e6526502ef636b63893b3fb41af2 (diff) |
[ruby/fileutils] Make copy methods handle FIFOs and UNIX sockets
Previously, this was broken. Trying to copy a FIFO would raise a
NoMethodError if File.mkfifo was defined. Trying to copy a UNIX
socket would raise a RuntimeError as File.mknod is not something
Ruby defines.
Handle the FIFO issue using File.mkfifo instead of mkfifo.
Handle the UNIX Socket issue by creating a unix socket.
Continue to not support character or block devices, raising a
RuntimeError for both.
Add tests for FIFO, UNIX Socket, and character/block devices.
https://github.com/ruby/fileutils/commit/123903532d
Diffstat (limited to 'test/fileutils')
-rw-r--r-- | test/fileutils/test_fileutils.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb index 18a4bed39e..663c81ed6d 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -440,6 +440,34 @@ class TestFileUtils < Test::Unit::TestCase } end if have_symlink? and !no_broken_symlink? + def test_cp_r_fifo + Dir.mkdir('tmp/cpr_src') + File.mkfifo 'tmp/cpr_src/fifo', 0600 + cp_r 'tmp/cpr_src', 'tmp/cpr_dest' + assert_equal(true, File.pipe?('tmp/cpr_dest/fifo')) + end if File.respond_to?(:mkfifo) + + def test_cp_r_dev + devs = Dir['/dev/*'] + chardev = Dir['/dev/*'].find{|f| File.chardev?(f)} + blockdev = Dir['/dev/*'].find{|f| File.blockdev?(f)} + Dir.mkdir('tmp/cpr_dest') + assert_raise(RuntimeError) { cp_r chardev, 'tmp/cpr_dest/cd' } + assert_raise(RuntimeError) { cp_r blockdev, 'tmp/cpr_dest/bd' } + end + + begin + require 'socket' + rescue LoadError + else + def test_cp_r_socket + Dir.mkdir('tmp/cpr_src') + UNIXServer.new('tmp/cpr_src/socket').close + cp_r 'tmp/cpr_src', 'tmp/cpr_dest' + assert_equal(true, File.socket?('tmp/cpr_dest/socket')) + end if defined?(UNIXServer) + end + def test_cp_r_pathname # pathname touch 'tmp/cprtmp' |