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

On Linux, tempname ignores the parent argument if the TMPDIR environment variable is set #43011

Closed
DilumAluthge opened this issue Nov 9, 2021 · 1 comment
Labels
filesystem Underlying file system and functions that use it system:linux Affects only Linux

Comments

@DilumAluthge
Copy link
Member

DilumAluthge commented Nov 9, 2021

The docstring for tempname says:

If a parent directory argument is given, the temporary path will be in that directory instead.

However, this is not always true. On Linux, if the TMPDIR environment variable is set, then the temporary file paths generated by tempname will always be in the TMPDIR directory, even if the parent argument is passed to the tempname function.

Is this a bug, or is this expected behavior?

Demonstration:

julia> delete!(ENV, "TMPDIR");

julia> d1 = mktempdir()
"/tmp/jl_oWiuuo"

julia> t1 = tempname(d1)
"/tmp/jl_oWiuuo/jl_AOblx7"

julia> dirname(t1)
"/tmp/jl_oWiuuo"

julia> dirname(t1) == d1
true

julia> ENV["TMPDIR"] = joinpath(mktempdir(), "my_custom_tmpdir")
"/tmp/jl_hR2Ra5/my_custom_tmpdir"

julia> mkpath(ENV["TMPDIR"])
"/tmp/jl_hR2Ra5/my_custom_tmpdir"

julia> d2 = mktempdir()
"/tmp/jl_hR2Ra5/my_custom_tmpdir/jl_tuYj5d"

julia> t2 = tempname(d2)
"/tmp/jl_hR2Ra5/my_custom_tmpdir/jl_qhfofs"

julia> dirname(t2)
"/tmp/jl_hR2Ra5/my_custom_tmpdir"

julia> dirname(t2) == d2
false

julia> delete!(ENV, "TMPDIR");

julia> d3 = mktempdir()
"/tmp/jl_9qlOId"

julia> t3 = tempname(d3)
"/tmp/jl_9qlOId/jl_ewuK8b"

julia> dirname(t3)
"/tmp/jl_9qlOId"

julia> dirname(t3) == d3
true
@KristofferC
Copy link
Member

Dup of #35785 (and #38873).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
filesystem Underlying file system and functions that use it system:linux Affects only Linux
Projects
None yet
Development

No branches or pull requests

2 participants