Skip to content

Commit 3931b22

Browse files
authored
filesystem: use libuv for rmdir directly (#39013)
1 parent ee6f6f1 commit 3931b22

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

base/file.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,15 @@ function rm(path::AbstractString; force::Bool=false, recursive::Bool=false)
282282
rm(joinpath(path, p), force=force, recursive=true)
283283
end
284284
end
285-
@static if Sys.iswindows()
286-
ret = ccall(:_wrmdir, Int32, (Cwstring,), path)
287-
else
288-
ret = ccall(:rmdir, Int32, (Cstring,), path)
285+
req = Libc.malloc(_sizeof_uv_fs)
286+
try
287+
ret = ccall(:uv_fs_rmdir, Cint, (Ptr{Cvoid}, Ptr{Cvoid}, Cstring, Ptr{Cvoid}), C_NULL, req, path, C_NULL)
288+
uv_fs_req_cleanup(req)
289+
ret < 0 && uv_error("rm($(repr(path)))", ret)
290+
nothing
291+
finally
292+
Libc.free(req)
289293
end
290-
systemerror(:rmdir, ret != 0, extrainfo=path)
291294
end
292295
end
293296

test/file.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ cp(newfile, c_file)
444444

445445
@test isdir(c_subdir)
446446
@test isfile(c_file)
447-
@test_throws SystemError rm(c_tmpdir)
448-
@test_throws SystemError rm(c_tmpdir, force=true)
447+
@test_throws Base.IOError rm(c_tmpdir)
448+
@test_throws Base.IOError rm(c_tmpdir, force=true)
449449

450450
# create temp dir in specific directory
451451
d_tmpdir = mktempdir(c_tmpdir)

0 commit comments

Comments
 (0)