ruby-changes:47816
From: nobu <ko1@a...>
Date: Sat, 16 Sep 2017 20:59:52 +0900 (JST)
Subject: [ruby-changes:47816] nobu:r59934 (trunk): fileutils.rb: error at rmdir
nobu 2017-09-16 20:59:47 +0900 (Sat, 16 Sep 2017) New Revision: 59934 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59934 Log: fileutils.rb: error at rmdir * lib/fileutils.rb (rmdir): should not ignore errors first, except for parent directories. [ruby-dev:50236] [Bug #13889] Modified files: trunk/lib/fileutils.rb trunk/test/fileutils/test_fileutils.rb Index: lib/fileutils.rb =================================================================== --- lib/fileutils.rb (revision 59933) +++ lib/fileutils.rb (revision 59934) @@ -245,15 +245,15 @@ module FileUtils https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L245 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 Index: test/fileutils/test_fileutils.rb =================================================================== --- test/fileutils/test_fileutils.rb (revision 59933) +++ test/fileutils/test_fileutils.rb (revision 59934) @@ -1612,6 +1612,15 @@ class TestFileUtils < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/fileutils/test_fileutils.rb#L1612 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) } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/