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

Remark TMP, TEMP and USERPROFILE env vars can influence env::temp_dir on Windows #125439

Open
jieyouxu opened this issue May 23, 2024 · 1 comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. O-windows Operating system: Windows T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@jieyouxu
Copy link
Member

Location

Summary

Encountered in #122580 (comment).

In codegen we (transitively) use env::temp_dir() for some temporary files. If you unset (or provide a value that is not a writable directory) all three TMP, TEMP, USERPROFILE env vars (such as by calling Command::env_clear on some cargo invocation) on Windows, then env::temp_dir() can return the Windows directory which is often not writable.

This is documented in GetTempPath2W, but it might be worth a remark on the docs for env::temp_dir and Command::env_clear that modifying or unsetting TMP, TEMP and USERPROFILE can influence the result of env::temp_dir on Windows.

It is already pointed out that env::temp_dir returns value of TMPDIR on Linux.

@jieyouxu jieyouxu added O-windows Operating system: Windows C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools labels May 23, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 23, 2024
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 23, 2024
@ChrisDenton
Copy link
Member

A more general remark to add is that std does not check the returned path in any way. On any platform there's always the risk it might not be writeable by the current application. It might not even exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. O-windows Operating system: Windows T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants