Skip to content

Commit

Permalink
rename and make private
Browse files Browse the repository at this point in the history
Co-Authored-By: Cody Tapscott <84105208+topolarity@users.noreply.github.com>
  • Loading branch information
IanButterworth and topolarity committed Feb 29, 2024
1 parent 8f997dd commit d81131f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 21 deletions.
2 changes: 0 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ New library functions
---------------------

* `logrange(start, stop; length)` makes a range of constant ratio, instead of constant step ([#39071])
* `readdirx` for returning directory contents along with the type of the entries in a vector of new `DirEntry`
objects ([#53377])

New library features
--------------------
Expand Down
2 changes: 0 additions & 2 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,6 @@ export
eof,
fd,
fdio,
DirEntry,
flush,
gethostname,
htol,
Expand All @@ -866,7 +865,6 @@ export
readbytes!,
readchomp,
readdir,
readdirx,
readline,
readlines,
readuntil,
Expand Down
12 changes: 6 additions & 6 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export
rename,
readlink,
readdir,
readdirx,
rm,
samefile,
sendfile,
Expand Down Expand Up @@ -977,15 +976,16 @@ isfifo(obj::DirEntry) = (isunknown(obj) || islink(obj)) ? isfifo(obj.path)
issocket(obj::DirEntry) = (isunknown(obj) || islink(obj)) ? issocket(obj.path) : obj.rawtype == UV_DIRENT_SOCKET
ischardev(obj::DirEntry) = (isunknown(obj) || islink(obj)) ? ischardev(obj.path) : obj.rawtype == UV_DIRENT_CHAR
isblockdev(obj::DirEntry) = (isunknown(obj) || islink(obj)) ? isblockdev(obj.path) : obj.rawtype == UV_DIRENT_BLOCK
realpath(obj::DirEntry) = realpath(obj.path)

"""
readdirx(dir::AbstractString=pwd(); sort::Bool = true) -> Vector{DirEntry}
_readdirx(dir::AbstractString=pwd(); sort::Bool = true) -> Vector{DirEntry}
Return a vector of [`DirEntry`](@ref) objects representing the contents of the directory `dir`,
or the current working directory if not given. If `sort` is true, the returned vector is
sorted by name.
Unlike [`readdir`](@ref), `readdirx` returns [`DirEntry`](@ref) objects, which contain the name of the
Unlike [`readdir`](@ref), `_readdirx` returns [`DirEntry`](@ref) objects, which contain the name of the
file, the directory it is in, and the type of the file which is determined during the
directory scan. This means that calls to [`isfile`](@ref), [`isdir`](@ref), [`islink`](@ref), [`isfifo`](@ref),
[`issocket`](@ref), [`ischardev`](@ref), and [`isblockdev`](@ref) can be made on the
Expand All @@ -994,12 +994,12 @@ cannot be determined without a stat call. In these cases the `rawtype` field of
object will be 0 (`UV_DIRENT_UNKNOWN`) and [`isfile`](@ref) etc. will fall back to a `stat` call.
```julia
for obj in readdirx()
isfile(obj) && println("$(obj.name) is a file with path $(obj.path)")
for obj in _readdirx()
isfile(obj) && println("\$(obj.name) is a file with path \$(obj.path)")
end
```
"""
readdirx(dir::AbstractString=pwd(); sort::Bool=true) = _readdir(dir; return_objects=true, sort)::Vector{DirEntry}
_readdirx(dir::AbstractString=pwd(); sort::Bool=true) = _readdir(dir; return_objects=true, sort)::Vector{DirEntry}

function _readdir(dir::AbstractString; return_objects::Bool=false, join::Bool=false, sort::Bool=true)
# Allocate space for uv_fs_t struct
Expand Down
2 changes: 0 additions & 2 deletions doc/src/base/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ Base.Filesystem.pwd
Base.Filesystem.cd(::AbstractString)
Base.Filesystem.cd(::Function)
Base.Filesystem.readdir
Base.Filesystem.readdirx
Base.Filesystem.DirEntry
Base.Filesystem.walkdir
Base.Filesystem.mkdir
Base.Filesystem.mkpath
Expand Down
15 changes: 8 additions & 7 deletions test/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ if !Sys.iswindows() || Sys.windows_version() >= Sys.WINDOWS_VISTA_VER
symlink(subdir, dirlink)
@test stat(dirlink) == stat(subdir)
@test readdir(dirlink) == readdir(subdir)
@test readdirx(dirlink) == readdirx(subdir)
@test map(o->o.names, Base.Filesystem._readdirx(dirlink)) == map(o->o.names, Base.Filesystem._readdirx(subdir))
@test realpath.(Base.Filesystem._readdirx(dirlink)) == realpath.(Base.Filesystem._readdirx(subdir))

# relative link
relsubdirlink = joinpath(subdir, "rel_subdirlink")
reldir = joinpath("..", "adir2")
symlink(reldir, relsubdirlink)
@test stat(relsubdirlink) == stat(subdir2)
@test readdir(relsubdirlink) == readdir(subdir2)
@test readdirx(relsubdirlink) == readdirx(subdir2)
@test Base.Filesystem._readdirx(relsubdirlink) == Base.Filesystem._readdirx(subdir2)

# creation of symlink to directory that does not yet exist
new_dir = joinpath(subdir, "new_dir")
Expand All @@ -58,7 +59,7 @@ if !Sys.iswindows() || Sys.windows_version() >= Sys.WINDOWS_VISTA_VER
mkdir(new_dir)
touch(foo_file)
@test readdir(new_dir) == readdir(nedlink)
@test readdirx(new_dir) == readdirx(nedlink)
@test realpath.(Base.Filesystem._readdirx(new_dir)) == realpath.(Base.Filesystem._readdirx(nedlink))

rm(foo_file)
rm(new_dir)
Expand Down Expand Up @@ -1444,10 +1445,10 @@ rm(dirwalk, recursive=true)
touch(randstring())
end
@test issorted(readdir())
@test issorted(readdirx())
@test map(o->o.name, readdirx()) == readdir()
@test map(o->o.path, readdirx()) == readdir(join=true)
@test count(isfile, readdir(join=true)) == count(isfile, readdirx())
@test issorted(Base.Filesystem._readdirx())
@test map(o->o.name, Base.Filesystem._readdirx()) == readdir()
@test map(o->o.path, Base.Filesystem._readdirx()) == readdir(join=true)
@test count(isfile, readdir(join=true)) == count(isfile, Base.Filesystem._readdirx())
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1363,9 +1363,10 @@ end
@test isdefined(KwdefWithEsc_TestModule, :Struct)

@testset "exports of modules" begin
for (_, mod) in Base.loaded_modules
@testset "$mod" for (_, mod) in Base.loaded_modules
mod === Main && continue # Main exports everything
for v in names(mod)
@testset "$v" for v in names(mod)
isdefined(mod, v) || @error "missing $v in $mod"
@test isdefined(mod, v)
end
end
Expand Down

0 comments on commit d81131f

Please sign in to comment.