-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Breaking] Make basename
and dirname
ignore a trailing path separator
#43137
Comments
The "insane" behaviour you mention allows a path to be a directory and have it returned by If we are talking breaking, my suggestion would be that Then if anybody still wants the odd (but standardised) Unix behaviour the names |
Are you referring to julia> dirname("/tmp/bar/")
"/tmp/bar" ? |
Yes, compared to Unix:
PS I quoted "insane" to imply that I do not agree with the OP on that assessment, sorry if that confused anyone. |
Well, I specifically don't like that behaviour, and I provided examples where you need extra checks to avoid |
So how do I pass a directory path as a string? The current behaviour allows indicating that to Basically there are two behaviours that have differing use-cases, so given the choice, why not have both as I suggested, why cut off other peoples behaviours just because you don't want it? |
I'm not opposed to having a different function which does something else. I'm still missing the use case (honestly I don't understand what you mean by "pass a directory as a string"), but that's not my concern, I'll probably not use it and that's it. I'd just like |
Good we agree, and I hope others do to, just please don't call behaviour for use-cases you don't know or understand "odd" "not sane" etc. |
If we're going to think about this as a "Julia 2.0" change, I can't help but mention actually having a path type to work around a large class of "file paths are just strings" issues. |
Statement of the problem
Currently,
basename
anddirname
have this documented, yet odd, behaviour:What these functions do when there is a trailing path separator doesn't make any sense. For example, the Single Unix Specification, §3.170 doesn't allow empty files names, which are defined as follow:
Additionally, this doesn't match what the Unix utilities with the same names do:
I was told that this behaviour was borrowed from Python's
os.path.basename
andos.path.dirname
, but this doesn't change the fact it's meaningless.This also makes it harder than necessary to automatically handle paths received from other functions, which may or may not have a trailing path separator, so if you are aware of
basename
anddirname
oddness you have to do checks likejulia/base/file.jl
Line 235 in 85f4db2
and a similar one is used in
BinaryBuilder
as well.Solution
My suggestion is to make
basename
anddirname
ignore trailing path separators.This was discussed already in #33000 and resolved by explicitly documenting the current behaviour in #37580. Here I'd like to ask to consider making the breaking change for Julia v2.0, basically what #33021 tried to do. I'd argue that no one in their sane mind should rely on
basename
reporting an empty string: if they want to know whether a path ends with a path separator, that's the job ofisdirpath
. Therefore, my expectation is that this change will cause very little breakage in practice.The text was updated successfully, but these errors were encountered: