Skip to content

Support for $TMPDIR.#643

Merged
MatthewFluet merged 1 commit intoMLton:masterfrom
Skyb0rg007:tmpfile-tmpdir
Feb 12, 2026
Merged

Support for $TMPDIR.#643
MatthewFluet merged 1 commit intoMLton:masterfrom
Skyb0rg007:tmpfile-tmpdir

Conversation

@Skyb0rg007
Copy link
Contributor

Modifies tempPrefix to first try to use the $TMPDIR environment variable. It only uses the $TMPDIR location if the path is absolute, canonical, and already exists as a directory.

This set of checks is based on the code in systemd here.

Considerations

Languages such as Python also check TEMP, TMP, and more locations: docs. It also performs the existence checks to the hardcoded locations, so if /tmp doesn't exist it can fallback to /var/tmp. I don't think this is a big deal: if a program wants to they can use the mkstemps function themselves.

Python caches the temporary directory check, so it doesn't call isDir every time. I don't think this is a meaningful cost since there's only one directory to check.

Rust uses confstr(_CS_DARWIN_USER_TEMP_DIR) to determine the temporary directory on Darwin: link. This isn't implemented here.

Feel free to modify the code if those mentioned options are appealing.

Closes #642.

Modifies tempPrefix to first use the $TMPDIR environment variable.
It only uses the $TMPDIR location if the path is absolute,
canonical, and already exists as a directory.

Closes MLton#642.
@MatthewFluet
Copy link
Member

Looks fine to me. Thanks.

@MatthewFluet MatthewFluet merged commit b495cc9 into MLton:master Feb 12, 2026
22 checks passed
@Skyb0rg007 Skyb0rg007 deleted the tmpfile-tmpdir branch February 12, 2026 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OS.FileSys.tmpName should respect $TMPDIR.

2 participants