Skip to content

Commit

Permalink
Use uv_os_tmpdir instead
Browse files Browse the repository at this point in the history
  • Loading branch information
musm committed Jun 11, 2019
1 parent 3704de0 commit 42ffe4a
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -420,22 +420,6 @@ const temp_prefix = "jl_"

if Sys.iswindows()

function ispathroot(path::String)
m = match(r"^([^\\]+:|\\\\[^\\]+\\[^\\]+|\\\\\?\\UNC\\[^\\]+\\[^\\]+|\\\\\?\\[^\\]+:|)(.*)$", path).captures[2]
return m == "\\" || isempty(m)
end

function tempdir()
temppath = Vector{UInt16}(undef, 32767)
lentemppath = ccall(:GetTempPathW, stdcall, UInt32, (UInt32, Ptr{UInt16}), length(temppath), temppath)
windowserror("GetTempPath", lentemppath >= length(temppath) || lentemppath == 0)
resize!(temppath, lentemppath - (temppath[lentemppath]==0x005c)) # ignore trailing `\` (according to docs GetTempPathW always adds '\')
path = transcode(String, temppath)
isroot = ispathroot(path)
# add trailing '\' back for drive root and UNC paths
return isroot ? path * '\\' : path
end

function _win_tempname(temppath::AbstractString, uunique::UInt32)
tempp = cwstring(temppath)
temppfx = cwstring(temp_prefix)
Expand Down Expand Up @@ -482,7 +466,14 @@ function tempname()
end

# Obtain a temporary directory's path.
tempdir() = dirname(tempname())
function tempdir()
path_max = 1024
buf = Vector{UInt8}(undef, path_max)
sz = Ref{Csize_t}(path_max)
rc = ccall(:uv_os_tmpdir, Cint, (Ptr{UInt8}, Ptr{Csize_t}), buf, sz)
resize!(buf, sz[])
return String(buf)
end

# Create and return the name of a temporary file along with an IOStream
function mktemp(parent=tempdir())
Expand All @@ -499,7 +490,11 @@ end # os-test
"""
tempdir()
Obtain the path of a temporary directory (possibly shared with other processes).
Obtain the path of a temporary directory (possibly shared with other processes). On Windows,
`tempdir()` uses the first environment variable found in the ordered list `TMP`, `TEMP`,
`USERPROFILE`. On all other operating systems, `tempdir()` uses the first environment
variable found in the ordered list `TMPDIR`, `TMP`, `TEMP`, and `TEMPDIR`. If none of these are
found, the path `"/tmp"` is used.
"""
tempdir()

Expand Down

0 comments on commit 42ffe4a

Please sign in to comment.