Project

General

Profile

Bug #3178 ยป catch_not_deleted_dirs_fileutils_rmdir.patch

vajrasky (Vajrasky Kok), 01/03/2014 05:50 PM

View differences:

lib/fileutils.rb (working copy)
268 268
    parents = options[:parents]
269 269
    fu_output_message "rmdir #{parents ? '-p ' : ''}#{list.join ' '}" if options[:verbose]
270 270
    return if options[:noop]
271
    not_deleted_dirs = {}
271 272
    list.each do |dir|
272 273
      begin
273 274
        Dir.rmdir(dir = remove_tailing_slash(dir))
......
277 278
            Dir.rmdir(dir)
278 279
          end
279 280
        end
280
      rescue Errno::ENOTEMPTY, Errno::ENOENT
281
      rescue Errno::ENOTEMPTY, Errno::ENOENT => errno
282
        not_deleted_dirs[dir] = errno
281 283
      end
282 284
    end
285
    not_deleted_dirs
283 286
  end
284 287
  module_function :rmdir
285 288

  
test/fileutils/test_fileutils.rb (working copy)
1375 1375
    end
1376 1376

  
1377 1377
    subdir = 'data/sub/dir'
1378
    mkdir_p(subdir)
1379
    assert_nothing_raised(Errno::ENOENT) {
1380
      rmdir(subdir, parents: true)
1381
    }
1378
    dir = 'dir1'
1379
    not_exist_dir = 'doesnotexist'
1380
    mkdir_p subdir
1381
    mkdir_p dir
1382
    not_deleted_dirs = rmdir([subdir, dir, not_exist_dir], parents: true)
1382 1383
    assert_file_not_exist(subdir)
1383 1384
    assert_file_not_exist('data/sub')
1384 1385
    assert_directory('data')
1386
    assert(not_deleted_dirs['data'].message =~ /Directory not empty/)
1387
    assert_equal(not_deleted_dirs['data'].class, Errno::ENOTEMPTY)
1388
    assert(not_deleted_dirs[not_exist_dir].message =~ /No such file or directory/)
1389
    assert_equal(not_deleted_dirs[not_exist_dir].class, Errno::ENOENT)
1390
    assert_equal(not_deleted_dirs.length, 2)
1385 1391
  end
1386 1392

  
1387 1393
  def test_rmtree