mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	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:
		
							parent
							
								
									40d117ae88
								
							
						
					
					
						commit
						2635984cf2
					
				
					 2 changed files with 13 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -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)
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue