Skip to content

Commit 4431ca5

Browse files
sferikmatzbot
authored andcommitted
[ruby/fileutils] FileUtils.remove_dir checks directory
ruby/fileutils@f0d7fc817b
1 parent 3dced79 commit 4431ca5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/fileutils.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,8 @@ def remove_file(path, force = false)
14871487
# Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
14881488
#
14891489
def remove_dir(path, force = false)
1490-
remove_entry path, force # FIXME?? check if it is a directory
1490+
raise Errno::ENOTDIR, path unless File.directory?(path)
1491+
remove_entry path, force
14911492
end
14921493
module_function :remove_dir
14931494

test/fileutils/test_fileutils.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,14 @@ def test_remove_dir_file_perm
18121812
assert_file_not_exist 'data/tmpdir'
18131813
end if have_file_perm?
18141814

1815+
def test_remove_dir_with_file
1816+
File.write('data/tmpfile', 'dummy')
1817+
assert_raise(Errno::ENOTDIR) { remove_dir 'data/tmpfile' }
1818+
assert_file_exist 'data/tmpfile'
1819+
ensure
1820+
File.unlink('data/tmpfile') if File.exist?('data/tmpfile')
1821+
end
1822+
18151823
def test_compare_file
18161824
check_singleton :compare_file
18171825
# FIXME

0 commit comments

Comments
 (0)