Skip to content
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

Unset TMPDIR before calling tempnam in tempname #35342

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,9 @@ else # !windows
# Obtain a temporary filename.
function tempname(parent::AbstractString=tempdir(); cleanup::Bool=true)
isdir(parent) || throw(ArgumentError("$(repr(parent)) is not a directory"))
p = ccall(:tempnam, Cstring, (Cstring, Cstring), parent, temp_prefix)
p = withenv("TMPDIR" => nothing) do
ccall(:tempnam, Cstring, (Cstring, Cstring), parent, temp_prefix)
end
systemerror(:tempnam, p == C_NULL)
s = unsafe_string(p)
Libc.free(p)
Expand Down
9 changes: 9 additions & 0 deletions test/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ end
@test_throws ArgumentError tempname(randstring())
end

@testset "tempname with parent and TMPDIR" begin
withenv("TMPDIR" => tempdir()) do
mktempdir() do d
t = tempname(d)
@test dirname(t) == d
end
end
end

child_eval(code::String) = eval(Meta.parse(readchomp(`$(Base.julia_cmd()) -E $code`)))

@testset "mktemp/dir basic cleanup" begin
Expand Down