summaryrefslogtreecommitdiff
path: root/lib/fileutils.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-07-09 20:41:51 -0700
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2019-09-27 11:39:02 +0900
commit1d99163aa59b637f1c14287135f26480df447e49 (patch)
tree55886c24c8b60761b33d9aceed24d6b81f406cb8 /lib/fileutils.rb
parent366dd9d80308e6526502ef636b63893b3fb41af2 (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 'lib/fileutils.rb')
-rw-r--r--lib/fileutils.rb21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/fileutils.rb b/lib/fileutils.rb
index ee903e2519..bc4fd70bf2 100644
--- a/lib/fileutils.rb
+++ b/lib/fileutils.rb
@@ -1383,18 +1383,21 @@ module FileUtils
end
when symlink?
File.symlink File.readlink(path()), dest
- when chardev?
- raise "cannot handle device file" unless File.respond_to?(:mknod)
- mknod dest, ?c, 0666, lstat().rdev
- when blockdev?
- raise "cannot handle device file" unless File.respond_to?(:mknod)
- mknod dest, ?b, 0666, lstat().rdev
+ when chardev?, blockdev?
+ raise "cannot handle device file"
when socket?
- raise "cannot handle socket" unless File.respond_to?(:mknod)
- mknod dest, nil, lstat().mode, 0
+ begin
+ require 'socket'
+ rescue LoadError
+ raise "cannot handle socket"
+ else
+ raise "cannot handle socket" unless defined?(UNIXServer)
+ end
+ UNIXServer.new(dest).close
+ File.chmod lstat().mode, dest
when pipe?
raise "cannot handle FIFO" unless File.respond_to?(:mkfifo)
- mkfifo dest, 0666
+ File.mkfifo dest, lstat().mode
when door?
raise "cannot handle door: #{path()}"
else