mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
Fix clippy::uninlined_format_args .
This commit is contained in:
parent
5d986bfb4c
commit
353eb53367
39 changed files with 127 additions and 169 deletions
|
@ -168,13 +168,13 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
print!("{}", before_filename);
|
print!("{before_filename}");
|
||||||
if should_print_filename {
|
if should_print_filename {
|
||||||
// The filename might not be valid UTF-8, and filename.display() would mangle the names.
|
// The filename might not be valid UTF-8, and filename.display() would mangle the names.
|
||||||
// Therefore, emit the bytes directly to stdout, without any attempt at encoding them.
|
// Therefore, emit the bytes directly to stdout, without any attempt at encoding them.
|
||||||
let _dropped_result = stdout().write_all(os_str_as_bytes(filename.as_os_str())?);
|
let _dropped_result = stdout().write_all(os_str_as_bytes(filename.as_os_str())?);
|
||||||
}
|
}
|
||||||
println!("{}", after_filename);
|
println!("{after_filename}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -175,7 +175,7 @@ impl Entry {
|
||||||
let source_is_dir = direntry.path().is_dir();
|
let source_is_dir = direntry.path().is_dir();
|
||||||
if path_ends_with_terminator(context.target) && source_is_dir {
|
if path_ends_with_terminator(context.target) && source_is_dir {
|
||||||
if let Err(e) = std::fs::create_dir_all(context.target) {
|
if let Err(e) = std::fs::create_dir_all(context.target) {
|
||||||
eprintln!("Failed to create directory: {}", e);
|
eprintln!("Failed to create directory: {e}");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
descendant = descendant.strip_prefix(context.root)?.to_path_buf();
|
descendant = descendant.strip_prefix(context.root)?.to_path_buf();
|
||||||
|
|
|
@ -237,7 +237,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
None => {
|
None => {
|
||||||
return Err(USimpleError::new(
|
return Err(USimpleError::new(
|
||||||
1,
|
1,
|
||||||
format!("invalid date {}", relative_time),
|
format!("invalid date {relative_time}"),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -444,7 +444,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
None => {
|
None => {
|
||||||
let filesystems = get_all_filesystems(&opt).map_err(|e| {
|
let filesystems = get_all_filesystems(&opt).map_err(|e| {
|
||||||
let context = "cannot read table of mounted file systems";
|
let context = "cannot read table of mounted file systems";
|
||||||
USimpleError::new(e.code(), format!("{}: {}", context, e))
|
USimpleError::new(e.code(), format!("{context}: {e}"))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if filesystems.is_empty() {
|
if filesystems.is_empty() {
|
||||||
|
@ -457,7 +457,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let paths: Vec<_> = paths.collect();
|
let paths: Vec<_> = paths.collect();
|
||||||
let filesystems = get_named_filesystems(&paths, &opt).map_err(|e| {
|
let filesystems = get_named_filesystems(&paths, &opt).map_err(|e| {
|
||||||
let context = "cannot read table of mounted file systems";
|
let context = "cannot read table of mounted file systems";
|
||||||
USimpleError::new(e.code(), format!("{}: {}", context, e))
|
USimpleError::new(e.code(), format!("{context}: {e}"))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
// This can happen if paths are given as command-line arguments
|
// This can happen if paths are given as command-line arguments
|
||||||
|
|
|
@ -78,14 +78,14 @@ pub fn generate_type_output(fmt: &OutputFmt) -> String {
|
||||||
match fmt {
|
match fmt {
|
||||||
OutputFmt::Display => FILE_TYPES
|
OutputFmt::Display => FILE_TYPES
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&(_, key, val)| format!("\x1b[{}m{}\t{}\x1b[0m", val, key, val))
|
.map(|&(_, key, val)| format!("\x1b[{val}m{key}\t{val}\x1b[0m"))
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("\n"),
|
.join("\n"),
|
||||||
_ => {
|
_ => {
|
||||||
// Existing logic for other formats
|
// Existing logic for other formats
|
||||||
FILE_TYPES
|
FILE_TYPES
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&(_, v1, v2)| format!("{}={}", v1, v2))
|
.map(|&(_, v1, v2)| format!("{v1}={v2}"))
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join(":")
|
.join(":")
|
||||||
}
|
}
|
||||||
|
@ -100,8 +100,7 @@ fn generate_ls_colors(fmt: &OutputFmt, sep: &str) -> String {
|
||||||
display_parts.push(type_output);
|
display_parts.push(type_output);
|
||||||
for &(extension, code) in FILE_COLORS {
|
for &(extension, code) in FILE_COLORS {
|
||||||
let prefix = if extension.starts_with('*') { "" } else { "*" };
|
let prefix = if extension.starts_with('*') { "" } else { "*" };
|
||||||
let formatted_extension =
|
let formatted_extension = format!("\x1b[{code}m{prefix}{extension}\t{code}\x1b[0m");
|
||||||
format!("\x1b[{}m{}{}\t{}\x1b[0m", code, prefix, extension, code);
|
|
||||||
display_parts.push(formatted_extension);
|
display_parts.push(formatted_extension);
|
||||||
}
|
}
|
||||||
display_parts.join("\n")
|
display_parts.join("\n")
|
||||||
|
@ -111,8 +110,8 @@ fn generate_ls_colors(fmt: &OutputFmt, sep: &str) -> String {
|
||||||
let mut parts = vec![];
|
let mut parts = vec![];
|
||||||
for &(extension, code) in FILE_COLORS {
|
for &(extension, code) in FILE_COLORS {
|
||||||
let prefix = if extension.starts_with('*') { "" } else { "*" };
|
let prefix = if extension.starts_with('*') { "" } else { "*" };
|
||||||
let formatted_extension = format!("{}{}", prefix, extension);
|
let formatted_extension = format!("{prefix}{extension}");
|
||||||
parts.push(format!("{}={}", formatted_extension, code));
|
parts.push(format!("{formatted_extension}={code}"));
|
||||||
}
|
}
|
||||||
let (prefix, suffix) = get_colors_format_strings(fmt);
|
let (prefix, suffix) = get_colors_format_strings(fmt);
|
||||||
let ls_colors = parts.join(sep);
|
let ls_colors = parts.join(sep);
|
||||||
|
@ -493,7 +492,7 @@ pub fn generate_dircolors_config() -> String {
|
||||||
);
|
);
|
||||||
config.push_str("COLORTERM ?*\n");
|
config.push_str("COLORTERM ?*\n");
|
||||||
for term in TERMS {
|
for term in TERMS {
|
||||||
config.push_str(&format!("TERM {}\n", term));
|
config.push_str(&format!("TERM {term}\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
config.push_str(
|
config.push_str(
|
||||||
|
@ -514,14 +513,14 @@ pub fn generate_dircolors_config() -> String {
|
||||||
);
|
);
|
||||||
|
|
||||||
for (name, _, code) in FILE_TYPES {
|
for (name, _, code) in FILE_TYPES {
|
||||||
config.push_str(&format!("{} {}\n", name, code));
|
config.push_str(&format!("{name} {code}\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
config.push_str("# List any file extensions like '.gz' or '.tar' that you would like ls\n");
|
config.push_str("# List any file extensions like '.gz' or '.tar' that you would like ls\n");
|
||||||
config.push_str("# to color below. Put the extension, a space, and the color init string.\n");
|
config.push_str("# to color below. Put the extension, a space, and the color init string.\n");
|
||||||
|
|
||||||
for (ext, color) in FILE_COLORS {
|
for (ext, color) in FILE_COLORS {
|
||||||
config.push_str(&format!("{} {}\n", ext, color));
|
config.push_str(&format!("{ext} {color}\n"));
|
||||||
}
|
}
|
||||||
config.push_str("# Subsequent TERM or COLORTERM entries, can be used to add / override\n");
|
config.push_str("# Subsequent TERM or COLORTERM entries, can be used to add / override\n");
|
||||||
config.push_str("# config specific to those matching environment variables.");
|
config.push_str("# config specific to those matching environment variables.");
|
||||||
|
|
|
@ -594,7 +594,7 @@ fn read_files_from(file_name: &str) -> Result<Vec<PathBuf>, std::io::Error> {
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
return Err(std::io::Error::new(
|
return Err(std::io::Error::new(
|
||||||
std::io::ErrorKind::Other,
|
std::io::ErrorKind::Other,
|
||||||
format!("{}: read error: Is a directory", file_name),
|
format!("{file_name}: read error: Is a directory"),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,10 +604,7 @@ fn read_files_from(file_name: &str) -> Result<Vec<PathBuf>, std::io::Error> {
|
||||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
|
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
|
||||||
return Err(std::io::Error::new(
|
return Err(std::io::Error::new(
|
||||||
std::io::ErrorKind::Other,
|
std::io::ErrorKind::Other,
|
||||||
format!(
|
format!("cannot open '{file_name}' for reading: No such file or directory"),
|
||||||
"cannot open '{}' for reading: No such file or directory",
|
|
||||||
file_name
|
|
||||||
),
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
|
|
10
src/uu/env/src/env.rs
vendored
10
src/uu/env/src/env.rs
vendored
|
@ -65,7 +65,7 @@ fn print_env(line_ending: LineEnding) {
|
||||||
let stdout_raw = io::stdout();
|
let stdout_raw = io::stdout();
|
||||||
let mut stdout = stdout_raw.lock();
|
let mut stdout = stdout_raw.lock();
|
||||||
for (n, v) in env::vars() {
|
for (n, v) in env::vars() {
|
||||||
write!(stdout, "{}={}{}", n, v, line_ending).unwrap();
|
write!(stdout, "{n}={v}{line_ending}").unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,15 +281,15 @@ pub fn parse_args_from_str(text: &NativeIntStr) -> UResult<Vec<NativeIntString>>
|
||||||
USimpleError::new(125, "invalid backslash at end of string in -S")
|
USimpleError::new(125, "invalid backslash at end of string in -S")
|
||||||
}
|
}
|
||||||
parse_error::ParseError::InvalidSequenceBackslashXInMinusS { pos: _, c } => {
|
parse_error::ParseError::InvalidSequenceBackslashXInMinusS { pos: _, c } => {
|
||||||
USimpleError::new(125, format!("invalid sequence '\\{}' in -S", c))
|
USimpleError::new(125, format!("invalid sequence '\\{c}' in -S"))
|
||||||
}
|
}
|
||||||
parse_error::ParseError::MissingClosingQuote { pos: _, c: _ } => {
|
parse_error::ParseError::MissingClosingQuote { pos: _, c: _ } => {
|
||||||
USimpleError::new(125, "no terminating quote in -S string")
|
USimpleError::new(125, "no terminating quote in -S string")
|
||||||
}
|
}
|
||||||
parse_error::ParseError::ParsingOfVariableNameFailed { pos, msg } => {
|
parse_error::ParseError::ParsingOfVariableNameFailed { pos, msg } => {
|
||||||
USimpleError::new(125, format!("variable name issue (at {}): {}", pos, msg,))
|
USimpleError::new(125, format!("variable name issue (at {pos}): {msg}",))
|
||||||
}
|
}
|
||||||
_ => USimpleError::new(125, format!("Error: {:?}", e)),
|
_ => USimpleError::new(125, format!("Error: {e:?}")),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,7 +393,7 @@ impl EnvAppData {
|
||||||
| clap::error::ErrorKind::DisplayVersion => e.into(),
|
| clap::error::ErrorKind::DisplayVersion => e.into(),
|
||||||
_ => {
|
_ => {
|
||||||
// extent any real issue with parameter parsing by the ERROR_MSG_S_SHEBANG
|
// extent any real issue with parameter parsing by the ERROR_MSG_S_SHEBANG
|
||||||
let s = format!("{}", e);
|
let s = format!("{e}");
|
||||||
if !s.is_empty() {
|
if !s.is_empty() {
|
||||||
let s = s.trim_end();
|
let s = s.trim_end();
|
||||||
uucore::show_error!("{}", s);
|
uucore::show_error!("{}", s);
|
||||||
|
|
2
src/uu/env/src/parse_error.rs
vendored
2
src/uu/env/src/parse_error.rs
vendored
|
@ -39,7 +39,7 @@ pub enum ParseError {
|
||||||
|
|
||||||
impl fmt::Display for ParseError {
|
impl fmt::Display for ParseError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
f.write_str(format!("{:?}", self).as_str())
|
f.write_str(format!("{self:?}").as_str())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
src/uu/env/src/variable_parser.rs
vendored
4
src/uu/env/src/variable_parser.rs
vendored
|
@ -21,7 +21,7 @@ impl<'a, 'b> VariableParser<'a, 'b> {
|
||||||
if c.is_ascii_digit() {
|
if c.is_ascii_digit() {
|
||||||
return Err(ParseError::ParsingOfVariableNameFailed {
|
return Err(ParseError::ParsingOfVariableNameFailed {
|
||||||
pos: self.parser.get_peek_position(),
|
pos: self.parser.get_peek_position(),
|
||||||
msg: format!("Unexpected character: '{}', expected variable name must not start with 0..9", c) });
|
msg: format!("Unexpected character: '{c}', expected variable name must not start with 0..9") });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -79,7 +79,7 @@ impl<'a, 'b> VariableParser<'a, 'b> {
|
||||||
Some(c) => {
|
Some(c) => {
|
||||||
return Err(ParseError::ParsingOfVariableNameFailed {
|
return Err(ParseError::ParsingOfVariableNameFailed {
|
||||||
pos: self.parser.get_peek_position(),
|
pos: self.parser.get_peek_position(),
|
||||||
msg: format!("Unexpected character: '{}', expected a closing brace ('}}') or colon (':')", c)
|
msg: format!("Unexpected character: '{c}', expected a closing brace ('}}') or colon (':')")
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -139,7 +139,7 @@ impl StringOp {
|
||||||
Self::Match => {
|
Self::Match => {
|
||||||
let left = left.eval()?.eval_as_string();
|
let left = left.eval()?.eval_as_string();
|
||||||
let right = right.eval()?.eval_as_string();
|
let right = right.eval()?.eval_as_string();
|
||||||
let re_string = format!("^{}", right);
|
let re_string = format!("^{right}");
|
||||||
let re = Regex::with_options(
|
let re = Regex::with_options(
|
||||||
&re_string,
|
&re_string,
|
||||||
RegexOptions::REGEX_OPTION_NONE,
|
RegexOptions::REGEX_OPTION_NONE,
|
||||||
|
|
|
@ -66,12 +66,12 @@ fn write_result(
|
||||||
for (factor, n) in factorization {
|
for (factor, n) in factorization {
|
||||||
if print_exponents {
|
if print_exponents {
|
||||||
if n > 1 {
|
if n > 1 {
|
||||||
write!(w, " {}^{}", factor, n)?;
|
write!(w, " {factor}^{n}")?;
|
||||||
} else {
|
} else {
|
||||||
write!(w, " {}", factor)?;
|
write!(w, " {factor}")?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
w.write_all(format!(" {}", factor).repeat(n).as_bytes())?;
|
w.write_all(format!(" {factor}").repeat(n).as_bytes())?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writeln!(w)?;
|
writeln!(w)?;
|
||||||
|
|
|
@ -129,7 +129,7 @@ impl FmtOptions {
|
||||||
if width > MAX_WIDTH {
|
if width > MAX_WIDTH {
|
||||||
return Err(USimpleError::new(
|
return Err(USimpleError::new(
|
||||||
1,
|
1,
|
||||||
format!("invalid width: '{}': Numerical result out of range", width),
|
format!("invalid width: '{width}': Numerical result out of range"),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@ fn extract_files(matches: &ArgMatches) -> UResult<Vec<String>> {
|
||||||
} else {
|
} else {
|
||||||
let first_num = x.chars().nth(1).expect("a negative number should be at least two characters long");
|
let first_num = x.chars().nth(1).expect("a negative number should be at least two characters long");
|
||||||
Some(Err(
|
Some(Err(
|
||||||
UUsageError::new(1, format!("invalid option -- {}; -WIDTH is recognized only when it is the first\noption; use -w N instead", first_num))
|
UUsageError::new(1, format!("invalid option -- {first_num}; -WIDTH is recognized only when it is the first\noption; use -w N instead"))
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -158,7 +158,7 @@ fn table() {
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|(_, s)| **s != "EXIT")
|
.filter(|(_, s)| **s != "EXIT")
|
||||||
{
|
{
|
||||||
println!("{0: >#2} {1}", idx, signal);
|
println!("{idx: >#2} {signal}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,9 +122,9 @@ pub fn print_dired_output(
|
||||||
|
|
||||||
/// Helper function to print positions with a given prefix.
|
/// Helper function to print positions with a given prefix.
|
||||||
fn print_positions(prefix: &str, positions: &Vec<BytePosition>) {
|
fn print_positions(prefix: &str, positions: &Vec<BytePosition>) {
|
||||||
print!("{}", prefix);
|
print!("{prefix}");
|
||||||
for c in positions {
|
for c in positions {
|
||||||
print!(" {}", c);
|
print!(" {c}");
|
||||||
}
|
}
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2040,7 +2040,7 @@ fn show_dir_name(path_data: &PathData, out: &mut BufWriter<Stdout>, config: &Con
|
||||||
if config.hyperlink && !config.dired {
|
if config.hyperlink && !config.dired {
|
||||||
let name = escape_name(path_data.p_buf.as_os_str(), &config.quoting_style);
|
let name = escape_name(path_data.p_buf.as_os_str(), &config.quoting_style);
|
||||||
let hyperlink = create_hyperlink(&name, path_data);
|
let hyperlink = create_hyperlink(&name, path_data);
|
||||||
write!(out, "{}:", hyperlink).unwrap();
|
write!(out, "{hyperlink}:").unwrap();
|
||||||
} else {
|
} else {
|
||||||
write!(out, "{}:", path_data.p_buf.display()).unwrap();
|
write!(out, "{}:", path_data.p_buf.display()).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -2091,7 +2091,7 @@ pub fn list(locs: Vec<&Path>, config: &Config) -> UResult<()> {
|
||||||
// color is given
|
// color is given
|
||||||
if style_manager.get_normal_style().is_some() {
|
if style_manager.get_normal_style().is_some() {
|
||||||
let to_write = style_manager.reset(true);
|
let to_write = style_manager.reset(true);
|
||||||
write!(out, "{}", to_write)?;
|
write!(out, "{to_write}")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2574,7 +2574,7 @@ fn display_items(
|
||||||
Format::Commas => {
|
Format::Commas => {
|
||||||
let mut current_col = 0;
|
let mut current_col = 0;
|
||||||
if let Some(name) = names.next() {
|
if let Some(name) = names.next() {
|
||||||
write!(out, "{}", name)?;
|
write!(out, "{name}")?;
|
||||||
current_col = ansi_width(&name) as u16 + 2;
|
current_col = ansi_width(&name) as u16 + 2;
|
||||||
}
|
}
|
||||||
for name in names {
|
for name in names {
|
||||||
|
@ -2582,10 +2582,10 @@ fn display_items(
|
||||||
// If the width is 0 we print one single line
|
// If the width is 0 we print one single line
|
||||||
if config.width != 0 && current_col + name_width + 1 > config.width {
|
if config.width != 0 && current_col + name_width + 1 > config.width {
|
||||||
current_col = name_width + 2;
|
current_col = name_width + 2;
|
||||||
write!(out, ",\n{}", name)?;
|
write!(out, ",\n{name}")?;
|
||||||
} else {
|
} else {
|
||||||
current_col += name_width + 2;
|
current_col += name_width + 2;
|
||||||
write!(out, ", {}", name)?;
|
write!(out, ", {name}")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Current col is never zero again if names have been printed.
|
// Current col is never zero again if names have been printed.
|
||||||
|
@ -2855,7 +2855,7 @@ fn display_item_long(
|
||||||
);
|
);
|
||||||
|
|
||||||
let displayed_item = if quoted && !item_name.starts_with('\'') {
|
let displayed_item = if quoted && !item_name.starts_with('\'') {
|
||||||
format!(" {}", item_name)
|
format!(" {item_name}")
|
||||||
} else {
|
} else {
|
||||||
item_name
|
item_name
|
||||||
};
|
};
|
||||||
|
@ -2969,7 +2969,7 @@ fn display_item_long(
|
||||||
}
|
}
|
||||||
write!(output_display, "{}{}", displayed_item, config.line_ending).unwrap();
|
write!(output_display, "{}{}", displayed_item, config.line_ending).unwrap();
|
||||||
}
|
}
|
||||||
write!(out, "{}", output_display)?;
|
write!(out, "{output_display}")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ fn format_and_handle_validation(input_line: &str, options: &NumfmtOptions) -> UR
|
||||||
}
|
}
|
||||||
InvalidModes::Ignore => {}
|
InvalidModes::Ignore => {}
|
||||||
};
|
};
|
||||||
println!("{}", input_line);
|
println!("{input_line}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -428,8 +428,8 @@ mod tests {
|
||||||
options.header = 0;
|
options.header = 0;
|
||||||
let result = handle_buffer(BufReader::new(mock_buffer), &options)
|
let result = handle_buffer(BufReader::new(mock_buffer), &options)
|
||||||
.expect_err("returned Ok after receiving IO error");
|
.expect_err("returned Ok after receiving IO error");
|
||||||
let result_debug = format!("{:?}", result);
|
let result_debug = format!("{result:?}");
|
||||||
let result_display = format!("{}", result);
|
let result_display = format!("{result}");
|
||||||
assert_eq!(result_debug, "IoError(\"broken pipe\")");
|
assert_eq!(result_debug, "IoError(\"broken pipe\")");
|
||||||
assert_eq!(result_display, "broken pipe");
|
assert_eq!(result_display, "broken pipe");
|
||||||
assert_eq!(result.code(), 1);
|
assert_eq!(result.code(), 1);
|
||||||
|
|
|
@ -111,10 +111,7 @@ fn paste(
|
||||||
if delimiters.ends_with('\\') && !delimiters.ends_with("\\\\") {
|
if delimiters.ends_with('\\') && !delimiters.ends_with("\\\\") {
|
||||||
return Err(USimpleError::new(
|
return Err(USimpleError::new(
|
||||||
1,
|
1,
|
||||||
format!(
|
format!("delimiter list ends with an unescaped backslash: {delimiters}"),
|
||||||
"delimiter list ends with an unescaped backslash: {}",
|
|
||||||
delimiters
|
|
||||||
),
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ impl Drop for FilterWriter {
|
||||||
if return_code != 0 {
|
if return_code != 0 {
|
||||||
show!(USimpleError::new(
|
show!(USimpleError::new(
|
||||||
1,
|
1,
|
||||||
format!("Shell process returned {}", return_code)
|
format!("Shell process returned {return_code}")
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -658,7 +658,7 @@ where
|
||||||
// Most likely continuous/infinite input stream
|
// Most likely continuous/infinite input stream
|
||||||
return Err(io::Error::new(
|
return Err(io::Error::new(
|
||||||
ErrorKind::Other,
|
ErrorKind::Other,
|
||||||
format!("{}: cannot determine input size", input),
|
format!("{input}: cannot determine input size"),
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
// Could be that file size is larger than set read limit
|
// Could be that file size is larger than set read limit
|
||||||
|
@ -684,7 +684,7 @@ where
|
||||||
// to address all possible file types and edge cases
|
// to address all possible file types and edge cases
|
||||||
return Err(io::Error::new(
|
return Err(io::Error::new(
|
||||||
ErrorKind::Other,
|
ErrorKind::Other,
|
||||||
format!("{}: cannot determine file size", input),
|
format!("{input}: cannot determine file size"),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -586,7 +586,7 @@ impl Stater {
|
||||||
let mut mount_list = read_fs_list()
|
let mut mount_list = read_fs_list()
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
let context = "cannot read table of mounted file systems";
|
let context = "cannot read table of mounted file systems";
|
||||||
USimpleError::new(e.code(), format!("{}: {}", context, e))
|
USimpleError::new(e.code(), format!("{context}: {e}"))
|
||||||
})?
|
})?
|
||||||
.iter()
|
.iter()
|
||||||
.map(|mi| mi.mount_dir.clone())
|
.map(|mi| mi.mount_dir.clone())
|
||||||
|
|
|
@ -40,7 +40,7 @@ fn set_buffer(stream: *mut FILE, value: &str) {
|
||||||
let buff_size: usize = match input.parse() {
|
let buff_size: usize = match input.parse() {
|
||||||
Ok(num) => num,
|
Ok(num) => num,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
eprintln!("failed to allocate a {} byte stdio buffer", value);
|
eprintln!("failed to allocate a {value} byte stdio buffer");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,12 +39,10 @@ impl UError for TouchError {}
|
||||||
impl Display for TouchError {
|
impl Display for TouchError {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
match self {
|
match self {
|
||||||
Self::InvalidDateFormat(s) => write!(f, "Unable to parse date: {}", s),
|
Self::InvalidDateFormat(s) => write!(f, "Unable to parse date: {s}"),
|
||||||
Self::InvalidFiletime(time) => write!(
|
Self::InvalidFiletime(time) => {
|
||||||
f,
|
write!(f, "Source has invalid access or modification time: {time}",)
|
||||||
"Source has invalid access or modification time: {}",
|
}
|
||||||
time,
|
|
||||||
),
|
|
||||||
Self::ReferenceFileInaccessible(path, err) => {
|
Self::ReferenceFileInaccessible(path, err) => {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
|
@ -54,9 +52,9 @@ impl Display for TouchError {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Self::WindowsStdoutPathError(code) => {
|
Self::WindowsStdoutPathError(code) => {
|
||||||
write!(f, "GetFinalPathNameByHandleW failed with code {}", code)
|
write!(f, "GetFinalPathNameByHandleW failed with code {code}")
|
||||||
}
|
}
|
||||||
Self::TouchFileError { error, .. } => write!(f, "{}", error),
|
Self::TouchFileError { error, .. } => write!(f, "{error}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -585,8 +585,8 @@ fn parse_timestamp(s: &str) -> UResult<FileTime> {
|
||||||
15 => (YYYYMMDDHHMM_DOT_SS, s.to_owned()),
|
15 => (YYYYMMDDHHMM_DOT_SS, s.to_owned()),
|
||||||
12 => (YYYYMMDDHHMM, s.to_owned()),
|
12 => (YYYYMMDDHHMM, s.to_owned()),
|
||||||
// If we don't add "20", we have insufficient information to parse
|
// If we don't add "20", we have insufficient information to parse
|
||||||
13 => (YYYYMMDDHHMM_DOT_SS, format!("20{}", s)),
|
13 => (YYYYMMDDHHMM_DOT_SS, format!("20{s}")),
|
||||||
10 => (YYYYMMDDHHMM, format!("20{}", s)),
|
10 => (YYYYMMDDHHMM, format!("20{s}")),
|
||||||
11 => (YYYYMMDDHHMM_DOT_SS, format!("{}{}", current_year(), s)),
|
11 => (YYYYMMDDHHMM_DOT_SS, format!("{}{}", current_year(), s)),
|
||||||
8 => (YYYYMMDDHHMM, format!("{}{}", current_year(), s)),
|
8 => (YYYYMMDDHHMM, format!("{}{}", current_year(), s)),
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -766,7 +766,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
Err(TouchError::InvalidFiletime(filetime)) => assert_eq!(filetime, invalid_filetime),
|
Err(TouchError::InvalidFiletime(filetime)) => assert_eq!(filetime, invalid_filetime),
|
||||||
Err(e) => panic!("Expected TouchError::InvalidFiletime, got {}", e),
|
Err(e) => panic!("Expected TouchError::InvalidFiletime, got {e}"),
|
||||||
Ok(_) => panic!("Expected to error with TouchError::InvalidFiletime but succeeded"),
|
Ok(_) => panic!("Expected to error with TouchError::InvalidFiletime but succeeded"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,17 +82,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let op = sets[1].quote();
|
let op = sets[1].quote();
|
||||||
let msg = if sets_len == 2 {
|
let msg = if sets_len == 2 {
|
||||||
format!(
|
format!(
|
||||||
"{} {}\nOnly one string may be given when deleting without squeezing repeats.",
|
"{start} {op}\nOnly one string may be given when deleting without squeezing repeats.",
|
||||||
start, op,
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
format!("{} {}", start, op,)
|
format!("{start} {op}",)
|
||||||
};
|
};
|
||||||
return Err(UUsageError::new(1, msg));
|
return Err(UUsageError::new(1, msg));
|
||||||
}
|
}
|
||||||
if sets_len > 2 {
|
if sets_len > 2 {
|
||||||
let op = sets[2].quote();
|
let op = sets[2].quote();
|
||||||
let msg = format!("{} {}", start, op);
|
let msg = format!("{start} {op}");
|
||||||
return Err(UUsageError::new(1, msg));
|
return Err(UUsageError::new(1, msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
return Err(USimpleError::new(
|
return Err(USimpleError::new(
|
||||||
1,
|
1,
|
||||||
format!("{}: read error: Is a directory", input),
|
format!("{input}: read error: Is a directory"),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
file_buf = File::open(path).map_err_context(|| input.to_string())?;
|
file_buf = File::open(path).map_err_context(|| input.to_string())?;
|
||||||
|
|
|
@ -33,8 +33,7 @@ fn get_long_usage() -> String {
|
||||||
let default_path: &str = OPENBSD_UTMP_FILE;
|
let default_path: &str = OPENBSD_UTMP_FILE;
|
||||||
format!(
|
format!(
|
||||||
"Output who is currently logged in according to FILE.
|
"Output who is currently logged in according to FILE.
|
||||||
If FILE is not specified, use {}. /var/log/wtmp as FILE is common.",
|
If FILE is not specified, use {default_path}. /var/log/wtmp as FILE is common."
|
||||||
default_path
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -323,7 +323,7 @@ fn determine_regex(lines: &[String]) -> Option<(Regex, bool)> {
|
||||||
fn bytes_to_hex(bytes: &[u8]) -> String {
|
fn bytes_to_hex(bytes: &[u8]) -> String {
|
||||||
bytes
|
bytes
|
||||||
.iter()
|
.iter()
|
||||||
.map(|byte| format!("{:02x}", byte))
|
.map(|byte| format!("{byte:02x}"))
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("")
|
.join("")
|
||||||
}
|
}
|
||||||
|
@ -365,10 +365,7 @@ fn get_file_to_check(
|
||||||
match File::open(filename) {
|
match File::open(filename) {
|
||||||
Ok(f) => {
|
Ok(f) => {
|
||||||
if f.metadata().ok()?.is_dir() {
|
if f.metadata().ok()?.is_dir() {
|
||||||
show!(USimpleError::new(
|
show!(USimpleError::new(1, format!("{filename}: Is a directory")));
|
||||||
1,
|
|
||||||
format!("{}: Is a directory", filename)
|
|
||||||
));
|
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(Box::new(f))
|
Some(Box::new(f))
|
||||||
|
@ -378,7 +375,7 @@ fn get_file_to_check(
|
||||||
if !ignore_missing {
|
if !ignore_missing {
|
||||||
// yes, we have both stderr and stdout here
|
// yes, we have both stderr and stdout here
|
||||||
show!(err.map_err_context(|| filename.to_string()));
|
show!(err.map_err_context(|| filename.to_string()));
|
||||||
println!("{}: FAILED open or read", filename);
|
println!("{filename}: FAILED open or read");
|
||||||
}
|
}
|
||||||
res.failed_open_file += 1;
|
res.failed_open_file += 1;
|
||||||
// we could not open the file but we want to continue
|
// we could not open the file but we want to continue
|
||||||
|
|
|
@ -340,7 +340,7 @@ fn format_float_decimal(f: f64, precision: usize, force_decimal: ForceDecimal) -
|
||||||
if precision == 0 && force_decimal == ForceDecimal::Yes {
|
if precision == 0 && force_decimal == ForceDecimal::Yes {
|
||||||
format!("{f:.0}.")
|
format!("{f:.0}.")
|
||||||
} else {
|
} else {
|
||||||
format!("{f:.*}", precision)
|
format!("{f:.precision$}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,10 +380,7 @@ fn format_float_scientific(
|
||||||
Case::Uppercase => 'E',
|
Case::Uppercase => 'E',
|
||||||
};
|
};
|
||||||
|
|
||||||
format!(
|
format!("{normalized:.precision$}{additional_dot}{exp_char}{exponent:+03}")
|
||||||
"{normalized:.*}{additional_dot}{exp_char}{exponent:+03}",
|
|
||||||
precision
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_float_shortest(
|
fn format_float_shortest(
|
||||||
|
@ -427,7 +424,7 @@ fn format_float_shortest(
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut normalized = format!("{normalized:.*}", precision);
|
let mut normalized = format!("{normalized:.precision$}");
|
||||||
|
|
||||||
if force_decimal == ForceDecimal::No {
|
if force_decimal == ForceDecimal::No {
|
||||||
strip_fractional_zeroes_and_dot(&mut normalized);
|
strip_fractional_zeroes_and_dot(&mut normalized);
|
||||||
|
@ -449,7 +446,7 @@ fn format_float_shortest(
|
||||||
let mut formatted = if decimal_places == 0 && force_decimal == ForceDecimal::Yes {
|
let mut formatted = if decimal_places == 0 && force_decimal == ForceDecimal::Yes {
|
||||||
format!("{f:.0}.")
|
format!("{f:.0}.")
|
||||||
} else {
|
} else {
|
||||||
format!("{f:.*}", decimal_places)
|
format!("{f:.decimal_places$}")
|
||||||
};
|
};
|
||||||
|
|
||||||
if force_decimal == ForceDecimal::No {
|
if force_decimal == ForceDecimal::No {
|
||||||
|
@ -514,11 +511,7 @@ fn write_output(
|
||||||
// Using min() because self.width could be 0, 0usize - 1usize should be avoided
|
// Using min() because self.width could be 0, 0usize - 1usize should be avoided
|
||||||
let remaining_width = width - min(width, sign_indicator.len());
|
let remaining_width = width - min(width, sign_indicator.len());
|
||||||
match alignment {
|
match alignment {
|
||||||
NumberAlignment::Left => write!(
|
NumberAlignment::Left => write!(writer, "{sign_indicator}{s:<remaining_width$}"),
|
||||||
writer,
|
|
||||||
"{sign_indicator}{s:<width$}",
|
|
||||||
width = remaining_width
|
|
||||||
),
|
|
||||||
NumberAlignment::RightSpace => {
|
NumberAlignment::RightSpace => {
|
||||||
let is_sign = sign_indicator.starts_with('-') || sign_indicator.starts_with('+'); // When sign_indicator is in ['-', '+']
|
let is_sign = sign_indicator.starts_with('-') || sign_indicator.starts_with('+'); // When sign_indicator is in ['-', '+']
|
||||||
if is_sign && remaining_width > 0 {
|
if is_sign && remaining_width > 0 {
|
||||||
|
@ -526,19 +519,11 @@ fn write_output(
|
||||||
s = sign_indicator + s.as_str();
|
s = sign_indicator + s.as_str();
|
||||||
write!(writer, "{s:>width$}", width = remaining_width + 1) // Since we now add sign_indicator and s together, plus 1
|
write!(writer, "{s:>width$}", width = remaining_width + 1) // Since we now add sign_indicator and s together, plus 1
|
||||||
} else {
|
} else {
|
||||||
write!(
|
write!(writer, "{sign_indicator}{s:>remaining_width$}")
|
||||||
writer,
|
|
||||||
"{sign_indicator}{s:>width$}",
|
|
||||||
width = remaining_width
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NumberAlignment::RightZero => {
|
NumberAlignment::RightZero => {
|
||||||
write!(
|
write!(writer, "{sign_indicator}{s:0>remaining_width$}")
|
||||||
writer,
|
|
||||||
"{sign_indicator}{s:0>width$}",
|
|
||||||
width = remaining_width
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,8 +220,8 @@ fn is_root(path: &Path, would_traverse_symlink: bool) -> bool {
|
||||||
Some(".") | Some("..") => true,
|
Some(".") | Some("..") => true,
|
||||||
Some(path_str) => {
|
Some(path_str) => {
|
||||||
(path_str.ends_with(MAIN_SEPARATOR_STR))
|
(path_str.ends_with(MAIN_SEPARATOR_STR))
|
||||||
|| (path_str.ends_with(&format!("{}.", MAIN_SEPARATOR_STR)))
|
|| (path_str.ends_with(&format!("{MAIN_SEPARATOR_STR}.")))
|
||||||
|| (path_str.ends_with(&format!("{}..", MAIN_SEPARATOR_STR)))
|
|| (path_str.ends_with(&format!("{MAIN_SEPARATOR_STR}..")))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// TODO: Once we reach MSRV 1.74.0, replace this abomination by something simpler, e.g. this:
|
// TODO: Once we reach MSRV 1.74.0, replace this abomination by something simpler, e.g. this:
|
||||||
|
|
|
@ -801,31 +801,31 @@ mod tests {
|
||||||
always_quote: false,
|
always_quote: false,
|
||||||
show_control: false,
|
show_control: false,
|
||||||
};
|
};
|
||||||
assert_eq!(format!("{}", style), "shell-escape");
|
assert_eq!(format!("{style}"), "shell-escape");
|
||||||
|
|
||||||
let style = QuotingStyle::Shell {
|
let style = QuotingStyle::Shell {
|
||||||
escape: false,
|
escape: false,
|
||||||
always_quote: true,
|
always_quote: true,
|
||||||
show_control: false,
|
show_control: false,
|
||||||
};
|
};
|
||||||
assert_eq!(format!("{}", style), "shell-always-quote");
|
assert_eq!(format!("{style}"), "shell-always-quote");
|
||||||
|
|
||||||
let style = QuotingStyle::Shell {
|
let style = QuotingStyle::Shell {
|
||||||
escape: false,
|
escape: false,
|
||||||
always_quote: false,
|
always_quote: false,
|
||||||
show_control: true,
|
show_control: true,
|
||||||
};
|
};
|
||||||
assert_eq!(format!("{}", style), "shell-show-control");
|
assert_eq!(format!("{style}"), "shell-show-control");
|
||||||
|
|
||||||
let style = QuotingStyle::C {
|
let style = QuotingStyle::C {
|
||||||
quotes: Quotes::Double,
|
quotes: Quotes::Double,
|
||||||
};
|
};
|
||||||
assert_eq!(format!("{}", style), "C");
|
assert_eq!(format!("{style}"), "C");
|
||||||
|
|
||||||
let style = QuotingStyle::Literal {
|
let style = QuotingStyle::Literal {
|
||||||
show_control: false,
|
show_control: false,
|
||||||
};
|
};
|
||||||
assert_eq!(format!("{}", style), "literal");
|
assert_eq!(format!("{style}"), "literal");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -79,8 +79,7 @@ fn add_ambiguous_value_tip(
|
||||||
err.insert(
|
err.insert(
|
||||||
ContextKind::Suggested,
|
ContextKind::Suggested,
|
||||||
ContextValue::StyledStrs(vec![format!(
|
ContextValue::StyledStrs(vec![format!(
|
||||||
"It looks like '{}' could match several values. Did you mean {}?",
|
"It looks like '{value}' could match several values. Did you mean {formatted_possible_values}?"
|
||||||
value, formatted_possible_values
|
|
||||||
)
|
)
|
||||||
.into()]),
|
.into()]),
|
||||||
);
|
);
|
||||||
|
@ -175,8 +174,7 @@ mod tests {
|
||||||
let result = parser.parse_ref(&cmd, None, OsStr::new(ambiguous_value));
|
let result = parser.parse_ref(&cmd, None, OsStr::new(ambiguous_value));
|
||||||
assert_eq!(ErrorKind::InvalidValue, result.as_ref().unwrap_err().kind());
|
assert_eq!(ErrorKind::InvalidValue, result.as_ref().unwrap_err().kind());
|
||||||
assert!(result.unwrap_err().to_string().contains(&format!(
|
assert!(result.unwrap_err().to_string().contains(&format!(
|
||||||
"It looks like '{}' could match several values. Did you mean 'abcd' or 'abef'?",
|
"It looks like '{ambiguous_value}' could match several values. Did you mean 'abcd' or 'abef'?"
|
||||||
ambiguous_value
|
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -341,7 +341,7 @@ fn test_cp_arg_update_none_fail() {
|
||||||
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
||||||
.arg("--update=none-fail")
|
.arg("--update=none-fail")
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_contains(format!("not replacing '{}'", TEST_HOW_ARE_YOU_SOURCE));
|
.stderr_contains(format!("not replacing '{TEST_HOW_ARE_YOU_SOURCE}'"));
|
||||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "How are you?\n");
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "How are you?\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3897,7 +3897,7 @@ fn test_acl_preserve() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("test skipped: setfacl failed with {}", e);
|
println!("test skipped: setfacl failed with {e}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5581,7 +5581,7 @@ fn test_dir_perm_race_with_preserve_mode_and_ownership() {
|
||||||
let child = scene
|
let child = scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&[
|
.args(&[
|
||||||
format!("--preserve={}", attr).as_str(),
|
format!("--preserve={attr}").as_str(),
|
||||||
"-R",
|
"-R",
|
||||||
"--copy-contents",
|
"--copy-contents",
|
||||||
"--parents",
|
"--parents",
|
||||||
|
@ -5600,12 +5600,12 @@ fn test_dir_perm_race_with_preserve_mode_and_ownership() {
|
||||||
start_time.elapsed() < timeout,
|
start_time.elapsed() < timeout,
|
||||||
"timed out: cp took too long to create destination directory"
|
"timed out: cp took too long to create destination directory"
|
||||||
);
|
);
|
||||||
if at.dir_exists(&format!("{}/{}", DEST_DIR, SRC_DIR)) {
|
if at.dir_exists(&format!("{DEST_DIR}/{SRC_DIR}")) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::thread::sleep(Duration::from_millis(100));
|
std::thread::sleep(Duration::from_millis(100));
|
||||||
}
|
}
|
||||||
let mode = at.metadata(&format!("{}/{}", DEST_DIR, SRC_DIR)).mode();
|
let mode = at.metadata(&format!("{DEST_DIR}/{SRC_DIR}")).mode();
|
||||||
#[allow(clippy::unnecessary_cast, clippy::cast_lossless)]
|
#[allow(clippy::unnecessary_cast, clippy::cast_lossless)]
|
||||||
let mask = if attr == "mode" {
|
let mask = if attr == "mode" {
|
||||||
libc::S_IWGRP | libc::S_IWOTH
|
libc::S_IWGRP | libc::S_IWOTH
|
||||||
|
@ -5615,8 +5615,7 @@ fn test_dir_perm_race_with_preserve_mode_and_ownership() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(mode & mask),
|
(mode & mask),
|
||||||
0,
|
0,
|
||||||
"unwanted permissions are present - {}",
|
"unwanted permissions are present - {attr}"
|
||||||
attr
|
|
||||||
);
|
);
|
||||||
at.write(FIFO, "done");
|
at.write(FIFO, "done");
|
||||||
child.wait().unwrap().succeeded();
|
child.wait().unwrap().succeeded();
|
||||||
|
@ -5673,18 +5672,15 @@ fn test_preserve_attrs_overriding_2() {
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
let at = &scene.fixtures;
|
let at = &scene.fixtures;
|
||||||
at.mkdir(FOLDER);
|
at.mkdir(FOLDER);
|
||||||
at.make_file(&format!("{}/{}", FOLDER, FILE1));
|
at.make_file(&format!("{FOLDER}/{FILE1}"));
|
||||||
at.set_mode(&format!("{}/{}", FOLDER, FILE1), 0o775);
|
at.set_mode(&format!("{FOLDER}/{FILE1}"), 0o775);
|
||||||
at.hard_link(
|
at.hard_link(&format!("{FOLDER}/{FILE1}"), &format!("{FOLDER}/{FILE2}"));
|
||||||
&format!("{}/{}", FOLDER, FILE1),
|
|
||||||
&format!("{}/{}", FOLDER, FILE2),
|
|
||||||
);
|
|
||||||
args.append(&mut vec![FOLDER, DEST]);
|
args.append(&mut vec![FOLDER, DEST]);
|
||||||
let src_file1_metadata = at.metadata(&format!("{}/{}", FOLDER, FILE1));
|
let src_file1_metadata = at.metadata(&format!("{FOLDER}/{FILE1}"));
|
||||||
scene.ucmd().args(&args).succeeds();
|
scene.ucmd().args(&args).succeeds();
|
||||||
at.dir_exists(DEST);
|
at.dir_exists(DEST);
|
||||||
let dest_file1_metadata = at.metadata(&format!("{}/{}", DEST, FILE1));
|
let dest_file1_metadata = at.metadata(&format!("{DEST}/{FILE1}"));
|
||||||
let dest_file2_metadata = at.metadata(&format!("{}/{}", DEST, FILE2));
|
let dest_file2_metadata = at.metadata(&format!("{DEST}/{FILE2}"));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
src_file1_metadata.modified().unwrap(),
|
src_file1_metadata.modified().unwrap(),
|
||||||
dest_file1_metadata.modified().unwrap()
|
dest_file1_metadata.modified().unwrap()
|
||||||
|
|
|
@ -1649,7 +1649,7 @@ fn test_reading_partial_blocks_from_fifo() {
|
||||||
// until the writer process starts).
|
// until the writer process starts).
|
||||||
let mut reader_command = Command::new(TESTS_BINARY);
|
let mut reader_command = Command::new(TESTS_BINARY);
|
||||||
let child = reader_command
|
let child = reader_command
|
||||||
.args(["dd", "ibs=3", "obs=3", &format!("if={}", fifoname)])
|
.args(["dd", "ibs=3", "obs=3", &format!("if={fifoname}")])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
|
@ -1661,7 +1661,7 @@ fn test_reading_partial_blocks_from_fifo() {
|
||||||
writer_command
|
writer_command
|
||||||
.args([
|
.args([
|
||||||
"-c",
|
"-c",
|
||||||
&format!("(printf \"ab\"; sleep 0.1; printf \"cd\") > {}", fifoname),
|
&format!("(printf \"ab\"; sleep 0.1; printf \"cd\") > {fifoname}"),
|
||||||
])
|
])
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -1692,7 +1692,7 @@ fn test_reading_partial_blocks_from_fifo_unbuffered() {
|
||||||
// `bs=N` takes precedence over `ibs=N` and `obs=N`.
|
// `bs=N` takes precedence over `ibs=N` and `obs=N`.
|
||||||
let mut reader_command = Command::new(TESTS_BINARY);
|
let mut reader_command = Command::new(TESTS_BINARY);
|
||||||
let child = reader_command
|
let child = reader_command
|
||||||
.args(["dd", "bs=3", "ibs=1", "obs=1", &format!("if={}", fifoname)])
|
.args(["dd", "bs=3", "ibs=1", "obs=1", &format!("if={fifoname}")])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
|
@ -1704,7 +1704,7 @@ fn test_reading_partial_blocks_from_fifo_unbuffered() {
|
||||||
writer_command
|
writer_command
|
||||||
.args([
|
.args([
|
||||||
"-c",
|
"-c",
|
||||||
&format!("(printf \"ab\"; sleep 0.1; printf \"cd\") > {}", fifoname),
|
&format!("(printf \"ab\"; sleep 0.1; printf \"cd\") > {fifoname}"),
|
||||||
])
|
])
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -1769,10 +1769,10 @@ fn test_stdin_stdout_not_rewound_even_when_connected_to_seekable_file() {
|
||||||
.succeeds();
|
.succeeds();
|
||||||
|
|
||||||
let err_file_content = std::fs::read_to_string(at.plus_as_string("err")).unwrap();
|
let err_file_content = std::fs::read_to_string(at.plus_as_string("err")).unwrap();
|
||||||
println!("stderr:\n{}", err_file_content);
|
println!("stderr:\n{err_file_content}");
|
||||||
|
|
||||||
let out_file_content = std::fs::read_to_string(at.plus_as_string("out")).unwrap();
|
let out_file_content = std::fs::read_to_string(at.plus_as_string("out")).unwrap();
|
||||||
println!("stdout:\n{}", out_file_content);
|
println!("stdout:\n{out_file_content}");
|
||||||
assert_eq!(out_file_content, "bde");
|
assert_eq!(out_file_content, "bde");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -935,7 +935,7 @@ mod tests_split_iterator {
|
||||||
// minimal amount of quoting in typical cases.
|
// minimal amount of quoting in typical cases.
|
||||||
match escape_style(s) {
|
match escape_style(s) {
|
||||||
EscapeStyle::None => s.into(),
|
EscapeStyle::None => s.into(),
|
||||||
EscapeStyle::SingleQuoted => format!("'{}'", s).into(),
|
EscapeStyle::SingleQuoted => format!("'{s}'").into(),
|
||||||
EscapeStyle::Mixed => {
|
EscapeStyle::Mixed => {
|
||||||
let mut quoted = String::new();
|
let mut quoted = String::new();
|
||||||
quoted.push('\'');
|
quoted.push('\'');
|
||||||
|
@ -1015,17 +1015,13 @@ mod tests_split_iterator {
|
||||||
match split(input) {
|
match split(input) {
|
||||||
Err(actual) => {
|
Err(actual) => {
|
||||||
panic!(
|
panic!(
|
||||||
"[{i}] calling split({:?}):\nexpected: Ok({:?})\n actual: Err({:?})\n",
|
"[{i}] calling split({input:?}):\nexpected: Ok({expected:?})\n actual: Err({actual:?})\n"
|
||||||
input, expected, actual
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Ok(actual) => {
|
Ok(actual) => {
|
||||||
assert!(
|
assert!(
|
||||||
expected == actual.as_slice(),
|
expected == actual.as_slice(),
|
||||||
"[{i}] After split({:?}).unwrap()\nexpected: {:?}\n actual: {:?}\n",
|
"[{i}] After split({input:?}).unwrap()\nexpected: {expected:?}\n actual: {actual:?}\n"
|
||||||
input,
|
|
||||||
expected,
|
|
||||||
actual
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,7 +174,7 @@ fn get_filesystem_type(scene: &TestScenario, path: &Path) -> String {
|
||||||
let regex = Regex::new(regex_str).unwrap();
|
let regex = Regex::new(regex_str).unwrap();
|
||||||
let m = regex.captures(&stdout_str).unwrap();
|
let m = regex.captures(&stdout_str).unwrap();
|
||||||
let fstype = m["fstype"].to_owned();
|
let fstype = m["fstype"].to_owned();
|
||||||
println!("detected fstype: {}", fstype);
|
println!("detected fstype: {fstype}");
|
||||||
fstype
|
fstype
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4120,7 +4120,7 @@ fn test_ls_dired_recursive_multiple() {
|
||||||
let result = cmd.succeeds();
|
let result = cmd.succeeds();
|
||||||
|
|
||||||
let output = result.stdout_str().to_string();
|
let output = result.stdout_str().to_string();
|
||||||
println!("Output:\n{}", output);
|
println!("Output:\n{output}");
|
||||||
|
|
||||||
let dired_line = output
|
let dired_line = output
|
||||||
.lines()
|
.lines()
|
||||||
|
@ -4143,7 +4143,7 @@ fn test_ls_dired_recursive_multiple() {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.trim()
|
.trim()
|
||||||
.to_string();
|
.to_string();
|
||||||
println!("Extracted filename: {}", filename);
|
println!("Extracted filename: {filename}");
|
||||||
filename
|
filename
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -4229,8 +4229,8 @@ fn test_ls_dired_complex() {
|
||||||
.skip(1)
|
.skip(1)
|
||||||
.map(|s| s.parse().unwrap())
|
.map(|s| s.parse().unwrap())
|
||||||
.collect();
|
.collect();
|
||||||
println!("{:?}", positions);
|
println!("{positions:?}");
|
||||||
println!("Parsed byte positions: {:?}", positions);
|
println!("Parsed byte positions: {positions:?}");
|
||||||
assert_eq!(positions.len() % 2, 0); // Ensure there's an even number of positions
|
assert_eq!(positions.len() % 2, 0); // Ensure there's an even number of positions
|
||||||
|
|
||||||
let filenames: Vec<String> = positions
|
let filenames: Vec<String> = positions
|
||||||
|
@ -4242,12 +4242,12 @@ fn test_ls_dired_complex() {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.trim()
|
.trim()
|
||||||
.to_string();
|
.to_string();
|
||||||
println!("Extracted filename: {}", filename);
|
println!("Extracted filename: {filename}");
|
||||||
filename
|
filename
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
println!("Extracted filenames: {:?}", filenames);
|
println!("Extracted filenames: {filenames:?}");
|
||||||
assert_eq!(filenames, vec!["a1", "a22", "a333", "a4444", "d"]);
|
assert_eq!(filenames, vec!["a1", "a22", "a333", "a4444", "d"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4269,7 +4269,7 @@ fn test_ls_subdired_complex() {
|
||||||
let result = cmd.succeeds();
|
let result = cmd.succeeds();
|
||||||
|
|
||||||
let output = result.stdout_str().to_string();
|
let output = result.stdout_str().to_string();
|
||||||
println!("Output:\n{}", output);
|
println!("Output:\n{output}");
|
||||||
|
|
||||||
let dired_line = output
|
let dired_line = output
|
||||||
.lines()
|
.lines()
|
||||||
|
@ -4280,7 +4280,7 @@ fn test_ls_subdired_complex() {
|
||||||
.skip(1)
|
.skip(1)
|
||||||
.map(|s| s.parse().unwrap())
|
.map(|s| s.parse().unwrap())
|
||||||
.collect();
|
.collect();
|
||||||
println!("Parsed byte positions: {:?}", positions);
|
println!("Parsed byte positions: {positions:?}");
|
||||||
assert_eq!(positions.len() % 2, 0); // Ensure there's an even number of positions
|
assert_eq!(positions.len() % 2, 0); // Ensure there's an even number of positions
|
||||||
|
|
||||||
let dirnames: Vec<String> = positions
|
let dirnames: Vec<String> = positions
|
||||||
|
@ -4290,12 +4290,12 @@ fn test_ls_subdired_complex() {
|
||||||
let end_pos = chunk[1];
|
let end_pos = chunk[1];
|
||||||
let dirname =
|
let dirname =
|
||||||
String::from_utf8(output.as_bytes()[start_pos..end_pos].to_vec()).unwrap();
|
String::from_utf8(output.as_bytes()[start_pos..end_pos].to_vec()).unwrap();
|
||||||
println!("Extracted dirname: {}", dirname);
|
println!("Extracted dirname: {dirname}");
|
||||||
dirname
|
dirname
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
println!("Extracted dirnames: {:?}", dirnames);
|
println!("Extracted dirnames: {dirnames:?}");
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
assert_eq!(dirnames, vec!["dir1", "dir1/c2", "dir1/d"]);
|
assert_eq!(dirnames, vec!["dir1", "dir1/c2", "dir1/d"]);
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
@ -4786,7 +4786,7 @@ fn test_acl_display() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("test skipped: setfacl failed with {}", e);
|
println!("test skipped: setfacl failed with {e}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4874,7 +4874,7 @@ fn test_ls_color_norm() {
|
||||||
let expected = "\x1b[0m\x1b[07mnorm \x1b[0m\x1b[01mno_color\x1b[0m\n\x1b[07mnorm \x1b[0m\x1b[01;32mexe\x1b[0m\n"; // spell-checker:disable-line
|
let expected = "\x1b[0m\x1b[07mnorm \x1b[0m\x1b[01mno_color\x1b[0m\n\x1b[07mnorm \x1b[0m\x1b[01;32mexe\x1b[0m\n"; // spell-checker:disable-line
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.env("LS_COLORS", format!("{}:fi=1", colors))
|
.env("LS_COLORS", format!("{colors}:fi=1"))
|
||||||
.env("TIME_STYLE", "+norm")
|
.env("TIME_STYLE", "+norm")
|
||||||
.arg("-gGU")
|
.arg("-gGU")
|
||||||
.arg("--color")
|
.arg("--color")
|
||||||
|
@ -4889,7 +4889,7 @@ fn test_ls_color_norm() {
|
||||||
"\x1b[0m\x1b[07mnorm \x1b[0mno_color\x1b[0m\n\x1b[07mnorm \x1b[0m\x1b[01;32mexe\x1b[0m\n"; // spell-checker:disable-line
|
"\x1b[0m\x1b[07mnorm \x1b[0mno_color\x1b[0m\n\x1b[07mnorm \x1b[0m\x1b[01;32mexe\x1b[0m\n"; // spell-checker:disable-line
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.env("LS_COLORS", format!("{}:fi=", colors))
|
.env("LS_COLORS", format!("{colors}:fi="))
|
||||||
.env("TIME_STYLE", "+norm")
|
.env("TIME_STYLE", "+norm")
|
||||||
.arg("-gGU")
|
.arg("-gGU")
|
||||||
.arg("--color")
|
.arg("--color")
|
||||||
|
@ -4903,7 +4903,7 @@ fn test_ls_color_norm() {
|
||||||
"\x1b[0m\x1b[07mnorm \x1b[0mno_color\x1b[0m\n\x1b[07mnorm \x1b[0m\x1b[01;32mexe\x1b[0m\n"; // spell-checker:disable-line
|
"\x1b[0m\x1b[07mnorm \x1b[0mno_color\x1b[0m\n\x1b[07mnorm \x1b[0m\x1b[01;32mexe\x1b[0m\n"; // spell-checker:disable-line
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.env("LS_COLORS", format!("{}:fi=0", colors))
|
.env("LS_COLORS", format!("{colors}:fi=0"))
|
||||||
.env("TIME_STYLE", "+norm")
|
.env("TIME_STYLE", "+norm")
|
||||||
.arg("-gGU")
|
.arg("-gGU")
|
||||||
.arg("--color")
|
.arg("--color")
|
||||||
|
|
|
@ -1448,7 +1448,7 @@ fn test_mv_directory_into_subdirectory_of_itself_fails() {
|
||||||
// check that it also errors out with /
|
// check that it also errors out with /
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.arg(format!("{}/", dir1))
|
.arg(format!("{dir1}/"))
|
||||||
.arg(dir2)
|
.arg(dir2)
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_contains(
|
.stderr_contains(
|
||||||
|
@ -1601,7 +1601,7 @@ fn test_acl() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("test skipped: setfacl failed with {}", e);
|
println!("test skipped: setfacl failed with {e}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,7 @@ fn test_delimiter_list_ending_with_escaped_backslash() {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
let mut ins = vec![];
|
let mut ins = vec![];
|
||||||
for (i, one_in) in ["a\n", "b\n"].iter().enumerate() {
|
for (i, one_in) in ["a\n", "b\n"].iter().enumerate() {
|
||||||
let file = format!("in{}", i);
|
let file = format!("in{i}");
|
||||||
at.write(&file, one_in);
|
at.write(&file, one_in);
|
||||||
ins.push(file);
|
ins.push(file);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1052,17 +1052,16 @@ fn test_batch_size_too_large() {
|
||||||
let large_batch_size = "18446744073709551616";
|
let large_batch_size = "18446744073709551616";
|
||||||
TestScenario::new(util_name!())
|
TestScenario::new(util_name!())
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.arg(format!("--batch-size={}", large_batch_size))
|
.arg(format!("--batch-size={large_batch_size}"))
|
||||||
.fails()
|
.fails()
|
||||||
.code_is(2)
|
.code_is(2)
|
||||||
.stderr_contains(format!(
|
.stderr_contains(format!(
|
||||||
"--batch-size argument '{}' too large",
|
"--batch-size argument '{large_batch_size}' too large"
|
||||||
large_batch_size
|
|
||||||
));
|
));
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
TestScenario::new(util_name!())
|
TestScenario::new(util_name!())
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.arg(format!("--batch-size={}", large_batch_size))
|
.arg(format!("--batch-size={large_batch_size}"))
|
||||||
.fails()
|
.fails()
|
||||||
.code_is(2)
|
.code_is(2)
|
||||||
.stderr_contains("maximum --batch-size argument with current rlimit is");
|
.stderr_contains("maximum --batch-size argument with current rlimit is");
|
||||||
|
|
|
@ -3594,10 +3594,8 @@ fn test_when_argument_file_is_non_existent_unix_socket_address_then_error() {
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
|
|
||||||
#[cfg(all(not(target_os = "freebsd"), not(target_os = "macos")))]
|
#[cfg(all(not(target_os = "freebsd"), not(target_os = "macos")))]
|
||||||
let expected_stderr = format!(
|
let expected_stderr =
|
||||||
"tail: cannot open '{}' for reading: No such device or address\n",
|
format!("tail: cannot open '{socket}' for reading: No such device or address\n");
|
||||||
socket
|
|
||||||
);
|
|
||||||
#[cfg(target_os = "freebsd")]
|
#[cfg(target_os = "freebsd")]
|
||||||
let expected_stderr = format!(
|
let expected_stderr = format!(
|
||||||
"tail: cannot open '{}' for reading: Operation not supported\n",
|
"tail: cannot open '{}' for reading: Operation not supported\n",
|
||||||
|
@ -3622,7 +3620,7 @@ fn test_when_argument_file_is_non_existent_unix_socket_address_then_error() {
|
||||||
let result = file.write_all(random_string.as_bytes());
|
let result = file.write_all(random_string.as_bytes());
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
|
|
||||||
let expected_stdout = [format!("==> {} <==", path), random_string].join("\n");
|
let expected_stdout = [format!("==> {path} <=="), random_string].join("\n");
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.args(&["-c", "+0", path, socket])
|
.args(&["-c", "+0", path, socket])
|
||||||
.fails()
|
.fails()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue