Skip to content
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

@__DIR__ and @__FILE__ should use upercase drive letter on Windows #26000

Open
davidanthoff opened this issue Feb 11, 2018 · 5 comments
Open
Labels
bug Indicates an unexpected problem or unintended behavior correctness bug ⚠ Bugs that are likely to lead to incorrect results in user code without throwing system:windows Affects only Windows

Comments

@davidanthoff
Copy link
Contributor

Both macros currently seem to return paths that use lowercase drive letters, i.e. something like c:\\bla\\bla. Functions like homedir() and abspath on the other hand return paths with uppercase drive letters. Things then break when one tries to mix paths returned from these macros with paths returned from things like homedir with the relpath function because it is case-sensitive.

I guess another option would be to make relpath on Windows case-insensitive. But it might be easier to just change the two macros?

@StefanKarpinski
Copy link
Member

Probably both should be done. When comparing drive letters I think that the drive comparison should be case insensitive since the underlying file system considers c: and C: to be the same thing. However, the @__DIR__ and @__FILE__ macros should return whatever the standard capitalization is, which presumably is uppercase?

@StefanKarpinski StefanKarpinski added bug Indicates an unexpected problem or unintended behavior system:windows Affects only Windows labels Feb 12, 2018
@StefanKarpinski StefanKarpinski added this to the 1.0.x milestone Feb 12, 2018
@ihnorton
Copy link
Member

Related to #9436 (making samefile work correctly on case-insensitive FS)

@davidanthoff
Copy link
Contributor Author

I just tried to figure out how this could be fixed, but I think the string with that path is constructed somewhere in the non-Julia parts, as far as I can tell. Which means it is above my pay grade :) Having said that, it would be fantastic if this could be fixed, this is constantly tripping up code on Windows that is comparing paths...

@2005m
Copy link
Contributor

2005m commented May 21, 2021

Hi,
abspath does not return paths with uppercase drive letters for me.
what about changing the function cd to something like this (not tested):

function cd(dir::AbstractString)
    if Sys.iswindows()
        m = match(r"[a-z]:", dir)
        if typeof(m) != Nothing
            dir = replace(dir, m.match => uppercase(m.match))
        end
    end
    err = ccall(:uv_chdir, Cint, (Cstring,), dir)
    err < 0 && uv_error("cd($(repr(dir)))", err)
    return nothing
end

@DilumAluthge DilumAluthge removed this from the 1.x.y milestone Mar 13, 2022
@LilithHafner LilithHafner added the correctness bug ⚠ Bugs that are likely to lead to incorrect results in user code without throwing label Aug 7, 2023
@inkydragon
Copy link
Member

It seems that this issue has been fixed?
Or maybe I didn't find the right way to reproduce it.

Current LTS version on Win 11:

julia> versioninfo()
Julia Version 1.10.6
Commit 67dffc4a8a (2024-10-28 12:23 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 32 × 13th Gen Intel(R) Core(TM) i9-13900HX
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, goldmont)
Threads: 1 default, 0 interactive, 1 GC (on 32 virtual cores)

julia> @info "Julia v$(VERSION):" (@__DIR__) (@__FILE__)
┌ Info: Julia v1.10.6:#= REPL[2]:1 =# @__DIR__ = "T:\\jl-testall"#= REPL[2]:1 =# @__FILE__ = "REPL[2]"

Test across versions:

test code

# bugs.jl
@info "Julia v$(VERSION):" (@__DIR__) (@__FILE__)

test script

# test-all-versions.ps1
Set-PSDebug -Trace 1

julia +1.0      bugs.jl
julia +1.6      bugs.jl

julia +1.10.0   bugs.jl
julia +1.10     bugs.jl

julia +1.11.0   bugs.jl
julia +1.11     bugs.jl

julia +nightly  bugs.jl

Output:

PS T:\jl-testall> .\test-all-versions.ps1
DEBUG:    1+  >>>> .\test-all-versions.ps1
DEBUG:    2+  >>>> Set-PSDebug -Trace 1

DEBUG:    4+  >>>> julia +1.0      bugs.jl

┌ Info: Julia v1.0.5:
│   #= T:\jl-testall\bugs.jl:2 =# @__DIR__ = "T:\\jl-testall"
└   #= T:\jl-testall\bugs.jl:2 =# @__FILE__ = "T:\\jl-testall\\bugs.jl"

DEBUG:    5+  >>>> julia +1.6      bugs.jl

┌ Info: Julia v1.6.7:
│   #= T:\jl-testall\bugs.jl:2 =# @__DIR__ = "T:\\jl-testall"
└   #= T:\jl-testall\bugs.jl:2 =# @__FILE__ = "T:\\jl-testall\\bugs.jl"

DEBUG:    7+  >>>> julia +1.10.0   bugs.jl

┌ Info: Julia v1.10.0:
│   #= T:\jl-testall\bugs.jl:2 =# @__DIR__ = "T:\\jl-testall"
└   #= T:\jl-testall\bugs.jl:2 =# @__FILE__ = "T:\\jl-testall\\bugs.jl"

DEBUG:    8+  >>>> julia +1.10     bugs.jl

┌ Info: Julia v1.10.6:
│   #= T:\jl-testall\bugs.jl:2 =# @__DIR__ = "T:\\jl-testall"
└   #= T:\jl-testall\bugs.jl:2 =# @__FILE__ = "T:\\jl-testall\\bugs.jl"

DEBUG:   10+  >>>> julia +1.11.0   bugs.jl

┌ Info: Julia v1.11.0:
│   #= T:\jl-testall\bugs.jl:2 =# @__DIR__ = "T:\\jl-testall"
└   #= T:\jl-testall\bugs.jl:2 =# @__FILE__ = "T:\\jl-testall\\bugs.jl"

DEBUG:   11+  >>>> julia +1.11     bugs.jl

┌ Info: Julia v1.11.1:
│   #= T:\jl-testall\bugs.jl:2 =# @__DIR__ = "T:\\jl-testall"
└   #= T:\jl-testall\bugs.jl:2 =# @__FILE__ = "T:\\jl-testall\\bugs.jl"

DEBUG:   13+  >>>> julia +nightly  bugs.jl

A new `nightly` version is available. Install with `juliaup update`.
┌ Info: Julia v1.12.0-DEV.1542:
│   #= T:\jl-testall\bugs.jl:2 =# @__DIR__ = "T:\\jl-testall"
└   #= T:\jl-testall\bugs.jl:2 =# @__FILE__ = "T:\\jl-testall\\bugs.jl"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior correctness bug ⚠ Bugs that are likely to lead to incorrect results in user code without throwing system:windows Affects only Windows
Projects
None yet
Development

No branches or pull requests

7 participants