Skip to content

Commit

Permalink
mkpath should always return the path [fix #29989] (#29990)
Browse files Browse the repository at this point in the history
(cherry picked from commit 151f853)
  • Loading branch information
StefanKarpinski authored and KristofferC committed Feb 11, 2019
1 parent 66194ad commit 8b79d2b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
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 @@ -1004,13 +1004,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

0 comments on commit 8b79d2b

Please sign in to comment.