uutils / coreutils

Cross-platform Rust rewrite of the GNU coreutils
https://uutils.github.io/
MIT License
17.62k stars 1.27k forks source link

`mktemp`: inconsistency between Windows and Unix #5042

Open tertsdiepraam opened 1 year ago

tertsdiepraam commented 1 year ago

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:

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?

tertsdiepraam commented 1 year ago

I think this touches on a larger question about the direction of the project on Windows. Which is: should we follow GNU or Windows conventions?

Following GNU conventions gives us more compatibility with ourselves on different platforms, but following Windows conventions gives us more compatibility with other Windows utilities.

Personally, I'm leaning towards following GNU, because the promise that you can take any script using uutils and run it without problems on any supported platform is really useful.

ongun-kanat commented 1 year ago

I think this specific issue can be solved with a compromise.

So I'll propose something like 2 but a predictable fallback. If TMPDIR is defined use it, which will make it consistent with the GNU and enables cross-platform operation, otherwise pull the temp directory from std::env::tmp_dir which will make Windows applications happy.

tertsdiepraam commented 1 year ago

Sounds good!