Skip to content

Commit

Permalink
mktemp -t foo.XXXX should create in TMPDIR
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed May 5, 2023
1 parent 4ee1118 commit a4467b5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/uu/mktemp/src/mktemp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,12 @@ impl Options {
(tmpdir, template.to_string())
}
Some(template) => {
let tmpdir = matches.get_one::<String>(OPT_TMPDIR).map(String::from);
let tmpdir = if matches.get_flag(OPT_T) {
// mktemp -t foo.xxx should export in TMPDIR
Some(env::temp_dir().display().to_string())
} else {
matches.get_one::<String>(OPT_TMPDIR).map(String::from)
};
(tmpdir, template.to_string())
}
}
Expand Down
15 changes: 15 additions & 0 deletions tests/by-util/test_mktemp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,3 +857,18 @@ fn test_default_missing_value() {
let scene = TestScenario::new(util_name!());
scene.ucmd().arg("-d").arg("--tmpdir").succeeds();
}

#[test]
fn test_default_issue_4821_t_tmpdir() {
let scene = TestScenario::new(util_name!());
let pathname = scene.fixtures.as_string();
let result = scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("-t")
.arg("foo.XXXX")
.succeeds();
let stdout = result.stdout_str();
println!("stdout = {stdout}");
assert!(stdout.contains(&pathname));
}

0 comments on commit a4467b5

Please sign in to comment.