-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
mktemp: respect TMPDIR environment variable #3552
Conversation
On windows:
|
ff3cae3
to
60ef369
Compare
Thanks, I hope that is fixed now. |
Nope, I still have an issue on Windows. I'll look into it later. |
224facf
to
27d57db
Compare
Something strange is happening with the
However, when I run the command myself, it seems to work as expected: $ ./target/release/mktemp bar.XXXX
bar.xXFS For some reason, the GNU test suite incorrectly thinks that the environment variable |
Correct me if I'm wrong, but I think it has something to do with the default value of the tmpdir. It seems like you're using the current directory as a fallback for when TMPDIR is missing, but the GNU docs state:
|
That quote seems to be from the description of the |
I see, it mentioned somewhere that a value of |
I created this file named #!/bin/sh
. "${srcdir=.}/tests/init.sh";
echo TMPDIR=$TMPDIR
Exit 1 and then I ran it with bash util/run-gnu-test.sh tests/misc/printtmpdir.sh and I got the following output
But printing the same environment variable as its own command gives $ echo TMPDIR=$TMPDIR
TMPDIR= This is more evidence that the |
Not sure about being unset, but they seem to set it explicitly in the # Note that the first lines are statements. They ensure that environment
# variables that can perturb tests are unset or set to expected values.
# The rest are envvar settings that propagate build-related Makefile
# variables to test scripts.
TESTS_ENVIRONMENT = \
. $(srcdir)/tests/lang-default; \
tmp__=$${TMPDIR-/tmp}; \
test -d "$$tmp__" && test -w "$$tmp__" || tmp__=.; \
. $(srcdir)/tests/envvar-check; \
TMPDIR=$$tmp__; export TMPDIR; \ |
Hm, but the test cases in |
Okay, I did some more tests. First, I checked any other places where (cargo commands are this PR) ❯ echo $TMPDIR
❯ cargo run --quiet -- bar.XXXX
bar.NVKh
❯ mktemp bar.XXXX
bar.lfXc
❯ TMPDIR=/tmp cargo run --quiet -- bar.XXXX
/tmp/bar.HCS6
❯ TMPDIR=/tmp mktemp bar.XXXX
bar.sgDY So, the test case actually doesn't care whether |
Okay, so I think the unit test that I wrote is incorrect, and I misunderstood how the environment variable interacts with the arguments. It's confusing! The documentation states "If TEMPLATE is not specified, use tmp.XXXXXXXXXX, and --tmpdir is implied." So in other words, $ mkdir d
$ TMPDIR=d mktemp
d/tmp.dhHS99qWsq
$ TMPDIR=d mktemp --tmpdir
d/tmp.KaKXYFfaUK
$ TMPDIR=d mktemp XXX
bAw
$ TMPDIR=d mktemp --tmpdir XXX
d/DSC I'll adjust the code on this branch to reflect that. |
27d57db
to
6cb3e6a
Compare
6cb3e6a
to
9ff62e3
Compare
I've updated this pull request with a new implementation and some new unit tests to match the intended behavior. However, now I'm facing a failure on Windows that I'm not able to diagnose:
|
c5aa9f5
to
e736754
Compare
I've looked into it, so it seems The function
So I guess we need to say that in Windows it prints an absolute path. I didn't find a good way to learn if the variable that this path was taken from contains absolute path or relative path. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Windows fails with:
---- test_mktemp::test_tmpdir_env_var stdout ----
current_directory_resolved:
run: D:\a\coreutils\coreutils\target\i686-pc-windows-msvc\debug\coreutils.exe mktemp
thread 'test_mktemp::test_tmpdir_env_var' panicked at '".\tmp.XXXXXXXXXX" != "C:\Users\RUNNER~1\AppData\Local\Temp\.tmpZJDV1L\tmp.knQR5r5wmV"', D:\a\coreutils\coreutils\tests\by-util\test_mktemp.rs:653:5
44729f2
to
7e41b0e
Compare
fb82c02
to
6b4a211
Compare
Okay, I got the tests to pass on Windows by relaxing the assertion so that it just checks that the filename printed to stdout ends with the template. |
Change `mktemp` so that it respects the value of the `TMPDIR` environment variable if no directory is otherwise specified in its arguments. For example, before this commit $ TMPDIR=. mktemp /tmp/tmp.WDJ66MaS1T After this commit, $ TMPDIR=. mktemp ./tmp.h96VZBhv8P This matches the behavior of GNU `mktemp`.
6b4a211
to
61345cb
Compare
Change
mktemp
so that it respects the value of theTMPDIR
environment variable, if no directory is otherwise specified in its
arguments. For example, before this commit
After this commit,
This matches the behavior of GNU
mktemp
.