Project

General

Profile

Bug #7824 ยป rmdir_parents.patch

iosctr (Brian Burns), 02/11/2013 04:50 AM

View differences:

lib/fileutils.rb
public
#
# Options: noop, verbose
# Options: noop, verbose, parents
#
# Removes one or more directories.
#
......
Dir.rmdir(dir = dir.chomp(?/))
if parents
until (parent = File.dirname(dir)) == '.' or parent == dir
Dir.rmdir(dir)
Dir.rmdir(dir = parent)
end
end
rescue Errno::ENOTEMPTY, Errno::ENOENT
test/fileutils/test_fileutils.rb
def test_rmdir
check_singleton :rmdir
Dir.mkdir 'tmp/a'
Dir.mkdir 'tmp/a/b'
rmdir 'tmp/a/b'
assert_file_not_exist 'tmp/a/b'
assert_file_exist 'tmp/a'
Dir.mkdir 'tmp/a/b'
touch 'tmp/a/b/file'
assert_nothing_raised {
rmdir 'tmp/a/b'
}
assert_file_exist 'tmp/a/b'
end
def test_rmdir_parents
check_singleton :rmdir
Dir.mkdir 'tmp/a'
Dir.mkdir 'tmp/a/b'
Dir.chdir('tmp') {
rmdir 'a/b', parents: true
}
assert_file_not_exist 'tmp/a/b'
assert_file_not_exist 'tmp/a'
assert_file_exist 'tmp'
Dir.mkdir 'tmp/a'
touch 'tmp/a/file'
Dir.mkdir 'tmp/a/b'
assert_nothing_raised {
Dir.chdir('tmp') {
rmdir 'a/b', parents: true
}
}
assert_file_not_exist 'tmp/a/b'
assert_file_exist 'tmp/a'
end
def test_rmtree
    (1-1/1)