From 8b79d2b0a9d31e6740c47d1fd7b499633d884e36 Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Sat, 10 Nov 2018 12:42:42 -0500 Subject: [PATCH] mkpath should always return the path [fix #29989] (#29990) (cherry picked from commit 151f85328ec2e086eb6517e8a8250621cf88f946) --- base/file.jl | 6 +++--- test/file.jl | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/base/file.jl b/base/file.jl index da966d37f0e490..f7a61dbf60144e 100644 --- a/base/file.jl +++ b/base/file.jl @@ -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 diff --git a/test/file.jl b/test/file.jl index 7d302463650e8b..cff58deabbdd02 100644 --- a/test/file.jl +++ b/test/file.jl @@ -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