зеркало из https://github.com/github/ruby.git
fileutils.rb: error at rmdir
* lib/fileutils.rb (rmdir): should not ignore errors first, except for parent directories. [ruby-dev:50236] [Bug #13889] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59934 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
40d117ae88
Коммит
2635984cf2
|
@ -245,15 +245,15 @@ module FileUtils
|
|||
fu_output_message "rmdir #{parents ? '-p ' : ''}#{list.join ' '}" if verbose
|
||||
return if noop
|
||||
list.each do |dir|
|
||||
begin
|
||||
Dir.rmdir(dir = remove_trailing_slash(dir))
|
||||
if parents
|
||||
Dir.rmdir(dir = remove_trailing_slash(dir))
|
||||
if parents
|
||||
begin
|
||||
until (parent = File.dirname(dir)) == '.' or parent == dir
|
||||
dir = parent
|
||||
Dir.rmdir(dir)
|
||||
end
|
||||
rescue Errno::ENOTEMPTY, Errno::EEXIST, Errno::ENOENT
|
||||
end
|
||||
rescue Errno::ENOTEMPTY, Errno::EEXIST, Errno::ENOENT
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1612,6 +1612,15 @@ class TestFileUtils < Test::Unit::TestCase
|
|||
|
||||
subdir = 'data/sub/dir'
|
||||
mkdir_p(subdir)
|
||||
File.write("#{subdir}/file", '')
|
||||
msg = "should fail to remove non-empty directory"
|
||||
assert_raise(Errno::ENOTEMPTY, Errno::EEXIST, msg) {
|
||||
rmdir(subdir)
|
||||
}
|
||||
assert_raise(Errno::ENOTEMPTY, Errno::EEXIST, msg) {
|
||||
rmdir(subdir, parents: true)
|
||||
}
|
||||
File.unlink("#{subdir}/file")
|
||||
assert_nothing_raised(Errno::ENOENT) {
|
||||
rmdir(subdir, parents: true)
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче