Skip to content

Commit 47de002

Browse files
authored
Merge pull request #17 from rofinn/rf/mkdir-fix
Fix recursive condition on mkdir
2 parents ceee16d + 40236c7 commit 47de002

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/path.jl

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -484,16 +484,20 @@ function Base.mkdir(path::AbstractPath; mode=0o777, recursive=false, exist_ok=fa
484484
if exists(path)
485485
!exist_ok && error("$path already exists.")
486486
else
487-
if !hasparent(path) || exists(parent(path))
488-
VERSION >= v"0.7-" ? mkdir(String(path), mode=mode) : mkdir(String(path), mode)
489-
elseif hasparent(path) && !exists(parent(path)) && recursive
490-
mkdir(parent(path); mode=mode, recursive=recursive, exist_ok=exist_ok)
491-
else
492-
error(
493-
"The parent of $path does not exist. " *
494-
"Pass recursive=true to create it."
495-
)
487+
if hasparent(path) && !exists(parent(path))
488+
if recursive
489+
mkdir(parent(path); mode=mode, recursive=recursive, exist_ok=exist_ok)
490+
else
491+
error(
492+
"The parent of $path does not exist. " *
493+
"Pass recursive=true to create it."
494+
)
495+
end
496496
end
497+
498+
499+
VERSION >= v"0.7-" ? mkdir(String(path), mode=mode) : mkdir(String(path), mode)
500+
497501
end
498502
end
499503

test/path.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ mktmpdir() do d
101101
new_path = p"foo/bar"
102102
@test_throws ErrorException mkdir(new_path)
103103
mkdir(new_path; recursive=true)
104+
@test exists(new_path)
104105
mkdir(new_path; recursive=true, exist_ok=true)
105106

106107
other_path = p"car/bar"

0 commit comments

Comments
 (0)