Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filesystem: use libuv for rmdir directly #39013

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,15 @@ function rm(path::AbstractString; force::Bool=false, recursive::Bool=false)
rm(joinpath(path, p), force=force, recursive=true)
end
end
@static if Sys.iswindows()
ret = ccall(:_wrmdir, Int32, (Cwstring,), path)
else
ret = ccall(:rmdir, Int32, (Cstring,), path)
req = Libc.malloc(_sizeof_uv_fs)
try
ret = ccall(:uv_fs_rmdir, Cint, (Ptr{Cvoid}, Ptr{Cvoid}, Cstring, Ptr{Cvoid}), C_NULL, req, path, C_NULL)
uv_fs_req_cleanup(req)
ret < 0 && uv_error("rm($(repr(path)))", ret)
nothing
finally
Libc.free(req)
end
systemerror(:rmdir, ret != 0, extrainfo=path)
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ cp(newfile, c_file)

@test isdir(c_subdir)
@test isfile(c_file)
@test_throws SystemError rm(c_tmpdir)
@test_throws SystemError rm(c_tmpdir, force=true)
@test_throws Base.IOError rm(c_tmpdir)
@test_throws Base.IOError rm(c_tmpdir, force=true)

# create temp dir in specific directory
d_tmpdir = mktempdir(c_tmpdir)
Expand Down