-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Use libuv for tempdir function #31434
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -424,18 +424,34 @@ function touch(path::AbstractString) | |
path | ||
end | ||
|
||
const temp_prefix = "jl_" | ||
|
||
if Sys.iswindows() | ||
""" | ||
tempdir() | ||
|
||
Gets the path of the temporary directory. 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. | ||
""" | ||
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) | ||
return transcode(String, temppath) | ||
buf = Base.StringVector(AVG_PATH - 1) # space for null-terminator implied by StringVector | ||
sz = RefValue{Csize_t}(length(buf) + 1) # total buffer size including null | ||
while true | ||
rc = ccall(:uv_os_tmpdir, Cint, (Ptr{UInt8}, Ptr{Csize_t}), buf, sz) | ||
if rc == 0 | ||
resize!(buf, sz[]) | ||
return String(buf) | ||
elseif rc == Base.UV_ENOBUFS | ||
resize!(buf, sz[] - 1) # space for null-terminator implied by StringVector | ||
else | ||
uv_error(:tmpdir, rc) | ||
end | ||
end | ||
end | ||
|
||
const temp_prefix = "jl_" | ||
|
||
if Sys.iswindows() | ||
|
||
function _win_tempname(temppath::AbstractString, uunique::UInt32) | ||
tempp = cwstring(temppath) | ||
temppfx = cwstring(temp_prefix) | ||
|
@@ -481,9 +497,6 @@ function tempname() | |
return s | ||
end | ||
|
||
# Obtain a temporary directory's path. | ||
tempdir() = dirname(tempname()) | ||
|
||
# Create and return the name of a temporary file along with an IOStream | ||
function mktemp(parent=tempdir()) | ||
b = joinpath(parent, temp_prefix * "XXXXXX") | ||
|
@@ -496,13 +509,6 @@ end | |
end # os-test | ||
|
||
|
||
""" | ||
tempdir() | ||
|
||
Obtain the path of a temporary directory (possibly shared with other processes). | ||
""" | ||
tempdir() | ||
|
||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the Aside: the windows implementation of |
||
tempname() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to use
tempdir()
ford
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will make these changes in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm. feel free to merge.