Skip to content

Commit

Permalink
Allow RPC_S_UUID_NO_ADDRESS; return filename when cleanup false; remo…
Browse files Browse the repository at this point in the history
…ve let scoping
  • Loading branch information
musm committed Nov 8, 2019
1 parent 9096247 commit 5dd28e7
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,8 @@ function mktemp(parent::AbstractString=tempdir(); cleanup::Bool=true)
return (filename, Base.open(filename, "r+"))
end

let
global tempname

# GUID win32 api
# TODO: refactor
struct GUID
l1::Culong
w1::Cushort
Expand All @@ -529,7 +528,7 @@ function tempname(parent::AbstractString=tempdir(); cleanup::Bool=true)

id = Ref{GUID}()
r = ccall((:UuidCreate,:Rpcrt4), Cint, (Ref{GUID},), id)
r == 0 || (r == RPC_S_UUID_LOCAL_ONLY && (@warn "UIUD guaranteed to be unique to this computer only"; true)) || (r == RPC_S_UUID_NO_ADDRESS && error("Cannot get Ethernet or token-ring hardware address for this computer."))
(r == 0 || r == RPC_S_UUID_LOCAL_ONLY) || (r == RPC_S_UUID_NO_ADDRESS && error("Cannot get Ethernet or token-ring hardware address for this computer."))

nameptr = Ref{Ptr{Cwchar_t}}()
r = ccall((:UuidToStringW, :Rpcrt4), Cint, (Ref{GUID}, Ref{Ptr{Cwchar_t}}), id, nameptr)
Expand All @@ -540,17 +539,15 @@ function tempname(parent::AbstractString=tempdir(); cleanup::Bool=true)

@assert ccall((:RpcStringFreeW, :Rpcrt4), Cint, (Ref{Ptr{Cwchar_t}},), nameptr) == 0

filename = joinpath(parent, name)
if !ispath(filename)
cleanup && temp_cleanup_later(filename)
filename = joinpath(parent, temp_prefix * name)
if !cleanup
return filename
else
tempname(parent; cleanup=cleanup)
# in the unlikley scenario filename is a path, call this function again regenerate a unique filename
return !ispath(filename) ? (temp_cleanup_later(filename); filename) : tempname(parent; cleanup=cleanup)
end
end

end

else # !windows

# Obtain a temporary filename.
Expand Down

0 comments on commit 5dd28e7

Please sign in to comment.