uutils / uutils/coreutils

`mktemp`: inconsistency between Windows and Unix

Open
#5,042 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - mktemp wontfix
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

mktemp uses env::temp_dir to get the default temporary directory. The behaviour of this function is different between platforms, which is confusing for writing cross-platforms scripts (which is supposed to be a strength of uutils!).

Here's what's different:

  • On Windows, TMPDIR is ignored.
  • On Unix TMP, TEMP and USERPROFILE are ignored.
  • On Unix, if TMPDIR is a relative path, a relative path is printed.

So we have a couple of options.

  1. Make Windows behave like Unix, which means copying the code from std::env::temp_dir from Unix. This makes it consistent, but a bit weird on Windows, because we ignore standard environment variables.
  2. Add a manual check for TMPDIR to the Windows implementation. This helps consistency, but then Unix does not behave like Windows.
  3. Add all variables to both Unix and Windows (at least TMPDIR, TMP & TEMP). This is consistent between platforms, but not consistent with GNU.

Any opinions on this?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating mktemp's use of env::temp_dir and the platform-specific temporary-directory implementations. Compare the Windows and Unix environment-variable behavior described in the issue, then review the discussion to identify an agreed direction. Done requires a decided cross-platform behavior and tests covering the relevant variables and relative paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, operating-systems
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.