# Mkpath behaves differently on Julia 1.12-rc1

**URL:** https://discourse.julialang.org/t/mkpath-behaves-differently-on-julia-1-12-rc1/131527
**Category:** General Usage
**Tags:** question
**Created:** [August 11, 2025, 10:04am UTC](https://discourse.julialang.org/t/mkpath-behaves-differently-on-julia-1-12-rc1/131527 "2025-08-11T10:04:33Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [August 11, 2025, 10:04am UTC](https://discourse.julialang.org/t/mkpath-behaves-differently-on-julia-1-12-rc1/131527/1 "2025-08-11T10:04:33Z")

</div>

Julia 1.11:

```julia
cd(mktempdir())
mkpath("uwe/")

```

Output: `"uwe"`

Julia 1.12-rc1:

```julia
cd(mktempdir())
mkpath("uwe/")

```

Output: `"uwe/"`

This difference causes my unit tests to fail.

Is this a bug, or just undefined behaviour?

This is on Ubuntu Linux.

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [August 11, 2025, 10:15am UTC](https://discourse.julialang.org/t/mkpath-behaves-differently-on-julia-1-12-rc1/131527/2 "2025-08-11T10:15:10Z")

</div>

If you care about your mental sanity, you should _ **really** _ not rely on the trailing path separator being there, you should always get rid of it before doing anything else with that path. See [[Breaking] Make `basename` and `dirname` ignore a trailing path separator · Issue #43137 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/43137) as an example where the trailing separator causes different behaviour.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [August 11, 2025, 10:18am UTC](https://discourse.julialang.org/t/mkpath-behaves-differently-on-julia-1-12-rc1/131527/3 "2025-08-11T10:18:47Z")

</div>

In principle, I agree. But I still do not know if I should report that as bug in the Julia repo.

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [August 11, 2025, 10:25am UTC](https://discourse.julialang.org/t/mkpath-behaves-differently-on-julia-1-12-rc1/131527/4 "2025-08-11T10:25:18Z")

</div>

That seems to be a deliberate change:

> <https://github.com/JuliaLang/julia/pull/54857>
>
> fix #54826
> 
> related performance test code:
> \`\`\`julia
> using BenchmarkTools
> us…ing Base: IOError
> 
> function checkmode(mode::Integer)
> if !(0 \<= mode \<= 511)
> throw(ArgumentError("Mode must be between 0 and 511 = 0o777"))
> end
> mode
> end
> 
> function mkpath(path::AbstractString; mode::Integer = 0o777)
> dir = dirname(path)
> # stop recursion for \`""\`, \`"/"\`, or existed dir
> (path == dir || isdir(path)) && return path
> mkpath(dir, mode = checkmode(mode))
> try
> # cases like \`mkpath("x/")\` will cause an error if \`isdir(path)\` is skipped
> # the error will not be rethrowed, but it may be slower, and thus we avoid it in advance
> isdir(path) || mkdir(path, mode = mode)
> 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, IOError) || !isdir(path)
> rethrow()
> end
> end
> return path
> end
> 
> function mkpath\_2(path::AbstractString; mode::Integer = 0o777)
> dir = dirname(path)
> # stop recursion for \`""\` and \`"/"\` or existed dir
> (path == dir || isdir(path)) && return path
> mkpath\_2(dir, mode = checkmode(mode))
> try
> mkdir(path, mode = mode)
> 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, IOError) || !isdir(path)
> rethrow()
> end
> end
> return path
> end
> 
> versioninfo()
> display(@benchmark begin rm("A", recursive=true, force=true); mkpath("A/B/C/D/") end)
> display(@benchmark begin rm("A", recursive=true, force=true); mkpath\_2("A/B/C/D/") end)
> \`\`\`
> output:
> \`\`\`
> Julia Version 1.10.4
> Commit 48d4fd48430 (2024-06-04 10:41 UTC)
> Build Info:
> Official https://julialang.org/ release
> Platform Info:
> OS: macOS (x86\_64-apple-darwin22.4.0)
> CPU: 16 × Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
> WORD\_SIZE: 64
> LIBM: libopenlibm
> LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
> Threads: 1 default, 0 interactive, 1 GC (on 16 virtual cores)
> Environment:
> JULIA\_EDITOR = code
> JULIA\_NUM\_THREADS = 
> BenchmarkTools.Trial: 8683 samples with 1 evaluation.
> Range (min … max): 473.972 μs … 18.867 ms ┊ GC (min … max): 0.00% … 0.00%
> Time (median): 519.704 μs ┊ GC (median): 0.00%
> Time (mean ± σ): 571.261 μs ± 378.851 μs ┊ GC (mean ± σ): 0.00% ± 0.00%
> 
> ▂█▇▄▁                                                         
> ▃███████▇▅▄▄▃▃▃▂▂▂▂▂▂▂▂▂▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
> 474 μs Histogram: frequency by time 961 μs \<
> 
> Memory estimate: 5.98 KiB, allocs estimate: 65.
> BenchmarkTools.Trial: 6531 samples with 1 evaluation.
> Range (min … max): 588.122 μs … 17.449 ms ┊ GC (min … max): 0.00% … 0.00%
> Time (median): 660.071 μs ┊ GC (median): 0.00%
> Time (mean ± σ): 760.333 μs ± 615.759 μs ┊ GC (mean ± σ): 0.00% ± 0.00%
> 
> ██▆▄▃▁▁ ▁
> ██████████▆▇█▇▆▆▅▅▅▄▁▄▁▄▄▃▄▃▁▃▃▁▃▁▁▁▄▁▁▁▁▁▁▁▃▃▁▁▁▃▁▁▃▁▁▁▁▅▅▄▇ █
> 588 μs Histogram: log(frequency) by time 4.2 ms \<
> 
> Memory estimate: 5.63 KiB, allocs estimate: 72.
> \`\`\`

The [linked issue](https://github.com/JuliaLang/julia/issues/54826) specifically talks about the case of directories ending with path separator. The handling of the trailing path separator is maddening.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [August 11, 2025, 10:35am UTC](https://discourse.julialang.org/t/mkpath-behaves-differently-on-julia-1-12-rc1/131527/5 "2025-08-11T10:35:19Z")

</div>

I created an issue:

> <https://github.com/JuliaLang/julia/issues/59249>
>
> Example:
> 
> Julia 1.11:
> \`\`\`julia
> cd(mktempdir())
> mkpath("uwe/")
> \`\`\`
> Output: \`"uwe"…\`
> 
> Julia 1.12-rc1:
> \`\`\`julia
> cd(mktempdir())
> mkpath("uwe/")
> \`\`\`
> Output: \`"uwe/"\`
> 
> This difference causes my unit tests to fail.
> 
> This seams to be an intended change, see: https://github.com/JuliaLang/julia/pull/54857
> 
> But then it should be mentioned in the release notes.
