Граф коммитов

235 Коммитов

Автор SHA1 Сообщение Дата
Burdette Lamar 788a5e14fa [ruby/fileutils] [DOC] More on cp_r (https://github.com/ruby/fileutils/pull/87)
* More on cp_r

https://github.com/ruby/fileutils/commit/82a2b62578
2022-06-15 05:42:26 +09:00
Burdette Lamar 9b9cc8ad34 [ruby/fileutils] [DOC] More on paths and lists (https://github.com/ruby/fileutils/pull/86)
* More on paths and lists

https://github.com/ruby/fileutils/commit/c3d92d34f4
2022-06-14 22:52:22 +09:00
Burdette Lamar 9a381c240c [ruby/fileutils] [DOC] Clarify path arguments (https://github.com/ruby/fileutils/pull/85)
https://github.com/ruby/fileutils/commit/5f9ef9ddc8
2022-06-14 00:39:44 +09:00
Burdette Lamar 753da6deca [ruby/fileutils] [DOC] Enhanced Rdoc (https://github.com/ruby/fileutils/pull/84)
Treats:

    ::chown_R
    ::touch
    ::commands
    ::options
    ::have_option?
    ::options_of
    ::collect_method

https://github.com/ruby/fileutils/commit/5df0324f52
2022-06-13 21:11:45 +09:00
Burdette Lamar 44b3daa0d7 [ruby/fileutils] Enhanced RDoc (https://github.com/ruby/fileutils/pull/83)
Treats ::chmod_R and ::chown.

https://github.com/ruby/fileutils/commit/df4ac84bef
2022-06-11 06:41:27 +09:00
Burdette Lamar c2468fd88b [ruby/fileutils] Enhanced RDoc (https://github.com/ruby/fileutils/pull/82)
Treats ::chmod; adds Pathname usage to ::install.

https://github.com/ruby/fileutils/commit/9db4cb129c
2022-06-10 05:03:33 +09:00
Burdette Lamar 9b7208fca1 [ruby/fileutils] [DOC] Enhanced RDoc (https://github.com/ruby/fileutils/pull/81)
https://github.com/ruby/fileutils/commit/b9d5a79e38
2022-06-09 05:38:09 +09:00
Burdette Lamar a07acbe417 [ruby/fileutils] File trees (https://github.com/ruby/fileutils/pull/80)
Adds a note about file tree examples.

https://github.com/ruby/fileutils/commit/65ac65067a
2022-06-08 21:35:00 +09:00
Burdette Lamar b737998d25 [ruby/fileutils] [DOC] Enhanced RDoc for FileUtils (https://github.com/ruby/fileutils/pull/78)
Treats:
    ::rm
    ::rm_f
    ::rm_r
    ::rm_rf
    ::remove_entry_secure

https://github.com/ruby/fileutils/commit/ce2a438d75
2022-06-07 00:37:31 +09:00
Burdette Lamar c50c9d4051 [ruby/fileutils] [DOC] Enhanced RDoc (https://github.com/ruby/fileutils/pull/77)
Treats:
    ::copy_entry
    ::copy_file
    ::copy_stream
    ::mv

https://github.com/ruby/fileutils/commit/d6d7e5330d
2022-05-31 02:30:07 +09:00
Burdette Lamar 012eb9b70d [ruby/fileutils] [DOC] Enhanced RDoc for copy_entry (https://github.com/ruby/fileutils/pull/76)
https://github.com/ruby/fileutils/commit/27a3c376c7
2022-05-26 07:08:26 +09:00
Burdette Lamar ae09fffbff [ruby/fileutils] [DOC] Enhanced RDoc for ::cp_r (https://github.com/ruby/fileutils/pull/75)
https://github.com/ruby/fileutils/commit/a4da433443
2022-05-25 00:38:14 +09:00
Burdette Lamar 9c9c217045 [ruby/fileutils] [DOC] Enhanced RDoc for ::cp (https://github.com/ruby/fileutils/pull/74)
https://github.com/ruby/fileutils/commit/956b345ceb
2022-05-24 07:57:52 +09:00
Burdette Lamar 08b2f22c27 [ruby/fileutils] Enhanced RDoc for ::ln_sf and ::link_entry (https://github.com/ruby/fileutils/pull/73)
https://github.com/ruby/fileutils/commit/ff49055f8a
2022-05-24 01:17:11 +09:00
Burdette Lamar 479884d596 [ruby/fileutils] [DOC] Enhanced RDoc for ::ln_s (https://github.com/ruby/fileutils/pull/72)
https://github.com/ruby/fileutils/commit/db612c5e22
2022-05-23 22:00:33 +09:00
Burdette Lamar aef36bb933 [ruby/fileutils] Enhanced RDoc for #cp_lr (https://github.com/ruby/fileutils/pull/71)
https://github.com/ruby/fileutils/commit/39772bccca
2022-05-21 08:55:57 +09:00
Burdette Lamar 48002ff187 [ruby/fileutils] [DOC] Enhanced RDoc for #ln (https://github.com/ruby/fileutils/pull/69)
Enhanced RDoc for #ln

https://github.com/ruby/fileutils/commit/79fc67f03f

Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2022-05-14 22:38:22 +09:00
Burdette Lamar 019169346a [ruby/fileutils] Update lib/fileutils.rb
https://github.com/ruby/fileutils/commit/4771925fee

Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2022-05-12 04:11:51 +09:00
BurdetteLamar dbca60c58d [ruby/fileutils] Enhanced RDoc for FileUtils
https://github.com/ruby/fileutils/commit/a0ea474214
2022-05-12 04:11:50 +09:00
BurdetteLamar becafe1efb [ruby/fileutils] Enhanced RDoc for FileUtils
https://github.com/ruby/fileutils/commit/c38fd02372
2022-05-11 23:00:04 +09:00
BurdetteLamar dde9db64e0 [ruby/fileutils] Enhanced RDoc for FileUtils
https://github.com/ruby/fileutils/commit/7b60f2d63b
2022-05-11 23:00:03 +09:00
Hiroshi SHIBATA 6b08aaf228 [ruby/fileutils] Bump up fileutils version to 1.6.0
https://github.com/ruby/fileutils/commit/918d19e4f2
2021-10-21 20:14:57 +09:00
David Rodríguez fa12e3e2f7 [ruby/fileutils] Remove counterproductive optimization
I think it's debatable which is the most common usage of
`FileUtils.mkdir_p`, but even assuming the most common use case is
creating a folder when it doesn't previously exist but the parent does,
this optimization doesn't seem to have a noticiable effect there while
harming other use cases.

For benchmarks, I created this script

```ruby
require "benchmark/ips"

Benchmark.ips do |x|
  x.report("old mkdir_p - exists") do
    FileUtils.mkdir_p "/tmp"
  end

  x.report("new_mkdir_p - exists") do
    FileUtils.mkdir_p_new "/tmp"
  end

  x.compare!
end

FileUtils.rm_rf "/tmp/foo"

Benchmark.ips do |x|
  x.report("old mkdir_p - doesnt exist, parent exists") do
    FileUtils.mkdir_p "/tmp/foo"
    FileUtils.rm_rf "/tmp/foo"
  end

  x.report("new_mkdir_p - doesnt exist, parent exists") do
    FileUtils.mkdir_p_new "/tmp/foo"
    FileUtils.rm_rf "/tmp/foo"
  end

  x.compare!
end

Benchmark.ips do |x|
  x.report("old mkdir_p - doesnt exist, parent either") do
    FileUtils.mkdir_p "/tmp/foo/bar"
    FileUtils.rm_rf "/tmp/foo"
  end

  x.report("new_mkdir_p - doesnt exist, parent either") do
    FileUtils.mkdir_p_new "/tmp/foo/bar"
    FileUtils.rm_rf "/tmp/foo"
  end

  x.compare!
end

Benchmark.ips do |x|
  x.report("old mkdir_p - more levels") do
    FileUtils.mkdir_p "/tmp/foo/bar/baz"
    FileUtils.rm_rf "/tmp/foo"
  end

  x.report("new_mkdir_p - more levels") do
    FileUtils.mkdir_p_new "/tmp/foo/bar/baz"
    FileUtils.rm_rf "/tmp/foo"
  end

  x.compare!
end
```

and copied the method with the "optimization" removed as
`FileUtils.mkdir_p_new`. The results are as below:

```
Warming up --------------------------------------
old mkdir_p - exists    15.914k i/100ms
new_mkdir_p - exists    46.512k i/100ms
Calculating -------------------------------------
old mkdir_p - exists    161.461k (± 3.2%) i/s -    811.614k in   5.032315s
new_mkdir_p - exists    468.192k (± 2.9%) i/s -      2.372M in   5.071225s

Comparison:
new_mkdir_p - exists:   468192.1 i/s
old mkdir_p - exists:   161461.0 i/s - 2.90x  (± 0.00) slower

Warming up --------------------------------------
old mkdir_p - doesnt exist, parent exists
                         2.142k i/100ms
new_mkdir_p - doesnt exist, parent exists
                         1.961k i/100ms
Calculating -------------------------------------
old mkdir_p - doesnt exist, parent exists
                         21.242k (± 6.7%) i/s -    107.100k in   5.069206s
new_mkdir_p - doesnt exist, parent exists
                         19.682k (± 4.2%) i/s -    100.011k in   5.091961s

Comparison:
old mkdir_p - doesnt exist, parent exists:    21241.7 i/s
new_mkdir_p - doesnt exist, parent exists:    19681.7 i/s - same-ish: difference falls within error

Warming up --------------------------------------
old mkdir_p - doesnt exist, parent either
                       945.000  i/100ms
new_mkdir_p - doesnt exist, parent either
                         1.002k i/100ms
Calculating -------------------------------------
old mkdir_p - doesnt exist, parent either
                          9.689k (± 4.4%) i/s -     49.140k in   5.084342s
new_mkdir_p - doesnt exist, parent either
                         10.806k (± 4.6%) i/s -     54.108k in   5.020714s

Comparison:
new_mkdir_p - doesnt exist, parent either:    10806.3 i/s
old mkdir_p - doesnt exist, parent either:     9689.3 i/s - 1.12x  (± 0.00) slower

Warming up --------------------------------------
old mkdir_p - more levels
                       702.000  i/100ms
new_mkdir_p - more levels
                       775.000  i/100ms
Calculating -------------------------------------
old mkdir_p - more levels
                          7.046k (± 3.5%) i/s -     35.802k in   5.087548s
new_mkdir_p - more levels
                          7.685k (± 5.5%) i/s -     38.750k in   5.061351s

Comparison:
new_mkdir_p - more levels:     7685.1 i/s
old mkdir_p - more levels:     7046.4 i/s - same-ish: difference falls within error
```

I think it's better to keep the code simpler is the optimization is not
so clear like in this case.

https://github.com/ruby/fileutils/commit/e842a0e70e
2021-10-14 09:12:16 +09:00
David Rodríguez d8d97872a1 [ruby/fileutils] Simplify loop to find out segments to be created
Doing it this way is simpler and it doesn't end up adding "/" to the
list of folders, so it doesn't need to be removed later.

https://github.com/ruby/fileutils/commit/df08e124ce
2021-10-14 09:12:15 +09:00
Nobuyoshi Nakada 562b97e2f0 [ruby/fileutils] Removed code for dead versions
https://github.com/ruby/fileutils/commit/1f707d8cc6
2021-01-17 12:20:57 +09:00
Hiroshi SHIBATA 9b9cbbbc17
Update library versions of the default gems.
They are followed up with
  8fb02b7a97
2020-12-22 21:45:28 +09:00
Hiroshi SHIBATA 349e79bae0
Try to test with rake-13.0.2 again.
[ruby/fileutils] Make verbose output go to stdout instead of stderr

  This reverts commit 510df47f5f.
2020-12-19 16:53:18 +09:00
Jeremy Evans da126250ba [ruby/fileutils] Make mkdir_p only attempt to create necessary directories
Previously, if creating the directory directly didn't work
and the directory didn't exist, mkdir_p would create all
directories from the root.  This modifies the approach to
check whether the directory exists when walking up the
directory tree from the argument, and once you have found an
intermediate directory that exists, you only need to create
directories under it.

This approach has a couple advantages:

1) It performs better when most directories in path already exist,
and that will be true for most usage of mkdir_p, as mkdir_p is
usually called with paths where the first few directories exist
and only the last directory or last few directories do not.

2) It works in file-system access limited environments such as
when unveil(2) is used on OpenBSD.  In these environments, if
/foo/bar/baz exists and is unveiled, you can do
`mkdir /foo/bar/baz/xyz` but `mkdir /foo` and `mkdir /foo/bar` raise
Errno::ENOENT.

https://github.com/ruby/fileutils/commit/ec0c229e78
2020-12-04 19:50:26 +09:00
Ashwin Maroli 3dd9e12b51 [ruby/fileutils] Reduce iteration through list for `:mkdir_p`
By calling the instruction to `list.map` within `list.each` itself.
https://github.com/ruby/fileutils/commit/e690eec937
2020-09-15 20:32:13 +09:00
Kazuhiro NISHIYAMA 6adbdb56ed
Fix Encoding::CompatibilityError in `FileUtils::Entry_#join` 2020-06-22 18:34:24 +09:00
Kazuhiro NISHIYAMA 7ac6c967e4
Revert d231b8f95b and add debug print 2020-06-22 18:18:16 +09:00
Kazuhiro NISHIYAMA d231b8f95b
Fix remove_entry error when path encoding is not compatible UTF-8 2020-06-22 17:11:24 +09:00
Nobuyoshi Nakada 510df47f5f
Revert "[ruby/fileutils] Make verbose output go to stdout instead of stderr"
This reverts commit 7cddb844e6,
because the test of rake 13.0.1 is depending on the previous
behavior.
2020-06-12 19:02:50 +09:00
Nobuyoshi Nakada cc9ca468fe [ruby/fileutils] Fix #install with "X" mode option
`FileUtils#install` methed raises an unexpected `TypeError`, when
called with `mode:` option which has `"X"`.

```
$ ruby -rfileutils -e 'FileUtils.install("tmp/a", "tmp/b", mode: "o+X")'
/opt/local/lib/ruby/2.7.0/fileutils.rb:942:in `directory?': no implicit conversion of File::Stat into String (TypeError)
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:942:in `block (3 levels) in symbolic_modes_to_i'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:933:in `each_char'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:933:in `each'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:933:in `inject'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:933:in `block (2 levels) in symbolic_modes_to_i'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:931:in `each'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:931:in `each_slice'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:931:in `block in symbolic_modes_to_i'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:926:in `each'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:926:in `inject'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:926:in `symbolic_modes_to_i'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:973:in `fu_mode'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:883:in `block in install'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:1588:in `block in fu_each_src_dest'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:1604:in `fu_each_src_dest0'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:1586:in `fu_each_src_dest'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:877:in `install'
	from -e:1:in `<main>'
```

In spite of that `symbolic_modes_to_i` considers the `File::Stat`
`path` case at the beginning, in `"X"` case, `path` is passed to
`FileTest.directory?` method which requires a `String`.  In such
case, the mode in `path` should be examined instead.

https://github.com/ruby/fileutils/commit/af675af6b2
2020-06-12 18:38:49 +09:00
Jeremy Evans 7cddb844e6 [ruby/fileutils] Make verbose output go to stdout instead of stderr
Verbose output is not error output, and should be sent to
stdout and not stderr.

Fixes Ruby bug 4436

https://github.com/ruby/fileutils/commit/563a383025
2020-06-12 18:38:47 +09:00
Kazuhiro NISHIYAMA 2dd61df69f
Revert encoding to `::Encoding::UTF_8` if `fu_windows?` 2020-06-11 17:12:11 +09:00
Kazuhiro NISHIYAMA 59646e8e29
Fix error in `remove_entry`
When `LANG=C`, dir is `UTF-8` and `base` is 'ASCII-8BIT` in `FileUtils::Entry_#join`.
So `Encoding::CompatibilityError` occurred and files are not removed.

https://rubyci.org/logs/rubyci.s3.amazonaws.com/arch/ruby-master/log/20200611T060002Z.fail.html.gz
```
  1) Error:
WEBrick::TestFileHandler#test_cjk_in_path:
Errno::ENOTEMPTY: Directory not empty @ dir_s_rmdir - /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/tmp/???20200611-1887828-3nn72a
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/fileutils.rb:1460:in `rmdir'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/fileutils.rb:1460:in `block in remove_dir1'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/fileutils.rb:1471:in `platform_support'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/fileutils.rb:1459:in `remove_dir1'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/fileutils.rb:1452:in `remove'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/fileutils.rb:780:in `block in remove_entry'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/fileutils.rb:1509:in `ensure in postorder_traverse'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/fileutils.rb:1509:in `postorder_traverse'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/fileutils.rb:778:in `remove_entry'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/lib/tmpdir.rb:97:in `mktmpdir'
    /home/chkbuild/chkbuild/tmp/build/20200611T060002Z/ruby/test/webrick/test_filehandler.rb:292:in `test_cjk_in_path'
```
2020-06-11 16:29:31 +09:00
卜部昌平 a19228f878 brace the fact that lchmod(2) can EOPNOTSUPP
Musl libc has this function as a tiny wrapper of fchmodat(3posix).  On
the other hand Linux kernel does not support changing modes of a symlink.
The operation always fails with EOPNOTSUPP.  This fchmodat behaviour is
defined in POSIX.  We have to take care of such exceptions.
2020-01-24 10:49:35 +09:00
Hiroshi SHIBATA 08c866d528 [ruby/fileutils] Bump version to 1.4.1
https://github.com/ruby/fileutils/commit/da15e3ce06
2019-11-30 18:09:41 +09:00
Hiroshi SHIBATA 32e547954f
Revert "[ruby/fileutils] Fix #install with "X" mode option"
This reverts commit eab88d20ea.

  The some CI was broken with this.
2019-11-30 17:58:39 +09:00
Hiroshi SHIBATA ea4272d02b [ruby/fileutils] Bump version to 1.4.0
https://github.com/ruby/fileutils/commit/f92145b10b
2019-11-30 17:36:13 +09:00
Nobuyoshi Nakada eab88d20ea [ruby/fileutils] Fix #install with "X" mode option
`FileUtils#install` methed raises an unexpected `TypeError`, when
called with `mode:` option which has `"X"`.

```
$ ruby -rfileutils -e 'FileUtils.install("tmp/a", "tmp/b", mode: "o+X")'
/opt/local/lib/ruby/2.7.0/fileutils.rb:942:in `directory?': no implicit conversion of File::Stat into String (TypeError)
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:942:in `block (3 levels) in symbolic_modes_to_i'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:933:in `each_char'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:933:in `each'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:933:in `inject'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:933:in `block (2 levels) in symbolic_modes_to_i'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:931:in `each'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:931:in `each_slice'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:931:in `block in symbolic_modes_to_i'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:926:in `each'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:926:in `inject'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:926:in `symbolic_modes_to_i'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:973:in `fu_mode'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:883:in `block in install'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:1588:in `block in fu_each_src_dest'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:1604:in `fu_each_src_dest0'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:1586:in `fu_each_src_dest'
	from /opt/local/lib/ruby/2.7.0/fileutils.rb:877:in `install'
	from -e:1:in `<main>'
```

In spite of that `symbolic_modes_to_i` considers the `File::Stat`
`path` case at the beginning, in `"X"` case, `path` is passed to
`FileTest.directory?` method which requires a `String`.  In such
case, the mode in `path` should be examined instead.

https://github.com/ruby/fileutils/commit/2ea54ade2f
2019-11-30 17:31:35 +09:00
Nobuyoshi Nakada 0a7d26bea1
[ruby/fileutils] Remove version.rb
Loading separate version.rb unnecessary increases every start-up
time.  In the other hand, the gemspec file is parsed only when
building the gem file.

https://github.com/ruby/fileutils/commit/8359cf7cce
2019-11-30 17:30:50 +09:00
Jeremy Evans e4cd0d7287 [ruby/fileutils] Remove use of untaint on Ruby 2.7 to avoid deprecation warnings
https://github.com/ruby/fileutils/commit/5ac9a8a1f7
2019-10-31 15:41:46 +09:00
Kazuhiro NISHIYAMA d5355123cc
[ruby/fileutils] Reduce global variables
https://github.com/ruby/fileutils/commit/ba81f024cf
2019-09-27 11:39:02 +09:00
Jeremy Evans 06c35cfa65
[ruby/fileutils] Fix cp_r with symlink root on Windows
Previously this would copy the symlink root as a symlink instead
of creating a new root directory.  This modifies the source
to expand it using File.realpath before starting the copy.

Fixes Ruby Bug 12123

https://github.com/ruby/fileutils/commit/7359cef359
2019-09-27 11:39:02 +09:00
Jeremy Evans 9494ef8b2d
[ruby/fileutils] Do not break in verbose mode if using FileUtils with a frozen object
If FileUtils is included into another object, and verbose mode is
used, a FrozenError is currently raised unless the object has the
@fileutils_output and @fileutils_label instance variables.

This fixes things so that it does not attempt to set the instance
variables, but it still uses them if they are present.

https://github.com/ruby/fileutils/commit/689cb9c56a
2019-09-27 11:39:02 +09:00
Jeremy Evans 1d99163aa5
[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
2019-09-27 11:39:02 +09:00
zverok 366dd9d803
[ruby/fileutils] Update the documentation content and formatting
https://github.com/ruby/fileutils/commit/b701353c53
2019-09-27 11:39:02 +09:00
Jeremy Evans 80b5a0ff2a
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.

This makes the following changes to : handling.

* Treats as **kw, prompting keyword argument separation warnings
  if called with a positional hash.

* Do not look for an option hash if empty keywords are provided.
  For backwards compatibility, treat an empty keyword splat as a empty
  mandatory positional hash argument, but emit a a warning, as this
  behavior will be removed in Ruby 3.  The argument number check
  needs to be moved lower so it can correctly handle an empty
  positional argument being added.

* If the last argument is nil and it is necessary to treat it as an option
  hash in order to make sure all arguments are processed, continue to
  treat the last argument as the option hash. Emit a warning in this case,
  as this behavior will be removed in Ruby 3.

* If splitting the keyword hash into two hashes, issue a warning, as we
  will not be splitting hashes in Ruby 3.

* If the keyword argument is required to fill a mandatory positional
  argument, continue to do so, but emit a warning as this behavior will
  be going away in Ruby 3.

* If keyword arguments are provided and the last argument is not a hash,
  that indicates something wrong. This can happen if a cfunc is calling
  rb_scan_args multiple times, and providing arguments that were not
  passed to it from Ruby.  Callers need to switch to the new
  rb_scan_args_kw function, which allows passing of whether keywords
  were provided.

This commit fixes all warnings caused by the changes above.

It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used.  If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.

In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby.  The last argument may or may not be a hash,
so we can't set keyword argument mode.  However, if it is a
hash, we don't want to warn when treating it as keywords.

In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args.  Also, make
sure not to pass nil in place of an option hash.

Work around Kernel#warn warnings due to problems in the Rubygems
override of the method.  There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.

Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 11:18:49 -07:00