Commit graph

167 commits

Author SHA1 Message Date
Nobuyoshi Nakada
5a8e87cb2e [ruby/fileutils] Just the parent path of the destination symlink should exist
71225b1b46
2025-07-19 14:09:50 +00:00
Erik Berlin
4431ca5363 [ruby/fileutils] FileUtils.remove_dir checks directory
f0d7fc817b
2025-07-19 13:54:45 +00:00
Nobuyoshi Nakada
3dced7955c [ruby/fileutils] Use shorter symlink by real paths
277f7f2ff8
2025-07-19 13:47:48 +00:00
Nobuyoshi Nakada
de68f22042 [ruby/fileutils] Fix up FileUtils#ln_sr
2836a164ed
2025-07-19 13:47:47 +00:00
Nobuyoshi Nakada
cfe8263f41 [ruby/fileutils] Fix ln_sf with multiple sources and target_directory: false
In this case, an ArgumentError is now raised rather than ignoring the
option, just as GNU coreutils' `ln` would error on the command line.
Fixes https://github.com/ruby/fileutils/pull/128 as well.

4fc578a75f
2025-07-18 09:22:34 +00:00
Hiroshi SHIBATA
6bd5a51ab5 Removed Solaris conditions from test files
We no longer execute those files with Solaris platforms.
2025-04-02 16:24:47 +09:00
KJ Tsanaktsidis
8800127d80 Skip some tests which don't work under permissionless containers
When running as UID 0 but without CAP_DAC_OVERRIDE (for example, in a
docker container running with --uid 0 but --cap-drop=all), these tests
won't work because of hard-coded assumptions about what uid 0 can and
can't do.
2024-08-23 09:34:41 +10:00
Satadru Pramanik, DO, MPH, MEng
94aed6ece5 [ruby/fileutils] Add mkdir_p to FileUtils.install
(https://github.com/ruby/fileutils/pull/104)

* Add mkdir_p to FileUtils.install

* Adjust raise message.

* adjust raise language

* handle trailing slash in dest

* simplify

* Add tests
2023-02-10 03:37:39 +00:00
Nobuyoshi Nakada
c6330cd32b [ruby/fileutils] [Feature #18925] Add ln_sr method and relative: option to ln_s
5116088d5c
2022-11-25 01:03:57 +00:00
Samuel Williams
ea8a7287e2
Add support for sockaddr_un on Windows. (#6513)
* Windows: Fix warning about undefined if_indextoname()

* Windows: Fix UNIXSocket on MINGW and make .pair more reliable

* Windows: Use nonblock=true for read tests with scheduler

* Windows: Move socket detection from File.socket? to File.stat

Add S_IFSOCK to Windows and interpret reparse points accordingly.
Enable tests that work now.

* Windows: Use wide-char functions to UNIXSocket

This fixes behaviour with non-ASCII characters.
It also fixes deletion of temporary UNIXSocket.pair files.

* Windows: Add UNIXSocket tests for specifics of Windows impl.

* Windows: fix VC build due to missing _snwprintf

Avoid usage of _snwprintf, since it fails linking ruby.dll like so:

  linking shared-library x64-vcruntime140-ruby320.dll
  x64-vcruntime140-ruby320.def : error LNK2001: unresolved external symbol snwprintf
  x64-vcruntime140-ruby320.def : error LNK2001: unresolved external symbol vsnwprintf_l

whereas linking miniruby.exe succeeds.

This patch uses snprintf on the UTF-8 string instead.

Also remove branch GetWindowsDirectoryW, since it doesn't work.

* Windows: Fix dangling symlink test failures

Co-authored-by: Lars Kanis <kanis@comcard.de>
2022-11-17 14:50:25 -08:00
Yusuke Endoh
72c7dba436 [ruby/fileutils] Revert "FileUtils.rm* methods swallows only Errno::ENOENT when force is true"
This reverts commit fa65d676ec.

This caused some incompatibility problems in real-world cases.
https://bugs.ruby-lang.org/issues/18784#change-98927
https://bugs.ruby-lang.org/issues/18784#change-98967

42983c2553
2022-11-07 11:25:25 +00:00
Yusuke Endoh
983115cf3c [ruby/fileutils] FileUtils.rm* methods swallows only Errno::ENOENT when force is true
... instead of any StandardError.

To behave like the standard `rm` command, it should only ignore
exceptions about not existing files, not every exception. This should
make debugging some errors easier, because the expectation is that `rm
-rf` will succeed if and only if, all given files (previously existent
or not) are removed. However, due to this exception swallowing, this is
not always the case.

From the `rm` man page

> COMPATIBILITY
>
> The rm utility differs from historical implementations in that the -f
> option only masks attempts to remove non-existent files instead of
> masking a large variety of errors.

fa65d676ec

Co-Authored-By: David Rodríguez <deivid.rodriguez@riseup.net>
2022-08-23 16:52:41 +09:00
Yusuke Endoh
96562a517d [ruby/fileutils] Narrow the scope of ensure
The ensure in postorder_traverse was added for [Bug #6756].
The intention was to try to delete the parent directory if it failed to
get the children. (It may be possible to delete the directory if it is
empty.)

However, the ensure region rescue'ed not only "failure to get children"
but also "failure to delete each child". Thus, the following raised
Errno::ENOTEMPTY, but we expect it to raise Errno::EACCES.

```
$ mkdir foo
$ touch foo/bar
$ chmod 555 foo
$ ruby -rfileutils -e 'FileUtils.rm_rf("foo")'
```

This changeset narrows the ensure region so that it rescues only
"failure to get children".

ec5d3b84ea
2022-08-23 16:52:40 +09:00
Yusuke Endoh
073f3b7e0a [ruby/fileutils] Fix the test permission of "test_rm_rf"
The test was added for [Bug #6756]. The ticket insisted
`FileUtils.rm_rf` should delete an empty directory even if its
permission is 000. However, the test tried to delete a directory with
permission 700.

d6c2ab2c01
2022-08-23 16:52:39 +09:00
David Rodríguez
70f69f8539 [ruby/fileutils] Fix mkdir_p hanging on Windows when trying to create a file on a offline drive
9cc6a082d7
2022-08-22 10:12:25 +09:00
Nobuyoshi Nakada
ee1d2b276a [ruby/fileutils] Add an octal prefix to clarify to be octal
332025bc02

Co-Authored-By: David Rodríguez <deivid.rodriguez@riseup.net>
2022-07-19 17:33:44 +09:00
Hiroshi SHIBATA
940a19e4b3
Use Test::Unit::AssertionFailedError instead of MiniTest::Assertion for test-unit migration 2021-09-06 18:34:15 +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
Yusuke Endoh
2fd71112fb Make the test suite pass on real Android/Termux environment
Attempting to create a hard link raises EACCES
2020-10-12 21:26:05 +09:00
Kazuhiro NISHIYAMA
6adbdb56ed
Fix Encoding::CompatibilityError in FileUtils::Entry_#join 2020-06-22 18:34:24 +09:00
Kazuhiro NISHIYAMA
3a1e63e540
Fix typos 2020-06-22 18:23:58 +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
Kazuhiro NISHIYAMA
48d7ebe6fc
Check symlink in tmpdir and do not use empty path 2020-06-22 17:11:23 +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.

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

563a383025
2020-06-12 18:38:47 +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.

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
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
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.

2ea54ade2f
2019-11-30 17:31:35 +09:00
Nobuyoshi Nakada
aab74fc938 [ruby/fileutils] Added test_install_mode_option
bb10efe104
2019-11-30 17:31:05 +09:00
Hiroshi SHIBATA
ad67adb5f9
[ruby/fileutils] Use pend instead of skip
ba2c24e2d7
2019-10-03 18:32:29 +09:00
Jeremy Evans
9792c9d183
[ruby/fileutils] Fix test_cp_r_dev on Windows or other systems without character/block device in /dev
Previously this would give an error such as:

TestFileUtils#test_cp_r_dev [c:/fileutils/test/fileutils/test_fileutils.rb:455]:
[RuntimeError] exception expected, not.
Class: <TypeError>
Message: <"no implicit conversion of nil into String">

0ce0fefbeb
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.

689cb9c56a
2019-09-27 11:39:02 +09:00
Jeremy Evans
02cd420505
[ruby/fileutils] Skip test_cp_r_socket on JRuby
20bb9ec789
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.

123903532d
2019-09-27 11:39:02 +09:00
Justin Collins
4f1a00a746
Improve same directory detection in FileUtils
Closes: https://github.com/ruby/ruby/pull/1425
2019-08-06 09:01:04 +09:00
mame
6a860ea006 Guard out the test when it is run under root permission
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67247 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-14 01:04:53 +00:00
nobu
af83a85f75 Run r66972 assertion only when a sticky-bit makes sense
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66973 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-01 01:31:34 +00:00
nobu
cb5a329814 Fix exception namespace
* lib/fileutils.rb (remove_entry_secure): EISDIR is under the
  Errno namespace.  [ruby-core:91362] [Bug #15577]

From: Tietew (Toru Iwase) <tietew@tietew.net>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66972 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-31 14:02:30 +00:00
hsbt
60fbe01353 Retry to merge fileutils-1.1.0.
* Revert "Revert "Merge fileutils-1.1.0.""
    This reverts commit 84bb8e81c2.

  * Added workaround for make mjit-headers

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-15 05:53:18 +00:00
mame
84bb8e81c2 Revert "Merge fileutils-1.1.0."
This reverts commit 99da3d2570e110d3024039102205f6d64174bf5e.
The change caused the following build failure:

```
.../ruby/lib/fileutils.rb:88:in `require': cannot load such file -- rbconfig (LoadError)
uncommon.mk:987: recipe for target 'encdb.h' failed
make: *** [encdb.h] Error 1
```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63428 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-15 04:16:08 +00:00
hsbt
6f9609867c Merge fileutils-1.1.0.
This version was migrated JRuby paches.
  https://github.com/ruby/fileutils/pull/18

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-15 01:22:36 +00:00
mame
d583ee266b 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
2018-03-13 08:18:03 +00:00
eregon
15689ed778 Fix test-all tests to avoid creating report_on_exception warnings
* The warnings are shown by Thread.report_on_exception defaulting to
  true. [Feature #14143] [ruby-core:83979]
* Improves tests by narrowing down the scope where an exception
  is expected.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12 18:44:49 +00:00
ko1
4c6eb271dd fix r60281
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60287 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 14:35:19 +00:00
kosaki
3666ceb729 test_cp_preserve_permissions should care about umask
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60281 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 14:21:56 +00:00
usa
2caaae0707 File.symlink is not potable
* test/fileutils/test_fileutils.rb: skip tests using File.symlink if it's not
  available.  this problem is reported by ko1.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 07:44:11 +00:00
hsbt
0242f7ccae Overwrite destination symlink file if remove_destination is set.
[Bug #13914][ruby-core:82846] Patch by @mzp
  https://github.com/ruby/fileutils/pull/9

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-20 07:03:11 +00:00
nobu
1241d59cef test_fileutils.rb: rmdir should fail on nonexistent directory
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59935 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-16 22:40:09 +00:00