mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
Merge pull request #3599 from jfinkels/mktemp-suffix-empty-string
mktemp: error on empty --suffix in some situations
This commit is contained in:
commit
5f999e9d92
2 changed files with 27 additions and 3 deletions
|
@ -224,6 +224,11 @@ fn find_last_contiguous_block_of_xs(s: &str) -> Option<(usize, usize)> {
|
|||
|
||||
impl Params {
|
||||
fn from(options: Options) -> Result<Self, MkTempError> {
|
||||
// The template argument must end in 'X' if a suffix option is given.
|
||||
if options.suffix.is_some() && !options.template.ends_with('X') {
|
||||
return Err(MkTempError::MustEndInX(options.template));
|
||||
}
|
||||
|
||||
// Get the start and end indices of the randomized part of the template.
|
||||
//
|
||||
// For example, if the template is "abcXXXXyz", then `i` is 3 and `j` is 7.
|
||||
|
@ -285,9 +290,6 @@ impl Params {
|
|||
if suffix.contains(MAIN_SEPARATOR) {
|
||||
return Err(MkTempError::SuffixContainsDirSeparator(suffix));
|
||||
}
|
||||
if !suffix_from_template.is_empty() && !suffix_from_option.is_empty() {
|
||||
return Err(MkTempError::MustEndInX(options.template));
|
||||
}
|
||||
|
||||
// The number of random characters in the template.
|
||||
//
|
||||
|
|
|
@ -619,3 +619,25 @@ fn test_three_contiguous_wildcard_blocks() {
|
|||
assert_matches_template!(template, filename);
|
||||
assert!(at.file_exists(filename));
|
||||
}
|
||||
|
||||
/// Test that template must end in X even if `--suffix` is the empty string.
|
||||
#[test]
|
||||
fn test_suffix_must_end_in_x() {
|
||||
new_ucmd!()
|
||||
.args(&["--suffix=", "aXXXb"])
|
||||
.fails()
|
||||
.stderr_is("mktemp: with --suffix, template 'aXXXb' must end in X\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_suffix_empty_template() {
|
||||
new_ucmd!()
|
||||
.args(&["--suffix=aXXXb", ""])
|
||||
.fails()
|
||||
.stderr_is("mktemp: with --suffix, template '' must end in X\n");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["-d", "--suffix=aXXXb", ""])
|
||||
.fails()
|
||||
.stderr_is("mktemp: with --suffix, template '' must end in X\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue