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

readdir: default to "." or pwd() depending on join keyword #33175

Merged
merged 1 commit into from
Sep 7, 2019
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
3 changes: 2 additions & 1 deletion base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ julia> readdir(abspath("base"), join=true)
"/home/JuliaUser/dev/julia/base/weakkeydict.jl"
```
"""
function readdir(dir::AbstractString=pwd(); join::Bool=false)
function readdir(dir::AbstractString; join::Bool=false)
StefanKarpinski marked this conversation as resolved.
Show resolved Hide resolved
# Allocate space for uv_fs_t struct
uv_readdir_req = zeros(UInt8, ccall(:jl_sizeof_uv_fs_t, Int32, ()))

Expand All @@ -759,6 +759,7 @@ function readdir(dir::AbstractString=pwd(); join::Bool=false)

return entries
end
readdir(; join::Bool=false) = readdir(join ? pwd() : ".", join=join)

"""
walkdir(dir; topdown=true, follow_symlinks=false, onerror=throw)
Expand Down
19 changes: 18 additions & 1 deletion test/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,7 @@ end
end
end

@testset "readir tests" begin
@testset "readdir tests" begin
≛(a, b) = sort(a) == sort(b)
mktempdir() do dir
d = cd(pwd, dir) # might resolve symlinks
Expand All @@ -1431,4 +1431,21 @@ end
@test readdir(b, join=true) ≛ [joinpath(b, x) for x in names]
end
end
if !Sys.iswindows()
mktempdir() do dir
cd(dir) do
d = pwd() # might resolve symlinks
@test isdir(d)
@test Base.Filesystem.samefile(d, ".")
@test isempty(readdir())
@test isempty(readdir(d))
@test isempty(readdir(join=true))
rm(d, recursive=true)
@test !ispath(d)
@test isempty(readdir())
@test_throws SystemError readdir(d)
@test_throws Base.IOError readdir(join=true)
end
end
end
end