1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

mktemp: correct error message on absolute path

Correct the error message produced by `mktemp` when `--tmpdir` is
given and the template is an absolute path:

    $ mktemp --tmpdir=a /XXX
    mktemp: invalid template, '/XXX'; with --tmpdir, it may not be absolute
This commit is contained in:
Jeffrey Finkelstein 2022-05-11 22:31:09 -04:00
parent d894847fc6
commit 8a941db20a
2 changed files with 21 additions and 3 deletions

View file

@ -414,6 +414,22 @@ fn test_mktemp_directory_tmpdir() {
assert!(PathBuf::from(result.stdout_str().trim()).is_dir());
}
/// Test that an absolute path is disallowed when --tmpdir is provided.
#[test]
fn test_tmpdir_absolute_path() {
#[cfg(windows)]
let path = r"C:\XXX";
#[cfg(not(windows))]
let path = "/XXX";
new_ucmd!()
.args(&["--tmpdir=a", path])
.fails()
.stderr_only(format!(
"mktemp: invalid template, '{}'; with --tmpdir, it may not be absolute\n",
path
));
}
/// Decide whether a string matches a given template.
///
/// In the template, the character `'X'` is treated as a wildcard,