Skip to content

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

@DilumAluthge

Description

@DilumAluthge

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    filesystemUnderlying file system and functions that use itsystem:linuxAffects only Linux

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions