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

mkpath should always return the path (fix #29989) #29990

Merged
merged 1 commit into from
Nov 10, 2018
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
6 changes: 3 additions & 3 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ julia> readdir("test")
function mkpath(path::AbstractString; mode::Integer = 0o777)
isdirpath(path) && (path = dirname(path))
dir = dirname(path)
(path == dir || isdir(path)) && return
(path == dir || isdir(path)) && return path
mkpath(dir, mode = checkmode(mode))
try
mkdir(path, mode = mode)
# If there is a problem with making the directory, but the directory
# does in fact exist, then ignore the error. Else re-throw it.
catch err
# If there is a problem with making the directory, but the directory
# does in fact exist, then ignore the error. Else re-throw it.
if !isa(err, SystemError) || !isdir(path)
rethrow()
end
Expand Down
8 changes: 5 additions & 3 deletions test/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1015,13 +1015,15 @@ rm(dir)
mktempdir() do dir
name1 = joinpath(dir, "apples")
name2 = joinpath(dir, "bannanas")
@test touch(name1)==name1
@test touch(name1) == name1 # when it doesn't exist
@test touch(name1) == name1 # when it does exist
@test mv(name1, name2) == name2
@test cp(name2, name1) == name1
namedir = joinpath(dir, "chalk")
namepath = joinpath(dir, "chalk","cheese","fresh")
@test mkdir(namedir) == namedir
@test mkpath(namepath) == namepath
@test mkdir(namedir) == namedir # when it doesn't exist
@test mkpath(namepath) == namepath # when it doesn't exist
@test mkpath(namepath) == namepath # when it does exist
end


Expand Down