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

mktemp -t foo.XXXX should create in TMPDIR #4832

Merged
merged 2 commits into from
May 18, 2023
Merged

Conversation

sylvestre
Copy link
Contributor

closes: #4821

Copy link
Contributor

@cakebaker cakebaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the PR is incomplete because mktemp -t -p ~/projects/playground foo.XXXX doesn't work as expected if $TMPDIR is not set: it creates the file in /tmp instead of ~/projects/playground.

From the GNU mktemp documentation:

-t interpret TEMPLATE as a single file name component,
relative to a directory: $TMPDIR, if set; else the
directory specified via -p; else /tmp [deprecated]

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/tail-2/inotify-dir-recreate. tests/tail-2/inotify-dir-recreate is passing on 'main'. Maybe you have to rebase?

Copy link
Contributor

@cakebaker cakebaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not quite complete yet ;-)

With GNU mktemp:

$ TMPDIR=dir_a mktemp -t -p dir_b foo.XXXX
dir_a/foo.CnlA

With uutils mktemp:

$ TMPDIR=dir_a cargo run mktemp -t -p dir_b foo.XXXX
dir_b/foo.DAXt

@sylvestre
Copy link
Contributor Author

sure but afaik, i didn't regress this issue :)

@cakebaker
Copy link
Contributor

Ah no, it's not a regression, I just didn't test this variant in my first review :)

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/misc/mktemp. tests/misc/mktemp is passing on 'main'. Maybe you have to rebase?

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/misc/mktemp. tests/misc/mktemp is passing on 'main'. Maybe you have to rebase?

Comment on lines 196 to 197
// Ignore TMPDIR when it's set to "."
if tmpdir_env == "." {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you ignore .? GNU mktemp accepts it:

$ TMPDIR=. mktemp -t -p dir_b foo.XXXX
./foo.6Nai

@@ -191,7 +191,22 @@ impl Options {
(tmpdir, template.to_string())
}
Some(template) => {
let tmpdir = matches.get_one::<String>(OPT_TMPDIR).map(String::from);
let tmpdir = if let Ok(tmpdir_env) = env::var("TMPDIR") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need an additional condition here. It currently breaks the GNU tests because GNU mktemp ignores TMPDIR in the following case:

$ TMPDIR=dir_a mktemp foo.XXXX
foo.fgPS

@sylvestre
Copy link
Contributor Author

this is why i would have prefer to land the previous commit as i didn't introduce a regression ;)

@sylvestre
Copy link
Contributor Author

I removed the last patch of the stack

It doesn't fix
$ TMPDIR=dir_a cargo run mktemp -t -p dir_b foo.XXXX
but as it isn't a regression, i will open a new issue to make sure we don't lose it

@cakebaker
Copy link
Contributor

Sorry, I misunderstood what you meant with "regression" :|

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/misc/seq-long-double. tests/misc/seq-long-double is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/tail-2/inotify-dir-recreate. tests/tail-2/inotify-dir-recreate is passing on 'main'. Maybe you have to rebase?

@sylvestre
Copy link
Contributor Author

yeah, sorry :) i use that word every day at Mozilla :)

By regression, i meant that this current PR is still an improvement over the current main. Even if it isn't perfect as you noticed :)

@cakebaker cakebaker merged commit 74e73be into uutils:main May 18, 2023
@sylvestre sylvestre deleted the issue_4821 branch May 18, 2023 13:31
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.

mktemp: incompatibility between coreutils, BSD (file created in current directory)
2 participants