diff --git a/base/loading.jl b/base/loading.jl index b7b1a8524586b..8d8dc9915eab4 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -11,7 +11,7 @@ elseif OS_NAME == :Windows # GetLongPathName Win32 function returns the case-preserved filename on NTFS. function isfile_casesensitive(path) isfile(path) || return false # Fail fast - longpath(path) == path + Filesystem.longpath(path) == path end elseif OS_NAME == :Darwin # HFS+ filesystem is case-preserving. The getattrlist API returns diff --git a/base/path.jl b/base/path.jl index 87069494faa51..6f191a0cd67c5 100644 --- a/base/path.jl +++ b/base/path.jl @@ -126,16 +126,15 @@ abspath(a::AbstractString, b::AbstractString...) = abspath(joinpath(a,b...)) @windows_only realpath(path::AbstractString) = realpath(utf16(path)) @windows_only function realpath(path::UTF16String) - p = UInt32((sizeof(path)>>2) + 1) + p::UInt32 = sizeof(path)>>1 while true - buflength = p - buf = zeros(UInt16,buflength) - p = ccall((:GetFullPathNameW, "Kernel32"), stdcall, + buf = zeros(UInt16, p + 1) + p = ccall((:GetFullPathNameW, "kernel32"), stdcall, UInt32, (Cwstring, UInt32, Ptr{UInt16}, Ptr{Void}), - path, buflength, buf, C_NULL) + path, length(buf), buf, C_NULL) systemerror(:realpath, p == 0) - if (p < buflength) - resize!(buf, p+1) + if (p < length(buf)) + resize!(buf, p + 1) return utf8(UTF16String(buf)) end end @@ -143,18 +142,18 @@ end @windows_only longpath(path::AbstractString) = longpath(utf16(path)) @windows_only function longpath(path::UTF16String) - buf = Array(UInt16, length(path.data)) + p::UInt32 = sizeof(path)>>1 while true - p = ccall((:GetLongPathNameW, "Kernel32"), stdcall, UInt32, + buf = zeros(UInt16, p + 1) + p = ccall((:GetLongPathNameW, "kernel32"), stdcall, UInt32, (Cwstring, Ptr{UInt16}, UInt32), path, buf, length(buf)) systemerror(:longpath, p == 0) # Buffer wasn't big enough, in which case `p` is the necessary buffer size - if (p > length(buf)) - resize!(buf, p) - continue + if (p < length(buf)) + resize!(buf, p + 1) + return utf8(UTF16String(buf)) end - return utf8(UTF16String(buf)) end end