Skip to content

Commit

Permalink
mkpath should always return the path (fix #29989)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Nov 9, 2018
1 parent a3599e9 commit b9c5bec
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 @@ -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

0 comments on commit b9c5bec

Please sign in to comment.