os: fix rmdir_all panic with hidden dirs (#9271)

pull/9285/head
Lukas Neubert 2021-03-13 07:43:38 +01:00 committed by GitHub
parent e09a8a47b0
commit fecf4a6f58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -142,8 +142,9 @@ pub fn rmdir_all(path string) ? {
fullpath := join_path(path, item)
if is_dir(fullpath) {
rmdir_all(fullpath) or { ret_err = err.msg }
} else {
rm(fullpath) or { ret_err = err.msg }
}
rm(fullpath) or { ret_err = err.msg }
}
rmdir(path) or { ret_err = err.msg }
if ret_err.len > 0 {

View File

@ -399,6 +399,21 @@ fn test_join() {
}
}
fn test_rmdir_all() {
mut dirs := ['some/dir', 'some/.hidden/directory']
$if windows {
for mut d in dirs {
d = d.replace('/', '\\')
}
}
for d in dirs {
os.mkdir_all(d) or { panic(err) }
assert os.is_dir(d)
}
os.rmdir_all('some') or { assert false }
assert !os.exists('some')
}
fn test_dir() {
$if windows {
assert os.dir('C:\\a\\b\\c') == 'C:\\a\\b'