Skip to content

Problem with isfile_casesensitive() on Windows #54799

@kimikage

Description

@kimikage

An internal function isfile_casesensitive() uses Win32API GetLongPathNameW on Windows.

julia/base/loading.jl

Lines 11 to 16 in 222231f

elseif Sys.iswindows()
# GetLongPathName Win32 function returns the case-preserved filename on NTFS.
function isfile_casesensitive(path)
isaccessiblefile(path) || return false # Fail fast
basename(Filesystem.longpath(path)) == basename(path)
end

However, the API may not be able to handle non-existent directories.

julia> dir = joinpath(DEPOT_PATH[1], "environments", "v1.10") # just an example
"C:\\Users\\username\\.julia\\environments\\v1.10"

julia> Base.Filesystem.longpath(joinpath(dir, "Project.toml"))
"C:\\Users\\username\\.julia\\environments\\v1.10\\Project.toml"

julia> Base.Filesystem.longpath(joinpath(dir, "nonexistent", "..", "Project.toml"))
ERROR: SystemError: longpath: The system cannot find the file specified.
Stacktrace:
 [1] windowserror(p::Symbol, code::UInt32; extrainfo::Nothing)
   @ Base .\error.jl:200
 [2] windowserror
   @ .\error.jl:199 [inlined]
 [3] longpath(path::String)
   @ Base.Filesystem .\path.jl:479
 [4] top-level scope
   @ REPL[3]:1

julia> versioninfo()
Julia Version 1.12.0-DEV.727
Commit 3054c00d33 (2024-06-14 05:13 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
  WORD_SIZE: 64
  LLVM: libLLVM-17.0.6 (ORCJIT, tigerlake)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)

This problem can also be reproduced on Julia v1.6.7.
Perhaps `normpath()' would mitigate this problem.

Incidentally, parent directories of non-existent directories seem to be invalid on Linux from the beginning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions