JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.16k stars 5.45k forks source link

`mkpath` does not stably return the original path #54826

Closed ctarn closed 2 weeks ago

ctarn commented 1 month ago

According to the doc, mkpath(path) should always return path. However, currently (1.10.4) it returns dirname(path) if isdirpath(path), e.g., the / is removed if path ends with /.

mkpath(path::AbstractString; mode::Unsigned = 0o777)

Create all intermediate directories in the path as required. Directories are created with the permissions mode which defaults to 0o777 and is modified by the current file creation mask. Unlike mkdir, mkpath does not error if path (or parts of it) already exists. However, an error will be thrown if path (or parts of it) points to an existing file. Return path.

julia> mkpath("test/")
"test"

julia> mkpath("test/te")
"test/te"

I would like to know if there is anyone who wants to keep the current behavior. If not, I will create a PR to fix it since it brings some trouble to me :)

It will not break cases like #27071 , since

julia> joinpath("test/", "te") == joinpath("test", "te")
true
ctarn commented 3 weeks ago

I created a PR to fix the issue. I would be grateful if there is anyone who can review the PR #54857