mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
remove needless pass by value
This commit is contained in:
parent
f4c6ea0ee8
commit
a2d5f06be4
55 changed files with 332 additions and 331 deletions
|
@ -153,7 +153,7 @@ pub fn handle_input<R: Read>(
|
|||
if !decode {
|
||||
match data.encode() {
|
||||
Ok(s) => {
|
||||
wrap_print(&data, s);
|
||||
wrap_print(&data, &s);
|
||||
Ok(())
|
||||
}
|
||||
Err(_) => Err(USimpleError::new(
|
||||
|
|
|
@ -236,7 +236,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
show_tabs,
|
||||
squeeze_blank,
|
||||
};
|
||||
cat_files(files, &options)
|
||||
cat_files(&files, &options)
|
||||
}
|
||||
|
||||
pub fn uu_app<'a>() -> App<'a> {
|
||||
|
@ -365,7 +365,7 @@ fn cat_path(
|
|||
}
|
||||
}
|
||||
|
||||
fn cat_files(files: Vec<String>, options: &OutputOptions) -> UResult<()> {
|
||||
fn cat_files(files: &[String], options: &OutputOptions) -> UResult<()> {
|
||||
let out_info = FileInformation::from_file(&std::io::stdout());
|
||||
|
||||
let mut state = OutputState {
|
||||
|
@ -376,7 +376,7 @@ fn cat_files(files: Vec<String>, options: &OutputOptions) -> UResult<()> {
|
|||
};
|
||||
let mut error_messages: Vec<String> = Vec::new();
|
||||
|
||||
for path in &files {
|
||||
for path in files {
|
||||
if let Err(err) = cat_path(path, options, &mut state, out_info.as_ref()) {
|
||||
error_messages.push(format!("{}: {}", path.maybe_quote(), err));
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
cmode,
|
||||
};
|
||||
|
||||
chmoder.chmod(files)
|
||||
chmoder.chmod(&files)
|
||||
}
|
||||
|
||||
pub fn uu_app<'a>() -> App<'a> {
|
||||
|
@ -193,10 +193,10 @@ struct Chmoder {
|
|||
}
|
||||
|
||||
impl Chmoder {
|
||||
fn chmod(&self, files: Vec<String>) -> UResult<()> {
|
||||
fn chmod(&self, files: &[String]) -> UResult<()> {
|
||||
let mut r = Ok(());
|
||||
|
||||
for filename in &files {
|
||||
for filename in files {
|
||||
let filename = &filename[..];
|
||||
let file = Path::new(filename);
|
||||
if !file.exists() {
|
||||
|
|
|
@ -752,7 +752,7 @@ fn parse_path_args(path_args: &[String], options: &Options) -> CopyResult<(Vec<S
|
|||
fn preserve_hardlinks(
|
||||
hard_links: &mut Vec<(String, u64)>,
|
||||
source: &std::path::Path,
|
||||
dest: std::path::PathBuf,
|
||||
dest: &std::path::Path,
|
||||
found_hard_link: &mut bool,
|
||||
) -> CopyResult<()> {
|
||||
// Redox does not currently support hard links
|
||||
|
@ -805,7 +805,7 @@ fn preserve_hardlinks(
|
|||
|
||||
for hard_link in hard_links.iter() {
|
||||
if hard_link.1 == inode {
|
||||
std::fs::hard_link(hard_link.0.clone(), dest.clone()).unwrap();
|
||||
std::fs::hard_link(hard_link.0.clone(), dest).unwrap();
|
||||
*found_hard_link = true;
|
||||
}
|
||||
}
|
||||
|
@ -849,7 +849,7 @@ fn copy(sources: &[Source], target: &TargetSlice, options: &Options) -> CopyResu
|
|||
let mut found_hard_link = false;
|
||||
if preserve_hard_links {
|
||||
let dest = construct_dest_path(source, target, &target_type, options)?;
|
||||
preserve_hardlinks(&mut hard_links, source, dest, &mut found_hard_link)?;
|
||||
preserve_hardlinks(&mut hard_links, source, &dest, &mut found_hard_link)?;
|
||||
}
|
||||
if !found_hard_link {
|
||||
if let Err(error) =
|
||||
|
@ -1031,7 +1031,7 @@ fn copy_directory(
|
|||
let mut found_hard_link = false;
|
||||
let source = path.to_path_buf();
|
||||
let dest = local_to_target.as_path().to_path_buf();
|
||||
preserve_hardlinks(&mut hard_links, &source, dest, &mut found_hard_link)?;
|
||||
preserve_hardlinks(&mut hard_links, &source, &dest, &mut found_hard_link)?;
|
||||
if !found_hard_link {
|
||||
match copy_file(
|
||||
path.as_path(),
|
||||
|
|
|
@ -108,9 +108,9 @@ where
|
|||
input_iter.rewind_buffer();
|
||||
if let Some((_, line)) = input_iter.next() {
|
||||
split_writer.new_writer()?;
|
||||
split_writer.writeln(line?)?;
|
||||
split_writer.writeln(&line?)?;
|
||||
for (_, line) in input_iter {
|
||||
split_writer.writeln(line?)?;
|
||||
split_writer.writeln(&line?)?;
|
||||
}
|
||||
split_writer.finish_split();
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ impl<'a> SplitWriter<'a> {
|
|||
/// # Errors
|
||||
///
|
||||
/// Some [`io::Error`] may occur when attempting to write the line.
|
||||
fn writeln(&mut self, line: String) -> io::Result<()> {
|
||||
fn writeln(&mut self, line: &str) -> io::Result<()> {
|
||||
if !self.dev_null {
|
||||
match self.current_writer {
|
||||
Some(ref mut current_writer) => {
|
||||
|
@ -343,7 +343,7 @@ impl<'a> SplitWriter<'a> {
|
|||
}
|
||||
Ordering::Greater => (),
|
||||
}
|
||||
self.writeln(l)?;
|
||||
self.writeln(&l)?;
|
||||
}
|
||||
self.finish_split();
|
||||
ret
|
||||
|
@ -373,7 +373,7 @@ impl<'a> SplitWriter<'a> {
|
|||
// The offset is zero or positive, no need for a buffer on the lines read.
|
||||
// NOTE: drain the buffer of input_iter, no match should be done within.
|
||||
for line in input_iter.drain_buffer() {
|
||||
self.writeln(line)?;
|
||||
self.writeln(&line)?;
|
||||
}
|
||||
// retain the matching line
|
||||
input_iter.set_size_of_buffer(1);
|
||||
|
@ -390,7 +390,7 @@ impl<'a> SplitWriter<'a> {
|
|||
);
|
||||
}
|
||||
// a positive offset, some more lines need to be added to the current split
|
||||
(false, _) => self.writeln(l)?,
|
||||
(false, _) => self.writeln(&l)?,
|
||||
_ => (),
|
||||
};
|
||||
offset -= 1;
|
||||
|
@ -399,7 +399,7 @@ impl<'a> SplitWriter<'a> {
|
|||
while offset > 0 {
|
||||
match input_iter.next() {
|
||||
Some((_, line)) => {
|
||||
self.writeln(line?)?;
|
||||
self.writeln(&line?)?;
|
||||
}
|
||||
None => {
|
||||
self.finish_split();
|
||||
|
@ -413,7 +413,7 @@ impl<'a> SplitWriter<'a> {
|
|||
self.finish_split();
|
||||
return Ok(());
|
||||
}
|
||||
self.writeln(l)?;
|
||||
self.writeln(&l)?;
|
||||
}
|
||||
} else {
|
||||
// With a negative offset we use a buffer to keep the lines within the offset.
|
||||
|
@ -427,7 +427,7 @@ impl<'a> SplitWriter<'a> {
|
|||
let l = line?;
|
||||
if regex.is_match(&l) {
|
||||
for line in input_iter.shrink_buffer_to_size() {
|
||||
self.writeln(line)?;
|
||||
self.writeln(&line)?;
|
||||
}
|
||||
if !self.options.suppress_matched {
|
||||
// add 1 to the buffer size to make place for the matched line
|
||||
|
@ -444,12 +444,12 @@ impl<'a> SplitWriter<'a> {
|
|||
return Ok(());
|
||||
}
|
||||
if let Some(line) = input_iter.add_line_to_buffer(ln, l) {
|
||||
self.writeln(line)?;
|
||||
self.writeln(&line)?;
|
||||
}
|
||||
}
|
||||
// no match, drain the buffer into the current split
|
||||
for line in input_iter.drain_buffer() {
|
||||
self.writeln(line)?;
|
||||
self.writeln(&line)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -340,7 +340,7 @@ fn cut_fields<R: Read>(reader: R, ranges: &[Range], opts: &FieldOptions) -> URes
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn cut_files(mut filenames: Vec<String>, mode: Mode) -> UResult<()> {
|
||||
fn cut_files(mut filenames: Vec<String>, mode: &Mode) -> UResult<()> {
|
||||
let mut stdin_read = false;
|
||||
|
||||
if filenames.is_empty() {
|
||||
|
@ -527,7 +527,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
.collect();
|
||||
|
||||
match mode_parse {
|
||||
Ok(mode) => cut_files(files, mode),
|
||||
Ok(mode) => cut_files(files, &mode),
|
||||
Err(e) => Err(USimpleError::new(1, e)),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ mod tests {
|
|||
assert_eq!(vec![] as Vec<usize>, items);
|
||||
}
|
||||
|
||||
fn test_multibyte(line: &[u8], expected: Vec<usize>) {
|
||||
fn test_multibyte(line: &[u8], expected: &[usize]) {
|
||||
let iter = Searcher::new(line, NEEDLE);
|
||||
let items: Vec<usize> = iter.collect();
|
||||
assert_eq!(expected, items);
|
||||
|
@ -80,26 +80,26 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_multibyte_normal() {
|
||||
test_multibyte("...ab...ab...".as_bytes(), vec![3, 8]);
|
||||
test_multibyte("...ab...ab...".as_bytes(), &[3, 8]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multibyte_needle_head_at_end() {
|
||||
test_multibyte("a".as_bytes(), vec![]);
|
||||
test_multibyte("a".as_bytes(), &[]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multibyte_starting_needle() {
|
||||
test_multibyte("ab...ab...".as_bytes(), vec![0, 5]);
|
||||
test_multibyte("ab...ab...".as_bytes(), &[0, 5]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multibyte_trailing_needle() {
|
||||
test_multibyte("...ab...ab".as_bytes(), vec![3, 8]);
|
||||
test_multibyte("...ab...ab".as_bytes(), &[3, 8]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multibyte_first_byte_false_match() {
|
||||
test_multibyte("aA..aCaC..ab..aD".as_bytes(), vec![10]);
|
||||
test_multibyte("aA..aCaC..ab..aD".as_bytes(), &[10]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -322,7 +322,7 @@ impl<W: Write> Output<W>
|
|||
where
|
||||
Self: OutputTrait,
|
||||
{
|
||||
fn write_blocks(&mut self, buf: Vec<u8>) -> io::Result<WriteStat> {
|
||||
fn write_blocks(&mut self, buf: &[u8]) -> io::Result<WriteStat> {
|
||||
let mut writes_complete = 0;
|
||||
let mut writes_partial = 0;
|
||||
let mut bytes_total = 0;
|
||||
|
@ -381,7 +381,7 @@ where
|
|||
) => break,
|
||||
(rstat_update, buf) => {
|
||||
let wstat_update = self
|
||||
.write_blocks(buf)
|
||||
.write_blocks(&buf)
|
||||
.map_err_context(|| "failed to write output".to_string())?;
|
||||
|
||||
rstat += rstat_update;
|
||||
|
@ -560,7 +560,7 @@ impl Write for Output<io::Stdout> {
|
|||
/// Splits the content of buf into cbs-length blocks
|
||||
/// Appends padding as specified by conv=block and cbs=N
|
||||
/// Expects ascii encoded data
|
||||
fn block(buf: Vec<u8>, cbs: usize, rstat: &mut ReadStat) -> Vec<Vec<u8>> {
|
||||
fn block(buf: &[u8], cbs: usize, rstat: &mut ReadStat) -> Vec<Vec<u8>> {
|
||||
let mut blocks = buf
|
||||
.split(|&e| e == NEWLINE)
|
||||
.map(|split| split.to_vec())
|
||||
|
@ -586,7 +586,7 @@ fn block(buf: Vec<u8>, cbs: usize, rstat: &mut ReadStat) -> Vec<Vec<u8>> {
|
|||
/// Trims padding from each cbs-length partition of buf
|
||||
/// as specified by conv=unblock and cbs=N
|
||||
/// Expects ascii encoded data
|
||||
fn unblock(buf: Vec<u8>, cbs: usize) -> Vec<u8> {
|
||||
fn unblock(buf: &[u8], cbs: usize) -> Vec<u8> {
|
||||
buf.chunks(cbs).fold(Vec::new(), |mut acc, block| {
|
||||
if let Some(last_char_idx) = block.iter().rposition(|&e| e != SPACE) {
|
||||
// Include text up to last space.
|
||||
|
@ -643,7 +643,7 @@ fn conv_block_unblock_helper<R: Read>(
|
|||
// ascii input so perform the block first
|
||||
let cbs = i.cflags.block.unwrap();
|
||||
|
||||
let mut blocks = block(buf, cbs, rstat);
|
||||
let mut blocks = block(&buf, cbs, rstat);
|
||||
|
||||
if let Some(ct) = i.cflags.ctable {
|
||||
for buf in blocks.iter_mut() {
|
||||
|
@ -662,14 +662,14 @@ fn conv_block_unblock_helper<R: Read>(
|
|||
apply_conversion(&mut buf, ct);
|
||||
}
|
||||
|
||||
let blocks = block(buf, cbs, rstat).into_iter().flatten().collect();
|
||||
let blocks = block(&buf, cbs, rstat).into_iter().flatten().collect();
|
||||
|
||||
Ok(blocks)
|
||||
} else if should_unblock_then_conv(i) {
|
||||
// ascii input so perform the unblock first
|
||||
let cbs = i.cflags.unblock.unwrap();
|
||||
|
||||
let mut buf = unblock(buf, cbs);
|
||||
let mut buf = unblock(&buf, cbs);
|
||||
|
||||
if let Some(ct) = i.cflags.ctable {
|
||||
apply_conversion(&mut buf, ct);
|
||||
|
@ -684,7 +684,7 @@ fn conv_block_unblock_helper<R: Read>(
|
|||
apply_conversion(&mut buf, ct);
|
||||
}
|
||||
|
||||
let buf = unblock(buf, cbs);
|
||||
let buf = unblock(&buf, cbs);
|
||||
|
||||
Ok(buf)
|
||||
} else {
|
||||
|
|
|
@ -63,8 +63,8 @@ macro_rules! make_unblock_test (
|
|||
#[test]
|
||||
fn block_test_no_nl() {
|
||||
let mut rs = ReadStat::default();
|
||||
let buf = vec![0u8, 1u8, 2u8, 3u8];
|
||||
let res = block(buf, 4, &mut rs);
|
||||
let buf = [0u8, 1u8, 2u8, 3u8];
|
||||
let res = block(&buf, 4, &mut rs);
|
||||
|
||||
assert_eq!(res, vec![vec![0u8, 1u8, 2u8, 3u8],]);
|
||||
}
|
||||
|
@ -72,8 +72,8 @@ fn block_test_no_nl() {
|
|||
#[test]
|
||||
fn block_test_no_nl_short_record() {
|
||||
let mut rs = ReadStat::default();
|
||||
let buf = vec![0u8, 1u8, 2u8, 3u8];
|
||||
let res = block(buf, 8, &mut rs);
|
||||
let buf = [0u8, 1u8, 2u8, 3u8];
|
||||
let res = block(&buf, 8, &mut rs);
|
||||
|
||||
assert_eq!(
|
||||
res,
|
||||
|
@ -84,8 +84,8 @@ fn block_test_no_nl_short_record() {
|
|||
#[test]
|
||||
fn block_test_no_nl_trunc() {
|
||||
let mut rs = ReadStat::default();
|
||||
let buf = vec![0u8, 1u8, 2u8, 3u8, 4u8];
|
||||
let res = block(buf, 4, &mut rs);
|
||||
let buf = [0u8, 1u8, 2u8, 3u8, 4u8];
|
||||
let res = block(&buf, 4, &mut rs);
|
||||
|
||||
// Commented section(s) should be truncated and appear for reference only.
|
||||
assert_eq!(res, vec![vec![0u8, 1u8, 2u8, 3u8 /*, 4u8*/],]);
|
||||
|
@ -95,10 +95,10 @@ fn block_test_no_nl_trunc() {
|
|||
#[test]
|
||||
fn block_test_nl_gt_cbs_trunc() {
|
||||
let mut rs = ReadStat::default();
|
||||
let buf = vec![
|
||||
let buf = [
|
||||
0u8, 1u8, 2u8, 3u8, 4u8, NEWLINE, 0u8, 1u8, 2u8, 3u8, 4u8, NEWLINE, 5u8, 6u8, 7u8, 8u8,
|
||||
];
|
||||
let res = block(buf, 4, &mut rs);
|
||||
let res = block(&buf, 4, &mut rs);
|
||||
|
||||
assert_eq!(
|
||||
res,
|
||||
|
@ -117,8 +117,8 @@ fn block_test_nl_gt_cbs_trunc() {
|
|||
#[test]
|
||||
fn block_test_surrounded_nl() {
|
||||
let mut rs = ReadStat::default();
|
||||
let buf = vec![0u8, 1u8, 2u8, 3u8, NEWLINE, 4u8, 5u8, 6u8, 7u8, 8u8];
|
||||
let res = block(buf, 8, &mut rs);
|
||||
let buf = [0u8, 1u8, 2u8, 3u8, NEWLINE, 4u8, 5u8, 6u8, 7u8, 8u8];
|
||||
let res = block(&buf, 8, &mut rs);
|
||||
|
||||
assert_eq!(
|
||||
res,
|
||||
|
@ -132,10 +132,10 @@ fn block_test_surrounded_nl() {
|
|||
#[test]
|
||||
fn block_test_multiple_nl_same_cbs_block() {
|
||||
let mut rs = ReadStat::default();
|
||||
let buf = vec![
|
||||
let buf = [
|
||||
0u8, 1u8, 2u8, 3u8, NEWLINE, 4u8, NEWLINE, 5u8, 6u8, 7u8, 8u8, 9u8,
|
||||
];
|
||||
let res = block(buf, 8, &mut rs);
|
||||
let res = block(&buf, 8, &mut rs);
|
||||
|
||||
assert_eq!(
|
||||
res,
|
||||
|
@ -150,10 +150,10 @@ fn block_test_multiple_nl_same_cbs_block() {
|
|||
#[test]
|
||||
fn block_test_multiple_nl_diff_cbs_block() {
|
||||
let mut rs = ReadStat::default();
|
||||
let buf = vec![
|
||||
let buf = [
|
||||
0u8, 1u8, 2u8, 3u8, NEWLINE, 4u8, 5u8, 6u8, 7u8, NEWLINE, 8u8, 9u8,
|
||||
];
|
||||
let res = block(buf, 8, &mut rs);
|
||||
let res = block(&buf, 8, &mut rs);
|
||||
|
||||
assert_eq!(
|
||||
res,
|
||||
|
@ -168,8 +168,8 @@ fn block_test_multiple_nl_diff_cbs_block() {
|
|||
#[test]
|
||||
fn block_test_end_nl_diff_cbs_block() {
|
||||
let mut rs = ReadStat::default();
|
||||
let buf = vec![0u8, 1u8, 2u8, 3u8, NEWLINE];
|
||||
let res = block(buf, 4, &mut rs);
|
||||
let buf = [0u8, 1u8, 2u8, 3u8, NEWLINE];
|
||||
let res = block(&buf, 4, &mut rs);
|
||||
|
||||
assert_eq!(res, vec![vec![0u8, 1u8, 2u8, 3u8],]);
|
||||
}
|
||||
|
@ -177,8 +177,8 @@ fn block_test_end_nl_diff_cbs_block() {
|
|||
#[test]
|
||||
fn block_test_end_nl_same_cbs_block() {
|
||||
let mut rs = ReadStat::default();
|
||||
let buf = vec![0u8, 1u8, 2u8, NEWLINE];
|
||||
let res = block(buf, 4, &mut rs);
|
||||
let buf = [0u8, 1u8, 2u8, NEWLINE];
|
||||
let res = block(&buf, 4, &mut rs);
|
||||
|
||||
assert_eq!(res, vec![vec![0u8, 1u8, 2u8, SPACE]]);
|
||||
}
|
||||
|
@ -186,8 +186,8 @@ fn block_test_end_nl_same_cbs_block() {
|
|||
#[test]
|
||||
fn block_test_double_end_nl() {
|
||||
let mut rs = ReadStat::default();
|
||||
let buf = vec![0u8, 1u8, 2u8, NEWLINE, NEWLINE];
|
||||
let res = block(buf, 4, &mut rs);
|
||||
let buf = [0u8, 1u8, 2u8, NEWLINE, NEWLINE];
|
||||
let res = block(&buf, 4, &mut rs);
|
||||
|
||||
assert_eq!(
|
||||
res,
|
||||
|
@ -198,8 +198,8 @@ fn block_test_double_end_nl() {
|
|||
#[test]
|
||||
fn block_test_start_nl() {
|
||||
let mut rs = ReadStat::default();
|
||||
let buf = vec![NEWLINE, 0u8, 1u8, 2u8, 3u8];
|
||||
let res = block(buf, 4, &mut rs);
|
||||
let buf = [NEWLINE, 0u8, 1u8, 2u8, 3u8];
|
||||
let res = block(&buf, 4, &mut rs);
|
||||
|
||||
assert_eq!(
|
||||
res,
|
||||
|
@ -210,8 +210,8 @@ fn block_test_start_nl() {
|
|||
#[test]
|
||||
fn block_test_double_surrounded_nl_no_trunc() {
|
||||
let mut rs = ReadStat::default();
|
||||
let buf = vec![0u8, 1u8, 2u8, 3u8, NEWLINE, NEWLINE, 4u8, 5u8, 6u8, 7u8];
|
||||
let res = block(buf, 8, &mut rs);
|
||||
let buf = [0u8, 1u8, 2u8, 3u8, NEWLINE, NEWLINE, 4u8, 5u8, 6u8, 7u8];
|
||||
let res = block(&buf, 8, &mut rs);
|
||||
|
||||
assert_eq!(
|
||||
res,
|
||||
|
@ -226,10 +226,10 @@ fn block_test_double_surrounded_nl_no_trunc() {
|
|||
#[test]
|
||||
fn block_test_double_surrounded_nl_double_trunc() {
|
||||
let mut rs = ReadStat::default();
|
||||
let buf = vec![
|
||||
let buf = [
|
||||
0u8, 1u8, 2u8, 3u8, NEWLINE, NEWLINE, 4u8, 5u8, 6u8, 7u8, 8u8,
|
||||
];
|
||||
let res = block(buf, 4, &mut rs);
|
||||
let res = block(&buf, 4, &mut rs);
|
||||
|
||||
assert_eq!(
|
||||
res,
|
||||
|
@ -272,24 +272,24 @@ make_block_test!(
|
|||
|
||||
#[test]
|
||||
fn unblock_test_full_cbs() {
|
||||
let buf = vec![0u8, 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8];
|
||||
let res = unblock(buf, 8);
|
||||
let buf = [0u8, 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8];
|
||||
let res = unblock(&buf, 8);
|
||||
|
||||
assert_eq!(res, vec![0u8, 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, NEWLINE],);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unblock_test_all_space() {
|
||||
let buf = vec![SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE];
|
||||
let res = unblock(buf, 8);
|
||||
let buf = [SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE];
|
||||
let res = unblock(&buf, 8);
|
||||
|
||||
assert_eq!(res, vec![NEWLINE],);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unblock_test_decoy_spaces() {
|
||||
let buf = vec![0u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, 7u8];
|
||||
let res = unblock(buf, 8);
|
||||
let buf = [0u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, 7u8];
|
||||
let res = unblock(&buf, 8);
|
||||
|
||||
assert_eq!(
|
||||
res,
|
||||
|
@ -299,8 +299,8 @@ fn unblock_test_decoy_spaces() {
|
|||
|
||||
#[test]
|
||||
fn unblock_test_strip_single_cbs() {
|
||||
let buf = vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE];
|
||||
let res = unblock(buf, 8);
|
||||
let buf = [0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE];
|
||||
let res = unblock(&buf, 8);
|
||||
|
||||
assert_eq!(res, vec![0u8, 1u8, 2u8, 3u8, NEWLINE],);
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ fn unblock_test_strip_multi_cbs() {
|
|||
.flatten()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let res = unblock(buf, 8);
|
||||
let res = unblock(&buf, 8);
|
||||
|
||||
let exp = vec![
|
||||
vec![0u8, NEWLINE],
|
||||
|
|
|
@ -127,7 +127,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
|
||||
let result;
|
||||
if files.is_empty() {
|
||||
result = parse(INTERNAL_DB.lines(), out_format, "")
|
||||
result = parse(INTERNAL_DB.lines(), &out_format, "")
|
||||
} else {
|
||||
if files.len() > 1 {
|
||||
return Err(UUsageError::new(
|
||||
|
@ -138,7 +138,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
match File::open(files[0]) {
|
||||
Ok(f) => {
|
||||
let fin = BufReader::new(f);
|
||||
result = parse(fin.lines().filter_map(Result::ok), out_format, files[0])
|
||||
result = parse(fin.lines().filter_map(Result::ok), &out_format, files[0])
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(USimpleError::new(
|
||||
|
@ -259,7 +259,7 @@ enum ParseState {
|
|||
use std::collections::HashMap;
|
||||
use uucore::InvalidEncodingHandling;
|
||||
|
||||
fn parse<T>(lines: T, fmt: OutputFmt, fp: &str) -> Result<String, String>
|
||||
fn parse<T>(lines: T, fmt: &OutputFmt, fp: &str) -> Result<String, String>
|
||||
where
|
||||
T: IntoIterator,
|
||||
T::Item: Borrow<str>,
|
||||
|
|
|
@ -247,7 +247,7 @@ fn get_file_info(path: &Path) -> Option<FileInfo> {
|
|||
fn read_block_size(s: Option<&str>) -> usize {
|
||||
if let Some(s) = s {
|
||||
parse_size(s)
|
||||
.unwrap_or_else(|e| crash!(1, "{}", format_error_message(e, s, options::BLOCK_SIZE)))
|
||||
.unwrap_or_else(|e| crash!(1, "{}", format_error_message(&e, s, options::BLOCK_SIZE)))
|
||||
} else {
|
||||
for env_var in &["DU_BLOCK_SIZE", "BLOCK_SIZE", "BLOCKSIZE"] {
|
||||
if let Ok(env_size) = env::var(env_var) {
|
||||
|
@ -493,7 +493,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
|
||||
let threshold = matches.value_of(options::THRESHOLD).map(|s| {
|
||||
Threshold::from_str(s)
|
||||
.unwrap_or_else(|e| crash!(1, "{}", format_error_message(e, s, options::THRESHOLD)))
|
||||
.unwrap_or_else(|e| crash!(1, "{}", format_error_message(&e, s, options::THRESHOLD)))
|
||||
});
|
||||
|
||||
let multiplier: u64 = if matches.is_present(options::SI) {
|
||||
|
@ -831,7 +831,7 @@ impl Threshold {
|
|||
}
|
||||
}
|
||||
|
||||
fn format_error_message(error: ParseSizeError, s: &str, option: &str) -> String {
|
||||
fn format_error_message(error: &ParseSizeError, s: &str, option: &str) -> String {
|
||||
// NOTE:
|
||||
// GNU's du echos affected flag, -B or --block-size (-t or --threshold), depending user's selection
|
||||
// GNU's du does distinguish between "invalid (suffix in) argument"
|
||||
|
|
|
@ -125,7 +125,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
None => vec!["".to_string()],
|
||||
};
|
||||
|
||||
execute(no_newline, escaped, values).map_err_context(|| "could not write to stdout".to_string())
|
||||
execute(no_newline, escaped, &values)
|
||||
.map_err_context(|| "could not write to stdout".to_string())
|
||||
}
|
||||
|
||||
pub fn uu_app<'a>() -> App<'a> {
|
||||
|
@ -162,7 +163,7 @@ pub fn uu_app<'a>() -> App<'a> {
|
|||
.arg(Arg::new(options::STRING).multiple_occurrences(true))
|
||||
}
|
||||
|
||||
fn execute(no_newline: bool, escaped: bool, free: Vec<String>) -> io::Result<()> {
|
||||
fn execute(no_newline: bool, escaped: bool, free: &[String]) -> io::Result<()> {
|
||||
let stdout = io::stdout();
|
||||
let mut output = stdout.lock();
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ fn is_space_or_comma(c: char) -> bool {
|
|||
/// in the list. This mode defines the strategy to use for computing the
|
||||
/// number of spaces to use for columns beyond the end of the tab stop
|
||||
/// list specified here.
|
||||
fn tabstops_parse(s: String) -> (RemainingMode, Vec<usize>) {
|
||||
fn tabstops_parse(s: &str) -> (RemainingMode, Vec<usize>) {
|
||||
// Leading commas and spaces are ignored.
|
||||
let s = s.trim_start_matches(is_space_or_comma);
|
||||
|
||||
|
@ -135,7 +135,7 @@ struct Options {
|
|||
impl Options {
|
||||
fn new(matches: &ArgMatches) -> Options {
|
||||
let (remaining_mode, tabstops) = match matches.value_of(options::TABS) {
|
||||
Some(s) => tabstops_parse(s.to_string()),
|
||||
Some(s) => tabstops_parse(s),
|
||||
None => (RemainingMode::None, vec![DEFAULT_TABSTOP]),
|
||||
};
|
||||
|
||||
|
@ -176,7 +176,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
let usage = usage();
|
||||
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
|
||||
|
||||
expand(Options::new(&matches)).map_err_context(|| "failed to write output".to_string())
|
||||
expand(&Options::new(&matches)).map_err_context(|| "failed to write output".to_string())
|
||||
}
|
||||
|
||||
pub fn uu_app<'a>() -> App<'a> {
|
||||
|
@ -212,12 +212,12 @@ pub fn uu_app<'a>() -> App<'a> {
|
|||
)
|
||||
}
|
||||
|
||||
fn open(path: String) -> BufReader<Box<dyn Read + 'static>> {
|
||||
fn open(path: &str) -> BufReader<Box<dyn Read + 'static>> {
|
||||
let file_buf;
|
||||
if path == "-" {
|
||||
BufReader::new(Box::new(stdin()) as Box<dyn Read>)
|
||||
} else {
|
||||
file_buf = match File::open(&path[..]) {
|
||||
file_buf = match File::open(path) {
|
||||
Ok(a) => a,
|
||||
Err(e) => crash!(1, "{}: {}\n", path.maybe_quote(), e),
|
||||
};
|
||||
|
@ -271,14 +271,14 @@ enum CharType {
|
|||
Other,
|
||||
}
|
||||
|
||||
fn expand(options: Options) -> std::io::Result<()> {
|
||||
fn expand(options: &Options) -> std::io::Result<()> {
|
||||
use self::CharType::*;
|
||||
|
||||
let mut output = BufWriter::new(stdout());
|
||||
let ts = options.tabstops.as_ref();
|
||||
let mut buf = Vec::new();
|
||||
|
||||
for file in options.files.into_iter() {
|
||||
for file in options.files.iter() {
|
||||
let mut fh = open(file);
|
||||
|
||||
while match fh.read_until(b'\n', &mut buf) {
|
||||
|
|
|
@ -60,7 +60,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
None => vec!["-".to_owned()],
|
||||
};
|
||||
|
||||
fold(files, bytes, spaces, width)
|
||||
fold(&files, bytes, spaces, width)
|
||||
}
|
||||
|
||||
pub fn uu_app<'a>() -> App<'a> {
|
||||
|
@ -115,8 +115,8 @@ fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
|
|||
(args.to_vec(), None)
|
||||
}
|
||||
|
||||
fn fold(filenames: Vec<String>, bytes: bool, spaces: bool, width: usize) -> UResult<()> {
|
||||
for filename in &filenames {
|
||||
fn fold(filenames: &[String], bytes: bool, spaces: bool, width: usize) -> UResult<()> {
|
||||
for filename in filenames {
|
||||
let filename: &str = filename;
|
||||
let mut stdin_buf;
|
||||
let mut file_buf;
|
||||
|
|
|
@ -335,7 +335,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
}
|
||||
|
||||
if default_format {
|
||||
id_print(&mut state, groups);
|
||||
id_print(&mut state, &groups);
|
||||
}
|
||||
print!("{}", line_ending);
|
||||
|
||||
|
@ -556,7 +556,7 @@ fn auditid() {
|
|||
println!("asid={}", auditinfo.ai_asid);
|
||||
}
|
||||
|
||||
fn id_print(state: &mut State, groups: Vec<u32>) {
|
||||
fn id_print(state: &mut State, groups: &[u32]) {
|
||||
let uid = state.ids.as_ref().unwrap().uid;
|
||||
let gid = state.ids.as_ref().unwrap().gid;
|
||||
let euid = state.ids.as_ref().unwrap().euid;
|
||||
|
|
|
@ -187,8 +187,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
let behavior = behavior(&matches)?;
|
||||
|
||||
match behavior.main_function {
|
||||
MainFunction::Directory => directory(paths, behavior),
|
||||
MainFunction::Standard => standard(paths, behavior),
|
||||
MainFunction::Directory => directory(&paths, &behavior),
|
||||
MainFunction::Standard => standard(paths, &behavior),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -391,7 +391,7 @@ fn behavior(matches: &ArgMatches) -> UResult<Behavior> {
|
|||
///
|
||||
/// Returns a Result type with the Err variant containing the error message.
|
||||
///
|
||||
fn directory(paths: Vec<String>, b: Behavior) -> UResult<()> {
|
||||
fn directory(paths: &[String], b: &Behavior) -> UResult<()> {
|
||||
if paths.is_empty() {
|
||||
Err(InstallError::DirNeedsArg().into())
|
||||
} else {
|
||||
|
@ -444,7 +444,7 @@ fn is_new_file_path(path: &Path) -> bool {
|
|||
///
|
||||
/// Returns a Result type with the Err variant containing the error message.
|
||||
///
|
||||
fn standard(mut paths: Vec<String>, b: Behavior) -> UResult<()> {
|
||||
fn standard(mut paths: Vec<String>, b: &Behavior) -> UResult<()> {
|
||||
let target: PathBuf = b
|
||||
.target_dir
|
||||
.clone()
|
||||
|
@ -454,7 +454,7 @@ fn standard(mut paths: Vec<String>, b: Behavior) -> UResult<()> {
|
|||
let sources = &paths.iter().map(PathBuf::from).collect::<Vec<_>>();
|
||||
|
||||
if sources.len() > 1 || (target.exists() && target.is_dir()) {
|
||||
copy_files_into_dir(sources, &target, &b)
|
||||
copy_files_into_dir(sources, &target, b)
|
||||
} else {
|
||||
if let Some(parent) = target.parent() {
|
||||
if !parent.exists() && b.create_leading {
|
||||
|
@ -471,7 +471,7 @@ fn standard(mut paths: Vec<String>, b: Behavior) -> UResult<()> {
|
|||
}
|
||||
|
||||
if target.is_file() || is_new_file_path(&target) {
|
||||
copy(&sources[0], &target, &b)
|
||||
copy(&sources[0], &target, b)
|
||||
} else {
|
||||
Err(InstallError::InvalidTarget(target).into())
|
||||
}
|
||||
|
|
|
@ -710,7 +710,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
.map(|v| v.map(Path::new).collect())
|
||||
.unwrap_or_else(|| vec![Path::new(".")]);
|
||||
|
||||
list(locs, config)
|
||||
list(locs, &config)
|
||||
}
|
||||
|
||||
pub fn uu_app<'a>() -> App<'a> {
|
||||
|
@ -1407,14 +1407,14 @@ impl PathData {
|
|||
}
|
||||
}
|
||||
|
||||
fn list(locs: Vec<&Path>, config: Config) -> UResult<()> {
|
||||
fn list(locs: Vec<&Path>, config: &Config) -> UResult<()> {
|
||||
let mut files = Vec::<PathData>::new();
|
||||
let mut dirs = Vec::<PathData>::new();
|
||||
let mut out = BufWriter::new(stdout());
|
||||
let initial_locs_len = locs.len();
|
||||
|
||||
for loc in locs {
|
||||
let path_data = PathData::new(PathBuf::from(loc), None, None, &config, true);
|
||||
let path_data = PathData::new(PathBuf::from(loc), None, None, config, true);
|
||||
|
||||
// Getting metadata here is no big deal as it's just the CWD
|
||||
// and we really just want to know if the strings exist as files/dirs
|
||||
|
@ -1441,10 +1441,10 @@ fn list(locs: Vec<&Path>, config: Config) -> UResult<()> {
|
|||
}
|
||||
}
|
||||
|
||||
sort_entries(&mut files, &config, &mut out);
|
||||
sort_entries(&mut dirs, &config, &mut out);
|
||||
sort_entries(&mut files, config, &mut out);
|
||||
sort_entries(&mut dirs, config, &mut out);
|
||||
|
||||
display_items(&files, &config, &mut out);
|
||||
display_items(&files, config, &mut out);
|
||||
|
||||
for (pos, path_data) in dirs.iter().enumerate() {
|
||||
// Do read_dir call here to match GNU semantics by printing
|
||||
|
@ -1467,7 +1467,7 @@ fn list(locs: Vec<&Path>, config: Config) -> UResult<()> {
|
|||
let _ = writeln!(out, "\n{}:", path_data.p_buf.display());
|
||||
}
|
||||
}
|
||||
enter_directory(path_data, read_dir, &config, &mut out);
|
||||
enter_directory(path_data, read_dir, config, &mut out);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -1749,7 +1749,7 @@ fn display_items(items: &[PathData], config: &Config, out: &mut BufWriter<Stdout
|
|||
for item in items {
|
||||
display_item_long(
|
||||
item,
|
||||
PaddingCollection {
|
||||
&PaddingCollection {
|
||||
#[cfg(unix)]
|
||||
longest_inode_len,
|
||||
longest_link_count_len,
|
||||
|
@ -1930,7 +1930,7 @@ fn display_grid(
|
|||
#[allow(clippy::write_literal)]
|
||||
fn display_item_long(
|
||||
item: &PathData,
|
||||
padding: PaddingCollection,
|
||||
padding: &PaddingCollection,
|
||||
config: &Config,
|
||||
out: &mut BufWriter<Stdout>,
|
||||
) {
|
||||
|
@ -2251,7 +2251,7 @@ fn display_date(metadata: &Metadata, config: &Config) -> String {
|
|||
// 3. The human-readable format uses powers for 1024, but does not display the "i"
|
||||
// that is commonly used to denote Kibi, Mebi, etc.
|
||||
// 4. Kibi and Kilo are denoted differently ("k" and "K", respectively)
|
||||
fn format_prefixed(prefixed: NumberPrefix<f64>) -> String {
|
||||
fn format_prefixed(prefixed: &NumberPrefix<f64>) -> String {
|
||||
match prefixed {
|
||||
NumberPrefix::Standalone(bytes) => bytes.to_string(),
|
||||
NumberPrefix::Prefixed(prefix, bytes) => {
|
||||
|
@ -2304,8 +2304,8 @@ fn display_size(size: u64, config: &Config) -> String {
|
|||
// NOTE: The human-readable behavior deviates from the GNU ls.
|
||||
// The GNU ls uses binary prefixes by default.
|
||||
match config.size_format {
|
||||
SizeFormat::Binary => format_prefixed(NumberPrefix::binary(size as f64)),
|
||||
SizeFormat::Decimal => format_prefixed(NumberPrefix::decimal(size as f64)),
|
||||
SizeFormat::Binary => format_prefixed(&NumberPrefix::binary(size as f64)),
|
||||
SizeFormat::Decimal => format_prefixed(&NumberPrefix::decimal(size as f64)),
|
||||
SizeFormat::Bytes => size.to_string(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -363,7 +363,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_names(name: &str, map: Vec<(&str, &str)>) {
|
||||
fn check_names(name: &str, map: &[(&str, &str)]) {
|
||||
assert_eq!(
|
||||
map.iter()
|
||||
.map(|(_, style)| escape_name(name.as_ref(), &get_style(style)))
|
||||
|
@ -378,7 +378,7 @@ mod tests {
|
|||
fn test_simple_names() {
|
||||
check_names(
|
||||
"one_two",
|
||||
vec![
|
||||
&[
|
||||
("one_two", "literal"),
|
||||
("one_two", "literal-show"),
|
||||
("one_two", "escape"),
|
||||
|
@ -397,7 +397,7 @@ mod tests {
|
|||
fn test_spaces() {
|
||||
check_names(
|
||||
"one two",
|
||||
vec![
|
||||
&[
|
||||
("one two", "literal"),
|
||||
("one two", "literal-show"),
|
||||
("one\\ two", "escape"),
|
||||
|
@ -413,7 +413,7 @@ mod tests {
|
|||
|
||||
check_names(
|
||||
" one",
|
||||
vec![
|
||||
&[
|
||||
(" one", "literal"),
|
||||
(" one", "literal-show"),
|
||||
("\\ one", "escape"),
|
||||
|
@ -433,7 +433,7 @@ mod tests {
|
|||
// One double quote
|
||||
check_names(
|
||||
"one\"two",
|
||||
vec![
|
||||
&[
|
||||
("one\"two", "literal"),
|
||||
("one\"two", "literal-show"),
|
||||
("one\"two", "escape"),
|
||||
|
@ -450,7 +450,7 @@ mod tests {
|
|||
// One single quote
|
||||
check_names(
|
||||
"one\'two",
|
||||
vec![
|
||||
&[
|
||||
("one'two", "literal"),
|
||||
("one'two", "literal-show"),
|
||||
("one'two", "escape"),
|
||||
|
@ -467,7 +467,7 @@ mod tests {
|
|||
// One single quote and one double quote
|
||||
check_names(
|
||||
"one'two\"three",
|
||||
vec![
|
||||
&[
|
||||
("one'two\"three", "literal"),
|
||||
("one'two\"three", "literal-show"),
|
||||
("one'two\"three", "escape"),
|
||||
|
@ -484,7 +484,7 @@ mod tests {
|
|||
// Consecutive quotes
|
||||
check_names(
|
||||
"one''two\"\"three",
|
||||
vec![
|
||||
&[
|
||||
("one''two\"\"three", "literal"),
|
||||
("one''two\"\"three", "literal-show"),
|
||||
("one''two\"\"three", "escape"),
|
||||
|
@ -504,7 +504,7 @@ mod tests {
|
|||
// A simple newline
|
||||
check_names(
|
||||
"one\ntwo",
|
||||
vec![
|
||||
&[
|
||||
("one?two", "literal"),
|
||||
("one\ntwo", "literal-show"),
|
||||
("one\\ntwo", "escape"),
|
||||
|
@ -521,7 +521,7 @@ mod tests {
|
|||
// A control character followed by a special shell character
|
||||
check_names(
|
||||
"one\n&two",
|
||||
vec![
|
||||
&[
|
||||
("one?&two", "literal"),
|
||||
("one\n&two", "literal-show"),
|
||||
("one\\n&two", "escape"),
|
||||
|
@ -539,7 +539,7 @@ mod tests {
|
|||
// no importance for file names.
|
||||
check_names(
|
||||
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
|
||||
vec![
|
||||
&[
|
||||
("????????????????", "literal"),
|
||||
(
|
||||
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
|
||||
|
@ -577,7 +577,7 @@ mod tests {
|
|||
// The last 16 control characters.
|
||||
check_names(
|
||||
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F",
|
||||
vec![
|
||||
&[
|
||||
("????????????????", "literal"),
|
||||
(
|
||||
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F",
|
||||
|
@ -615,7 +615,7 @@ mod tests {
|
|||
// DEL
|
||||
check_names(
|
||||
"\x7F",
|
||||
vec![
|
||||
&[
|
||||
("?", "literal"),
|
||||
("\x7F", "literal-show"),
|
||||
("\\177", "escape"),
|
||||
|
@ -637,7 +637,7 @@ mod tests {
|
|||
// in other tests)
|
||||
check_names(
|
||||
"one?two",
|
||||
vec![
|
||||
&[
|
||||
("one?two", "literal"),
|
||||
("one?two", "literal-show"),
|
||||
("one?two", "escape"),
|
||||
|
@ -657,7 +657,7 @@ mod tests {
|
|||
// Escaped in C-style, but not in Shell-style escaping
|
||||
check_names(
|
||||
"one\\two",
|
||||
vec![
|
||||
&[
|
||||
("one\\two", "literal"),
|
||||
("one\\two", "literal-show"),
|
||||
("one\\\\two", "escape"),
|
||||
|
@ -672,34 +672,34 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_tilde_and_hash() {
|
||||
check_names("~", vec![("'~'", "shell"), ("'~'", "shell-escape")]);
|
||||
check_names("~", &[("'~'", "shell"), ("'~'", "shell-escape")]);
|
||||
check_names(
|
||||
"~name",
|
||||
vec![("'~name'", "shell"), ("'~name'", "shell-escape")],
|
||||
&[("'~name'", "shell"), ("'~name'", "shell-escape")],
|
||||
);
|
||||
check_names(
|
||||
"some~name",
|
||||
vec![("some~name", "shell"), ("some~name", "shell-escape")],
|
||||
&[("some~name", "shell"), ("some~name", "shell-escape")],
|
||||
);
|
||||
check_names("name~", vec![("name~", "shell"), ("name~", "shell-escape")]);
|
||||
check_names("name~", &[("name~", "shell"), ("name~", "shell-escape")]);
|
||||
|
||||
check_names("#", vec![("'#'", "shell"), ("'#'", "shell-escape")]);
|
||||
check_names("#", &[("'#'", "shell"), ("'#'", "shell-escape")]);
|
||||
check_names(
|
||||
"#name",
|
||||
vec![("'#name'", "shell"), ("'#name'", "shell-escape")],
|
||||
&[("'#name'", "shell"), ("'#name'", "shell-escape")],
|
||||
);
|
||||
check_names(
|
||||
"some#name",
|
||||
vec![("some#name", "shell"), ("some#name", "shell-escape")],
|
||||
&[("some#name", "shell"), ("some#name", "shell-escape")],
|
||||
);
|
||||
check_names("name#", vec![("name#", "shell"), ("name#", "shell-escape")]);
|
||||
check_names("name#", &[("name#", "shell"), ("name#", "shell-escape")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_special_chars_in_double_quotes() {
|
||||
check_names(
|
||||
"can'$t",
|
||||
vec![
|
||||
&[
|
||||
("'can'\\''$t'", "shell"),
|
||||
("'can'\\''$t'", "shell-always"),
|
||||
("'can'\\''$t'", "shell-escape"),
|
||||
|
@ -709,7 +709,7 @@ mod tests {
|
|||
|
||||
check_names(
|
||||
"can'`t",
|
||||
vec![
|
||||
&[
|
||||
("'can'\\''`t'", "shell"),
|
||||
("'can'\\''`t'", "shell-always"),
|
||||
("'can'\\''`t'", "shell-escape"),
|
||||
|
@ -719,7 +719,7 @@ mod tests {
|
|||
|
||||
check_names(
|
||||
"can'\\t",
|
||||
vec![
|
||||
&[
|
||||
("'can'\\''\\t'", "shell"),
|
||||
("'can'\\''\\t'", "shell-always"),
|
||||
("'can'\\''\\t'", "shell-escape"),
|
||||
|
|
|
@ -16,7 +16,7 @@ use std::env;
|
|||
use std::error::Error;
|
||||
use std::fmt::Display;
|
||||
use std::iter;
|
||||
use std::path::{is_separator, PathBuf};
|
||||
use std::path::{is_separator, Path, PathBuf};
|
||||
|
||||
use rand::Rng;
|
||||
use tempfile::Builder;
|
||||
|
@ -124,7 +124,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
let res = if dry_run {
|
||||
dry_exec(tmpdir, prefix, rand, suffix)
|
||||
} else {
|
||||
exec(tmpdir, prefix, rand, suffix, make_dir)
|
||||
exec(&tmpdir, prefix, rand, suffix, make_dir)
|
||||
};
|
||||
|
||||
if suppress_file_err {
|
||||
|
@ -249,7 +249,7 @@ pub fn dry_exec(mut tmpdir: PathBuf, prefix: &str, rand: usize, suffix: &str) ->
|
|||
println_verbatim(tmpdir).map_err_context(|| "failed to print directory name".to_owned())
|
||||
}
|
||||
|
||||
fn exec(dir: PathBuf, prefix: &str, rand: usize, suffix: &str, make_dir: bool) -> UResult<()> {
|
||||
fn exec(dir: &Path, prefix: &str, rand: usize, suffix: &str, make_dir: bool) -> UResult<()> {
|
||||
let context = || {
|
||||
format!(
|
||||
"failed to create file via template '{}{}{}'",
|
||||
|
|
|
@ -116,7 +116,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
strip_slashes: matches.is_present(OPT_STRIP_TRAILING_SLASHES),
|
||||
};
|
||||
|
||||
exec(&files[..], behavior)
|
||||
exec(&files[..], &behavior)
|
||||
}
|
||||
|
||||
pub fn uu_app<'a>() -> App<'a> {
|
||||
|
@ -207,7 +207,7 @@ fn determine_overwrite_mode(matches: &ArgMatches) -> OverwriteMode {
|
|||
}
|
||||
}
|
||||
|
||||
fn exec(files: &[OsString], b: Behavior) -> UResult<()> {
|
||||
fn exec(files: &[OsString], b: &Behavior) -> UResult<()> {
|
||||
let paths: Vec<PathBuf> = {
|
||||
let paths = files.iter().map(Path::new);
|
||||
|
||||
|
@ -222,7 +222,7 @@ fn exec(files: &[OsString], b: Behavior) -> UResult<()> {
|
|||
};
|
||||
|
||||
if let Some(ref name) = b.target_dir {
|
||||
return move_files_into_dir(&paths, &PathBuf::from(name), &b);
|
||||
return move_files_into_dir(&paths, &PathBuf::from(name), b);
|
||||
}
|
||||
match paths.len() {
|
||||
/* case 0/1 are not possible thanks to clap */
|
||||
|
@ -256,12 +256,12 @@ fn exec(files: &[OsString], b: Behavior) -> UResult<()> {
|
|||
if !source.is_dir() {
|
||||
Err(MvError::DirectoryToNonDirectory(target.quote().to_string()).into())
|
||||
} else {
|
||||
rename(source, target, &b).map_err_context(|| {
|
||||
rename(source, target, b).map_err_context(|| {
|
||||
format!("cannot move {} to {}", source.quote(), target.quote())
|
||||
})
|
||||
}
|
||||
} else {
|
||||
move_files_into_dir(&[source.clone()], target, &b)
|
||||
move_files_into_dir(&[source.clone()], target, b)
|
||||
}
|
||||
} else if target.exists() && source.is_dir() {
|
||||
Err(MvError::NonDirectoryToDirectory(
|
||||
|
@ -270,7 +270,7 @@ fn exec(files: &[OsString], b: Behavior) -> UResult<()> {
|
|||
)
|
||||
.into())
|
||||
} else {
|
||||
rename(source, target, &b).map_err(|e| USimpleError::new(1, format!("{}", e)))
|
||||
rename(source, target, b).map_err(|e| USimpleError::new(1, format!("{}", e)))
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
|
@ -281,7 +281,7 @@ fn exec(files: &[OsString], b: Behavior) -> UResult<()> {
|
|||
));
|
||||
}
|
||||
let target_dir = paths.last().unwrap();
|
||||
move_files_into_dir(&paths[..paths.len() - 1], target_dir, &b)
|
||||
move_files_into_dir(&paths[..paths.len() - 1], target_dir, b)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,9 +55,9 @@ fn usage() -> String {
|
|||
format!("{0} [OPTION]... [NUMBER]...", uucore::execution_phrase())
|
||||
}
|
||||
|
||||
fn handle_args<'a>(args: impl Iterator<Item = &'a str>, options: NumfmtOptions) -> UResult<()> {
|
||||
fn handle_args<'a>(args: impl Iterator<Item = &'a str>, options: &NumfmtOptions) -> UResult<()> {
|
||||
for l in args {
|
||||
match format_and_print(l, &options) {
|
||||
match format_and_print(l, options) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => Err(NumfmtError::FormattingError(e.to_string())),
|
||||
}?;
|
||||
|
@ -66,7 +66,7 @@ fn handle_args<'a>(args: impl Iterator<Item = &'a str>, options: NumfmtOptions)
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_buffer<R>(input: R, options: NumfmtOptions) -> UResult<()>
|
||||
fn handle_buffer<R>(input: R, options: &NumfmtOptions) -> UResult<()>
|
||||
where
|
||||
R: BufRead,
|
||||
{
|
||||
|
@ -77,7 +77,7 @@ where
|
|||
println!("{}", l);
|
||||
Ok(())
|
||||
}
|
||||
Ok(l) => match format_and_print(&l, &options) {
|
||||
Ok(l) => match format_and_print(&l, options) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => Err(NumfmtError::FormattingError(e.to_string())),
|
||||
},
|
||||
|
@ -173,11 +173,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
let options = parse_options(&matches).map_err(NumfmtError::IllegalArgument)?;
|
||||
|
||||
let result = match matches.values_of(options::NUMBER) {
|
||||
Some(values) => handle_args(values, options),
|
||||
Some(values) => handle_args(values, &options),
|
||||
None => {
|
||||
let stdin = std::io::stdin();
|
||||
let mut locked_stdin = stdin.lock();
|
||||
handle_buffer(&mut locked_stdin, options)
|
||||
handle_buffer(&mut locked_stdin, &options)
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -304,7 +304,7 @@ mod tests {
|
|||
#[test]
|
||||
fn broken_buffer_returns_io_error() {
|
||||
let mock_buffer = MockBuffer {};
|
||||
let result = handle_buffer(BufReader::new(mock_buffer), get_valid_options())
|
||||
let result = handle_buffer(BufReader::new(mock_buffer), &get_valid_options())
|
||||
.expect_err("returned Ok after receiving IO error");
|
||||
let result_debug = format!("{:?}", result);
|
||||
let result_display = format!("{}", result);
|
||||
|
@ -316,7 +316,7 @@ mod tests {
|
|||
#[test]
|
||||
fn non_numeric_returns_formatting_error() {
|
||||
let input_value = b"135\nhello";
|
||||
let result = handle_buffer(BufReader::new(&input_value[..]), get_valid_options())
|
||||
let result = handle_buffer(BufReader::new(&input_value[..]), &get_valid_options())
|
||||
.expect_err("returned Ok after receiving improperly formatted input");
|
||||
let result_debug = format!("{:?}", result);
|
||||
let result_display = format!("{}", result);
|
||||
|
@ -331,7 +331,7 @@ mod tests {
|
|||
#[test]
|
||||
fn valid_input_returns_ok() {
|
||||
let input_value = b"165\n100\n300\n500";
|
||||
let result = handle_buffer(BufReader::new(&input_value[..]), get_valid_options());
|
||||
let result = handle_buffer(BufReader::new(&input_value[..]), &get_valid_options());
|
||||
assert!(result.is_ok(), "did not return Ok for valid input");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ struct OdOptions {
|
|||
}
|
||||
|
||||
impl OdOptions {
|
||||
fn new(matches: ArgMatches, args: Vec<String>) -> UResult<OdOptions> {
|
||||
fn new(matches: &ArgMatches, args: &[String]) -> UResult<OdOptions> {
|
||||
let byte_order = match matches.value_of(options::ENDIAN) {
|
||||
None => ByteOrder::Native,
|
||||
Some("little") => ByteOrder::Little,
|
||||
|
@ -141,7 +141,7 @@ impl OdOptions {
|
|||
Err(e) => {
|
||||
return Err(USimpleError::new(
|
||||
1,
|
||||
format_error_message(e, s, options::SKIP_BYTES),
|
||||
format_error_message(&e, s, options::SKIP_BYTES),
|
||||
))
|
||||
}
|
||||
},
|
||||
|
@ -149,7 +149,7 @@ impl OdOptions {
|
|||
|
||||
let mut label: Option<usize> = None;
|
||||
|
||||
let parsed_input = parse_inputs(&matches)
|
||||
let parsed_input = parse_inputs(matches)
|
||||
.map_err(|e| USimpleError::new(1, format!("Invalid inputs: {}", e)))?;
|
||||
let input_strings = match parsed_input {
|
||||
CommandLineInputs::FileNames(v) => v,
|
||||
|
@ -160,7 +160,7 @@ impl OdOptions {
|
|||
}
|
||||
};
|
||||
|
||||
let formats = parse_format_flags(&args).map_err(|e| USimpleError::new(1, e))?;
|
||||
let formats = parse_format_flags(args).map_err(|e| USimpleError::new(1, e))?;
|
||||
|
||||
let mut line_bytes = match matches.value_of(options::WIDTH) {
|
||||
None => 16,
|
||||
|
@ -173,7 +173,7 @@ impl OdOptions {
|
|||
Err(e) => {
|
||||
return Err(USimpleError::new(
|
||||
1,
|
||||
format_error_message(e, s, options::WIDTH),
|
||||
format_error_message(&e, s, options::WIDTH),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ impl OdOptions {
|
|||
Err(e) => {
|
||||
return Err(USimpleError::new(
|
||||
1,
|
||||
format_error_message(e, s, options::READ_BYTES),
|
||||
format_error_message(&e, s, options::READ_BYTES),
|
||||
))
|
||||
}
|
||||
},
|
||||
|
@ -260,7 +260,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
.clone() // Clone to reuse clap_opts to print help
|
||||
.get_matches_from(args.clone());
|
||||
|
||||
let od_options = OdOptions::new(clap_matches, args)?;
|
||||
let od_options = OdOptions::new(&clap_matches, &args)?;
|
||||
|
||||
let mut input_offset =
|
||||
InputOffset::new(od_options.radix, od_options.skip_bytes, od_options.label);
|
||||
|
@ -664,7 +664,7 @@ fn open_input_peek_reader(
|
|||
PeekReader::new(pr)
|
||||
}
|
||||
|
||||
fn format_error_message(error: ParseSizeError, s: &str, option: &str) -> String {
|
||||
fn format_error_message(error: &ParseSizeError, s: &str, option: &str) -> String {
|
||||
// NOTE:
|
||||
// GNU's od echos affected flag, -N or --read-bytes (-j or --skip-bytes, etc.), depending user's selection
|
||||
// GNU's od does distinguish between "invalid (suffix in) argument"
|
||||
|
|
|
@ -46,7 +46,7 @@ pub fn parse_inputs(matches: &dyn CommandLineOpts) -> Result<CommandLineInputs,
|
|||
let mut input_strings = matches.inputs();
|
||||
|
||||
if matches.opts_present(&["traditional"]) {
|
||||
return parse_inputs_traditional(input_strings);
|
||||
return parse_inputs_traditional(&input_strings);
|
||||
}
|
||||
|
||||
// test if command line contains: [file] <offset>
|
||||
|
@ -91,7 +91,7 @@ pub fn parse_inputs(matches: &dyn CommandLineOpts) -> Result<CommandLineInputs,
|
|||
///
|
||||
/// normally returns CommandLineInputs::FileAndOffset, but if no offset is found,
|
||||
/// it returns CommandLineInputs::FileNames (also to differentiate from the offset == 0)
|
||||
pub fn parse_inputs_traditional(input_strings: Vec<&str>) -> Result<CommandLineInputs, String> {
|
||||
pub fn parse_inputs_traditional(input_strings: &[&str]) -> Result<CommandLineInputs, String> {
|
||||
match input_strings.len() {
|
||||
0 => Ok(CommandLineInputs::FileNames(vec!["-".to_string()])),
|
||||
1 => {
|
||||
|
|
|
@ -39,7 +39,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
let serial = matches.is_present(options::SERIAL);
|
||||
let delimiters = matches.value_of(options::DELIMITER).unwrap().to_owned();
|
||||
let delimiters = matches.value_of(options::DELIMITER).unwrap();
|
||||
let files = matches
|
||||
.values_of(options::FILE)
|
||||
.unwrap()
|
||||
|
@ -76,7 +76,7 @@ pub fn uu_app<'a>() -> App<'a> {
|
|||
)
|
||||
}
|
||||
|
||||
fn paste(filenames: Vec<String>, serial: bool, delimiters: String) -> UResult<()> {
|
||||
fn paste(filenames: Vec<String>, serial: bool, delimiters: &str) -> UResult<()> {
|
||||
let mut files = vec![];
|
||||
for name in filenames {
|
||||
let file = if name == "-" {
|
||||
|
@ -146,7 +146,7 @@ fn paste(filenames: Vec<String>, serial: bool, delimiters: String) -> UResult<()
|
|||
|
||||
// Unescape all special characters
|
||||
// TODO: this will need work to conform to GNU implementation
|
||||
fn unescape(s: String) -> String {
|
||||
fn unescape(s: &str) -> String {
|
||||
s.replace("\\n", "\n")
|
||||
.replace("\\t", "\t")
|
||||
.replace("\\\\", "\\")
|
||||
|
|
|
@ -409,11 +409,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
};
|
||||
|
||||
for file_group in file_groups {
|
||||
let result_options = build_options(&matches, &file_group, args.join(" "));
|
||||
let result_options = build_options(&matches, &file_group, &args.join(" "));
|
||||
let options = match result_options {
|
||||
Ok(options) => options,
|
||||
Err(err) => {
|
||||
print_error(&matches, err);
|
||||
print_error(&matches, &err);
|
||||
return Err(1.into());
|
||||
}
|
||||
};
|
||||
|
@ -426,7 +426,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
|
||||
let status = match cmd_result {
|
||||
Err(error) => {
|
||||
print_error(&matches, error);
|
||||
print_error(&matches, &error);
|
||||
1
|
||||
}
|
||||
_ => 0,
|
||||
|
@ -465,7 +465,7 @@ fn recreate_arguments(args: &[String]) -> Vec<String> {
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn print_error(matches: &Matches, err: PrError) {
|
||||
fn print_error(matches: &Matches, err: &PrError) {
|
||||
if !matches.opt_present(options::SUPPRESS_PRINTING_ERROR) {
|
||||
eprintln!("{}", err);
|
||||
}
|
||||
|
@ -531,7 +531,7 @@ fn parse_usize(matches: &Matches, opt: &str) -> Option<Result<usize, PrError>> {
|
|||
fn build_options(
|
||||
matches: &Matches,
|
||||
paths: &[String],
|
||||
free_args: String,
|
||||
free_args: &str,
|
||||
) -> Result<OutputOptions, PrError> {
|
||||
let form_feed_used = matches.opt_present(options::FORM_FEED_OPTION)
|
||||
|| matches.opt_present(options::FORM_FEED_OPTION_SMALL);
|
||||
|
@ -617,7 +617,7 @@ fn build_options(
|
|||
|
||||
// +page option is less priority than --pages
|
||||
let page_plus_re = Regex::new(r"\s*\+(\d+:*\d*)\s*").unwrap();
|
||||
let start_page_in_plus_option = match page_plus_re.captures(&free_args).map(|i| {
|
||||
let start_page_in_plus_option = match page_plus_re.captures(free_args).map(|i| {
|
||||
let unparsed_num = i.get(1).unwrap().as_str().trim();
|
||||
let x: Vec<_> = unparsed_num.split(':').collect();
|
||||
x[0].to_string().parse::<usize>().map_err(|_e| {
|
||||
|
@ -629,7 +629,7 @@ fn build_options(
|
|||
};
|
||||
|
||||
let end_page_in_plus_option = match page_plus_re
|
||||
.captures(&free_args)
|
||||
.captures(free_args)
|
||||
.map(|i| i.get(1).unwrap().as_str().trim())
|
||||
.filter(|i| i.contains(':'))
|
||||
.map(|unparsed_num| {
|
||||
|
@ -747,7 +747,7 @@ fn build_options(
|
|||
|
||||
let re_col = Regex::new(r"\s*-(\d+)\s*").unwrap();
|
||||
|
||||
let start_column_option = match re_col.captures(&free_args).map(|i| {
|
||||
let start_column_option = match re_col.captures(free_args).map(|i| {
|
||||
let unparsed_num = i.get(1).unwrap().as_str().trim();
|
||||
unparsed_num.parse::<usize>().map_err(|_e| {
|
||||
PrError::EncounteredErrors(format!("invalid {} argument {}", "-", unparsed_num.quote()))
|
||||
|
|
|
@ -138,7 +138,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
}
|
||||
}
|
||||
|
||||
if remove(files, options) {
|
||||
if remove(&files, &options) {
|
||||
return Err(1.into());
|
||||
}
|
||||
}
|
||||
|
@ -236,19 +236,19 @@ pub fn uu_app<'a>() -> App<'a> {
|
|||
}
|
||||
|
||||
// TODO: implement one-file-system (this may get partially implemented in walkdir)
|
||||
fn remove(files: Vec<String>, options: Options) -> bool {
|
||||
fn remove(files: &[String], options: &Options) -> bool {
|
||||
let mut had_err = false;
|
||||
|
||||
for filename in &files {
|
||||
for filename in files {
|
||||
let file = Path::new(filename);
|
||||
had_err = match file.symlink_metadata() {
|
||||
Ok(metadata) => {
|
||||
if metadata.is_dir() {
|
||||
handle_dir(file, &options)
|
||||
handle_dir(file, options)
|
||||
} else if is_symlink_dir(&metadata) {
|
||||
remove_dir(file, &options)
|
||||
remove_dir(file, options)
|
||||
} else {
|
||||
remove_file(file, &options)
|
||||
remove_file(file, options)
|
||||
}
|
||||
}
|
||||
Err(_e) => {
|
||||
|
|
|
@ -73,7 +73,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
CommandLineMode::Print => print_current_context().map_err(|e| RunconError::new(e).into()),
|
||||
CommandLineMode::PlainContext { context, command } => {
|
||||
get_plain_context(context)
|
||||
.and_then(set_next_exec_context)
|
||||
.and_then(|ctx| set_next_exec_context(&ctx))
|
||||
.map_err(RunconError::new)?;
|
||||
// On successful execution, the following call never returns,
|
||||
// and this process image is replaced.
|
||||
|
@ -97,7 +97,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
range.as_deref(),
|
||||
command,
|
||||
)
|
||||
.and_then(set_next_exec_context)
|
||||
.and_then(|ctx| set_next_exec_context(&ctx))
|
||||
.map_err(RunconError::new)?;
|
||||
// On successful execution, the following call never returns,
|
||||
// and this process image is replaced.
|
||||
|
@ -277,7 +277,7 @@ fn print_current_context() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn set_next_exec_context(context: OpaqueSecurityContext) -> Result<()> {
|
||||
fn set_next_exec_context(context: &OpaqueSecurityContext) -> Result<()> {
|
||||
let c_context = context
|
||||
.to_c_string()
|
||||
.map_err(|r| Error::from_selinux("Creating new context", r))?;
|
||||
|
|
|
@ -115,8 +115,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
let last = last.round_towards(&first);
|
||||
print_seq_integers(
|
||||
(first, increment, last),
|
||||
options.separator,
|
||||
options.terminator,
|
||||
&options.separator,
|
||||
&options.terminator,
|
||||
options.widths,
|
||||
padding,
|
||||
options.format,
|
||||
|
@ -129,8 +129,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
last.into_extended_big_decimal(),
|
||||
),
|
||||
largest_dec,
|
||||
options.separator,
|
||||
options.terminator,
|
||||
&options.separator,
|
||||
&options.terminator,
|
||||
options.widths,
|
||||
padding,
|
||||
options.format,
|
||||
|
@ -265,8 +265,8 @@ fn write_value_int(
|
|||
fn print_seq(
|
||||
range: RangeFloat,
|
||||
largest_dec: usize,
|
||||
separator: String,
|
||||
terminator: String,
|
||||
separator: &str,
|
||||
terminator: &str,
|
||||
pad: bool,
|
||||
padding: usize,
|
||||
format: Option<&str>,
|
||||
|
@ -336,8 +336,8 @@ fn print_seq(
|
|||
/// numbers). Only set this to `true` if `first` is actually zero.
|
||||
fn print_seq_integers(
|
||||
range: RangeInt,
|
||||
separator: String,
|
||||
terminator: String,
|
||||
separator: &str,
|
||||
terminator: &str,
|
||||
pad: bool,
|
||||
padding: usize,
|
||||
format: Option<&str>,
|
||||
|
|
|
@ -38,8 +38,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
|
||||
|
||||
if let Some(values) = matches.values_of(options::NUMBER) {
|
||||
let numbers = values.collect();
|
||||
return sleep(numbers);
|
||||
let numbers = values.collect::<Vec<_>>();
|
||||
return sleep(&numbers);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -61,7 +61,7 @@ pub fn uu_app<'a>() -> App<'a> {
|
|||
)
|
||||
}
|
||||
|
||||
fn sleep(args: Vec<&str>) -> UResult<()> {
|
||||
fn sleep(args: &[&str]) -> UResult<()> {
|
||||
let sleep_dur =
|
||||
args.iter().try_fold(
|
||||
Duration::new(0, 0),
|
||||
|
|
|
@ -40,7 +40,7 @@ pub fn check(path: &OsStr, settings: &GlobalSettings) -> UResult<()> {
|
|||
let (loaded_sender, loaded_receiver) = sync_channel(2);
|
||||
thread::spawn({
|
||||
let settings = settings.clone();
|
||||
move || reader(file, recycled_receiver, loaded_sender, &settings)
|
||||
move || reader(file, &recycled_receiver, &loaded_sender, &settings)
|
||||
});
|
||||
for _ in 0..2 {
|
||||
let _ = recycled_sender.send(RecycledChunk::new(if settings.buffer_size < 100 * 1024 {
|
||||
|
@ -102,14 +102,14 @@ pub fn check(path: &OsStr, settings: &GlobalSettings) -> UResult<()> {
|
|||
/// The function running on the reader thread.
|
||||
fn reader(
|
||||
mut file: Box<dyn Read + Send>,
|
||||
receiver: Receiver<RecycledChunk>,
|
||||
sender: SyncSender<Chunk>,
|
||||
receiver: &Receiver<RecycledChunk>,
|
||||
sender: &SyncSender<Chunk>,
|
||||
settings: &GlobalSettings,
|
||||
) -> UResult<()> {
|
||||
let mut carry_over = vec![];
|
||||
for recycled_chunk in receiver.iter() {
|
||||
let should_continue = chunks::read(
|
||||
&sender,
|
||||
sender,
|
||||
recycled_chunk,
|
||||
None,
|
||||
&mut carry_over,
|
||||
|
|
|
@ -50,13 +50,13 @@ pub fn ext_sort(
|
|||
let (recycled_sender, recycled_receiver) = std::sync::mpsc::sync_channel(1);
|
||||
thread::spawn({
|
||||
let settings = settings.clone();
|
||||
move || sorter(recycled_receiver, sorted_sender, settings)
|
||||
move || sorter(&recycled_receiver, &sorted_sender, &settings)
|
||||
});
|
||||
if settings.compress_prog.is_some() {
|
||||
reader_writer::<_, WriteableCompressedTmpFile>(
|
||||
files,
|
||||
settings,
|
||||
sorted_receiver,
|
||||
&sorted_receiver,
|
||||
recycled_sender,
|
||||
output,
|
||||
tmp_dir,
|
||||
|
@ -65,7 +65,7 @@ pub fn ext_sort(
|
|||
reader_writer::<_, WriteablePlainTmpFile>(
|
||||
files,
|
||||
settings,
|
||||
sorted_receiver,
|
||||
&sorted_receiver,
|
||||
recycled_sender,
|
||||
output,
|
||||
tmp_dir,
|
||||
|
@ -79,7 +79,7 @@ fn reader_writer<
|
|||
>(
|
||||
files: F,
|
||||
settings: &GlobalSettings,
|
||||
receiver: Receiver<Chunk>,
|
||||
receiver: &Receiver<Chunk>,
|
||||
sender: SyncSender<Chunk>,
|
||||
output: Output,
|
||||
tmp_dir: &mut TmpDirWrapper,
|
||||
|
@ -156,10 +156,10 @@ fn reader_writer<
|
|||
}
|
||||
|
||||
/// The function that is executed on the sorter thread.
|
||||
fn sorter(receiver: Receiver<Chunk>, sender: SyncSender<Chunk>, settings: GlobalSettings) {
|
||||
fn sorter(receiver: &Receiver<Chunk>, sender: &SyncSender<Chunk>, settings: &GlobalSettings) {
|
||||
while let Ok(mut payload) = receiver.recv() {
|
||||
payload.with_contents_mut(|contents| {
|
||||
sort_by(&mut contents.lines, &settings, &contents.line_data)
|
||||
sort_by(&mut contents.lines, settings, &contents.line_data)
|
||||
});
|
||||
if sender.send(payload).is_err() {
|
||||
// The receiver has gone away, likely because the other thread hit an error.
|
||||
|
@ -187,7 +187,7 @@ fn read_write_loop<I: WriteableTmpFile>(
|
|||
separator: u8,
|
||||
buffer_size: usize,
|
||||
settings: &GlobalSettings,
|
||||
receiver: Receiver<Chunk>,
|
||||
receiver: &Receiver<Chunk>,
|
||||
sender: SyncSender<Chunk>,
|
||||
) -> UResult<ReadResult<I>> {
|
||||
let mut file = files.next().unwrap()?;
|
||||
|
|
|
@ -166,7 +166,7 @@ fn merge_without_limit<M: MergeInput + 'static, F: Iterator<Item = UResult<M>>>(
|
|||
let settings = settings.clone();
|
||||
move || {
|
||||
reader(
|
||||
request_receiver,
|
||||
&request_receiver,
|
||||
&mut reader_files,
|
||||
&settings,
|
||||
if settings.zero_terminated {
|
||||
|
@ -210,7 +210,7 @@ struct ReaderFile<M: MergeInput> {
|
|||
|
||||
/// The function running on the reader thread.
|
||||
fn reader(
|
||||
recycled_receiver: Receiver<(usize, RecycledChunk)>,
|
||||
recycled_receiver: &Receiver<(usize, RecycledChunk)>,
|
||||
files: &mut [Option<ReaderFile<impl MergeInput>>],
|
||||
settings: &GlobalSettings,
|
||||
separator: u8,
|
||||
|
|
|
@ -52,7 +52,7 @@ impl NumInfo {
|
|||
/// an empty range (idx..idx) is returned so that idx is the char after the last zero.
|
||||
/// If the input is not a number (which has to be treated as zero), the returned empty range
|
||||
/// will be 0..0.
|
||||
pub fn parse(num: &str, parse_settings: NumInfoParseSettings) -> (Self, Range<usize>) {
|
||||
pub fn parse(num: &str, parse_settings: &NumInfoParseSettings) -> (Self, Range<usize>) {
|
||||
let mut exponent = -1;
|
||||
let mut had_decimal_pt = false;
|
||||
let mut had_digit = false;
|
||||
|
@ -80,7 +80,7 @@ impl NumInfo {
|
|||
continue;
|
||||
}
|
||||
|
||||
if Self::is_invalid_char(char, &mut had_decimal_pt, &parse_settings) {
|
||||
if Self::is_invalid_char(char, &mut had_decimal_pt, parse_settings) {
|
||||
return if let Some(start) = start {
|
||||
let has_si_unit = parse_settings.accept_si_units
|
||||
&& matches!(char, 'K' | 'k' | 'M' | 'G' | 'T' | 'P' | 'E' | 'Z' | 'Y');
|
||||
|
@ -270,7 +270,7 @@ mod tests {
|
|||
fn parses_exp() {
|
||||
let n = "1";
|
||||
assert_eq!(
|
||||
NumInfo::parse(n, Default::default()),
|
||||
NumInfo::parse(n, &Default::default()),
|
||||
(
|
||||
NumInfo {
|
||||
exponent: 0,
|
||||
|
@ -281,7 +281,7 @@ mod tests {
|
|||
);
|
||||
let n = "100";
|
||||
assert_eq!(
|
||||
NumInfo::parse(n, Default::default()),
|
||||
NumInfo::parse(n, &Default::default()),
|
||||
(
|
||||
NumInfo {
|
||||
exponent: 2,
|
||||
|
@ -294,7 +294,7 @@ mod tests {
|
|||
assert_eq!(
|
||||
NumInfo::parse(
|
||||
n,
|
||||
NumInfoParseSettings {
|
||||
&NumInfoParseSettings {
|
||||
thousands_separator: Some(','),
|
||||
..Default::default()
|
||||
}
|
||||
|
@ -309,7 +309,7 @@ mod tests {
|
|||
);
|
||||
let n = "1,000";
|
||||
assert_eq!(
|
||||
NumInfo::parse(n, Default::default()),
|
||||
NumInfo::parse(n, &Default::default()),
|
||||
(
|
||||
NumInfo {
|
||||
exponent: 0,
|
||||
|
@ -320,7 +320,7 @@ mod tests {
|
|||
);
|
||||
let n = "1000.00";
|
||||
assert_eq!(
|
||||
NumInfo::parse(n, Default::default()),
|
||||
NumInfo::parse(n, &Default::default()),
|
||||
(
|
||||
NumInfo {
|
||||
exponent: 3,
|
||||
|
@ -334,7 +334,7 @@ mod tests {
|
|||
fn parses_negative_exp() {
|
||||
let n = "0.00005";
|
||||
assert_eq!(
|
||||
NumInfo::parse(n, Default::default()),
|
||||
NumInfo::parse(n, &Default::default()),
|
||||
(
|
||||
NumInfo {
|
||||
exponent: -5,
|
||||
|
@ -345,7 +345,7 @@ mod tests {
|
|||
);
|
||||
let n = "00000.00005";
|
||||
assert_eq!(
|
||||
NumInfo::parse(n, Default::default()),
|
||||
NumInfo::parse(n, &Default::default()),
|
||||
(
|
||||
NumInfo {
|
||||
exponent: -5,
|
||||
|
@ -360,7 +360,7 @@ mod tests {
|
|||
fn parses_sign() {
|
||||
let n = "5";
|
||||
assert_eq!(
|
||||
NumInfo::parse(n, Default::default()),
|
||||
NumInfo::parse(n, &Default::default()),
|
||||
(
|
||||
NumInfo {
|
||||
exponent: 0,
|
||||
|
@ -371,7 +371,7 @@ mod tests {
|
|||
);
|
||||
let n = "-5";
|
||||
assert_eq!(
|
||||
NumInfo::parse(n, Default::default()),
|
||||
NumInfo::parse(n, &Default::default()),
|
||||
(
|
||||
NumInfo {
|
||||
exponent: 0,
|
||||
|
@ -382,7 +382,7 @@ mod tests {
|
|||
);
|
||||
let n = " -5";
|
||||
assert_eq!(
|
||||
NumInfo::parse(n, Default::default()),
|
||||
NumInfo::parse(n, &Default::default()),
|
||||
(
|
||||
NumInfo {
|
||||
exponent: 0,
|
||||
|
@ -394,8 +394,8 @@ mod tests {
|
|||
}
|
||||
|
||||
fn test_helper(a: &str, b: &str, expected: Ordering) {
|
||||
let (a_info, a_range) = NumInfo::parse(a, Default::default());
|
||||
let (b_info, b_range) = NumInfo::parse(b, Default::default());
|
||||
let (a_info, a_range) = NumInfo::parse(a, &Default::default());
|
||||
let (b_info, b_range) = NumInfo::parse(b, &Default::default());
|
||||
let ordering = numeric_str_cmp(
|
||||
(&a[a_range.to_owned()], &a_info),
|
||||
(&b[b_range.to_owned()], &b_info),
|
||||
|
@ -470,7 +470,7 @@ mod tests {
|
|||
}
|
||||
#[test]
|
||||
fn single_minus() {
|
||||
let info = NumInfo::parse("-", Default::default());
|
||||
let info = NumInfo::parse("-", &Default::default());
|
||||
assert_eq!(
|
||||
info,
|
||||
(
|
||||
|
@ -486,7 +486,7 @@ mod tests {
|
|||
fn invalid_with_unit() {
|
||||
let info = NumInfo::parse(
|
||||
"-K",
|
||||
NumInfoParseSettings {
|
||||
&NumInfoParseSettings {
|
||||
accept_si_units: true,
|
||||
..Default::default()
|
||||
},
|
||||
|
|
|
@ -578,7 +578,7 @@ impl<'a> Line<'a> {
|
|||
// find out which range is used for numeric comparisons
|
||||
let (_, num_range) = NumInfo::parse(
|
||||
&self.line[selection.clone()],
|
||||
NumInfoParseSettings {
|
||||
&NumInfoParseSettings {
|
||||
accept_si_units: selector.settings.mode == SortMode::HumanNumeric,
|
||||
..Default::default()
|
||||
},
|
||||
|
@ -927,7 +927,7 @@ impl FieldSelector {
|
|||
// Parse NumInfo for this number.
|
||||
let (info, num_range) = NumInfo::parse(
|
||||
range,
|
||||
NumInfoParseSettings {
|
||||
&NumInfoParseSettings {
|
||||
accept_si_units: self.settings.mode == SortMode::HumanNumeric,
|
||||
..Default::default()
|
||||
},
|
||||
|
@ -1156,7 +1156,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
.value_of(options::BUF_SIZE)
|
||||
.map_or(Ok(DEFAULT_BUF_SIZE), |s| {
|
||||
GlobalSettings::parse_byte_count(s).map_err(|e| {
|
||||
USimpleError::new(2, format_error_message(e, s, options::BUF_SIZE))
|
||||
USimpleError::new(2, format_error_message(&e, s, options::BUF_SIZE))
|
||||
})
|
||||
})?;
|
||||
|
||||
|
@ -1829,7 +1829,7 @@ fn open(path: impl AsRef<OsStr>) -> UResult<Box<dyn Read + Send>> {
|
|||
}
|
||||
}
|
||||
|
||||
fn format_error_message(error: ParseSizeError, s: &str, option: &str) -> String {
|
||||
fn format_error_message(error: &ParseSizeError, s: &str, option: &str) -> String {
|
||||
// NOTE:
|
||||
// GNU's sort echos affected flag, -S or --buffer-size, depending user's selection
|
||||
// GNU's sort does distinguish between "invalid (suffix in) argument"
|
||||
|
|
|
@ -62,7 +62,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
.after_help(&long_usage[..])
|
||||
.get_matches_from(args);
|
||||
let settings = Settings::from(matches)?;
|
||||
split(settings)
|
||||
split(&settings)
|
||||
}
|
||||
|
||||
pub fn uu_app<'a>() -> App<'a> {
|
||||
|
@ -436,7 +436,7 @@ where
|
|||
.map_err_context(|| "I/O error".to_string())
|
||||
}
|
||||
|
||||
fn split(settings: Settings) -> UResult<()> {
|
||||
fn split(settings: &Settings) -> UResult<()> {
|
||||
let mut reader = BufReader::new(if settings.input == "-" {
|
||||
Box::new(stdin()) as Box<dyn Read>
|
||||
} else {
|
||||
|
@ -450,7 +450,7 @@ fn split(settings: Settings) -> UResult<()> {
|
|||
});
|
||||
|
||||
if let Strategy::Number(num_chunks) = settings.strategy {
|
||||
return split_into_n_chunks_by_byte(&settings, &mut reader, num_chunks);
|
||||
return split_into_n_chunks_by_byte(settings, &mut reader, num_chunks);
|
||||
}
|
||||
|
||||
let mut splitter: Box<dyn Splitter> = match settings.strategy {
|
||||
|
|
|
@ -219,7 +219,7 @@ pub struct Stater {
|
|||
}
|
||||
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
fn print_it(arg: &str, output_type: OutputType, flag: u8, width: usize, precision: i32) {
|
||||
fn print_it(arg: &str, output_type: &OutputType, flag: u8, width: usize, precision: i32) {
|
||||
// If the precision is given as just '.', the precision is taken to be zero.
|
||||
// A negative precision is taken as if the precision were omitted.
|
||||
// This gives the minimum number of digits to appear for d, i, o, u, x, and X conversions,
|
||||
|
@ -250,7 +250,7 @@ fn print_it(arg: &str, output_type: OutputType, flag: u8, width: usize, precisio
|
|||
// By default, a sign is used only for negative numbers.
|
||||
// A + overrides a space if both are used.
|
||||
|
||||
if output_type == OutputType::Unknown {
|
||||
if output_type == &OutputType::Unknown {
|
||||
return print!("?");
|
||||
}
|
||||
|
||||
|
@ -461,7 +461,7 @@ impl Stater {
|
|||
Ok(tokens)
|
||||
}
|
||||
|
||||
fn new(matches: ArgMatches) -> UResult<Stater> {
|
||||
fn new(matches: &ArgMatches) -> UResult<Stater> {
|
||||
let files: Vec<String> = matches
|
||||
.values_of(ARG_FILES)
|
||||
.map(|v| v.map(ToString::to_string).collect())
|
||||
|
@ -743,7 +743,7 @@ impl Stater {
|
|||
output_type = OutputType::Unknown;
|
||||
}
|
||||
}
|
||||
print_it(&arg, output_type, flag, width, precision);
|
||||
print_it(&arg, &output_type, flag, width, precision);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -836,7 +836,7 @@ impl Stater {
|
|||
}
|
||||
}
|
||||
|
||||
print_it(&arg, output_type, flag, width, precision);
|
||||
print_it(&arg, &output_type, flag, width, precision);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -957,7 +957,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
.after_help(&long_usage[..])
|
||||
.get_matches_from(args);
|
||||
|
||||
let stater = Stater::new(matches)?;
|
||||
let stater = Stater::new(&matches)?;
|
||||
let exit_status = stater.exec();
|
||||
if exit_status == 0 {
|
||||
Ok(())
|
||||
|
|
|
@ -127,7 +127,7 @@ fn check_option(matches: &ArgMatches, name: &str) -> Result<BufferType, ProgramO
|
|||
}
|
||||
}
|
||||
|
||||
fn set_command_env(command: &mut Command, buffer_name: &str, buffer_type: BufferType) {
|
||||
fn set_command_env(command: &mut Command, buffer_name: &str, buffer_type: &BufferType) {
|
||||
match buffer_type {
|
||||
BufferType::Size(m) => {
|
||||
command.env(buffer_name, m.to_string());
|
||||
|
@ -167,9 +167,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
let mut tmp_dir = tempdir().unwrap();
|
||||
let (preload_env, libstdbuf) = get_preload_env(&mut tmp_dir).map_err_context(String::new)?;
|
||||
command.env(preload_env, libstdbuf);
|
||||
set_command_env(&mut command, "_STDBUF_I", options.stdin);
|
||||
set_command_env(&mut command, "_STDBUF_O", options.stdout);
|
||||
set_command_env(&mut command, "_STDBUF_E", options.stderr);
|
||||
set_command_env(&mut command, "_STDBUF_I", &options.stdin);
|
||||
set_command_env(&mut command, "_STDBUF_O", &options.stdout);
|
||||
set_command_env(&mut command, "_STDBUF_E", &options.stderr);
|
||||
command.args(command_params);
|
||||
|
||||
let mut process = command
|
||||
|
|
|
@ -57,7 +57,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
None => vec!["-"],
|
||||
};
|
||||
|
||||
tac(files, before, regex, separator)
|
||||
tac(&files, before, regex, separator)
|
||||
}
|
||||
|
||||
pub fn uu_app<'a>() -> App<'a> {
|
||||
|
@ -223,7 +223,7 @@ fn buffer_tac(data: &[u8], before: bool, separator: &str) -> std::io::Result<()>
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn tac(filenames: Vec<&str>, before: bool, regex: bool, separator: &str) -> UResult<()> {
|
||||
fn tac(filenames: &[&str], before: bool, regex: bool, separator: &str) -> UResult<()> {
|
||||
// Compile the regular expression pattern if it is provided.
|
||||
let maybe_pattern = if regex {
|
||||
match regex::bytes::Regex::new(separator) {
|
||||
|
@ -234,7 +234,7 @@ fn tac(filenames: Vec<&str>, before: bool, regex: bool, separator: &str) -> URes
|
|||
None
|
||||
};
|
||||
|
||||
for &filename in &filenames {
|
||||
for &filename in filenames {
|
||||
let mmap;
|
||||
let buf;
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
.unwrap_or_default(),
|
||||
};
|
||||
|
||||
match tee(options) {
|
||||
match tee(&options) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err(1.into()),
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ fn ignore_interrupts() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn tee(options: Options) -> Result<()> {
|
||||
fn tee(options: &Options) -> Result<()> {
|
||||
if options.ignore_interrupts {
|
||||
ignore_interrupts()?
|
||||
}
|
||||
|
|
|
@ -188,25 +188,25 @@ fn eval(stack: &mut Vec<Symbol>) -> Result<bool, String> {
|
|||
let f = pop_literal!();
|
||||
|
||||
Ok(match op {
|
||||
"-b" => path(&f, PathCondition::BlockSpecial),
|
||||
"-c" => path(&f, PathCondition::CharacterSpecial),
|
||||
"-d" => path(&f, PathCondition::Directory),
|
||||
"-e" => path(&f, PathCondition::Exists),
|
||||
"-f" => path(&f, PathCondition::Regular),
|
||||
"-g" => path(&f, PathCondition::GroupIdFlag),
|
||||
"-G" => path(&f, PathCondition::GroupOwns),
|
||||
"-h" => path(&f, PathCondition::SymLink),
|
||||
"-k" => path(&f, PathCondition::Sticky),
|
||||
"-L" => path(&f, PathCondition::SymLink),
|
||||
"-O" => path(&f, PathCondition::UserOwns),
|
||||
"-p" => path(&f, PathCondition::Fifo),
|
||||
"-r" => path(&f, PathCondition::Readable),
|
||||
"-S" => path(&f, PathCondition::Socket),
|
||||
"-s" => path(&f, PathCondition::NonEmpty),
|
||||
"-b" => path(&f, &PathCondition::BlockSpecial),
|
||||
"-c" => path(&f, &PathCondition::CharacterSpecial),
|
||||
"-d" => path(&f, &PathCondition::Directory),
|
||||
"-e" => path(&f, &PathCondition::Exists),
|
||||
"-f" => path(&f, &PathCondition::Regular),
|
||||
"-g" => path(&f, &PathCondition::GroupIdFlag),
|
||||
"-G" => path(&f, &PathCondition::GroupOwns),
|
||||
"-h" => path(&f, &PathCondition::SymLink),
|
||||
"-k" => path(&f, &PathCondition::Sticky),
|
||||
"-L" => path(&f, &PathCondition::SymLink),
|
||||
"-O" => path(&f, &PathCondition::UserOwns),
|
||||
"-p" => path(&f, &PathCondition::Fifo),
|
||||
"-r" => path(&f, &PathCondition::Readable),
|
||||
"-S" => path(&f, &PathCondition::Socket),
|
||||
"-s" => path(&f, &PathCondition::NonEmpty),
|
||||
"-t" => isatty(&f)?,
|
||||
"-u" => path(&f, PathCondition::UserIdFlag),
|
||||
"-w" => path(&f, PathCondition::Writable),
|
||||
"-x" => path(&f, PathCondition::Executable),
|
||||
"-u" => path(&f, &PathCondition::UserIdFlag),
|
||||
"-w" => path(&f, &PathCondition::Writable),
|
||||
"-x" => path(&f, &PathCondition::Executable),
|
||||
_ => panic!(),
|
||||
})
|
||||
}
|
||||
|
@ -283,7 +283,7 @@ enum PathCondition {
|
|||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn path(path: &OsStr, condition: PathCondition) -> bool {
|
||||
fn path(path: &OsStr, condition: &PathCondition) -> bool {
|
||||
use std::fs::{self, Metadata};
|
||||
use std::os::unix::fs::{FileTypeExt, MetadataExt};
|
||||
|
||||
|
@ -325,7 +325,7 @@ fn path(path: &OsStr, condition: PathCondition) -> bool {
|
|||
}
|
||||
};
|
||||
|
||||
let metadata = if condition == PathCondition::SymLink {
|
||||
let metadata = if condition == &PathCondition::SymLink {
|
||||
fs::symlink_metadata(path)
|
||||
} else {
|
||||
fs::metadata(path)
|
||||
|
@ -362,7 +362,7 @@ fn path(path: &OsStr, condition: PathCondition) -> bool {
|
|||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn path(path: &OsStr, condition: PathCondition) -> bool {
|
||||
fn path(path: &OsStr, condition: &PathCondition) -> bool {
|
||||
use std::fs::metadata;
|
||||
|
||||
let stat = match metadata(path) {
|
||||
|
|
|
@ -57,7 +57,7 @@ struct Config {
|
|||
}
|
||||
|
||||
impl Config {
|
||||
fn from(options: clap::ArgMatches) -> Config {
|
||||
fn from(options: &clap::ArgMatches) -> Config {
|
||||
let signal = match options.value_of(options::SIGNAL) {
|
||||
Some(signal_) => {
|
||||
let signal_result = signal_by_name_or_value(signal_);
|
||||
|
@ -112,7 +112,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
|
||||
let matches = app.get_matches_from(args);
|
||||
|
||||
let config = Config::from(matches);
|
||||
let config = Config::from(&matches);
|
||||
timeout(
|
||||
&config.command,
|
||||
config.duration,
|
||||
|
|
|
@ -27,8 +27,8 @@ fn parse_octal(input: &str) -> IResult<&str, char> {
|
|||
)(input)
|
||||
}
|
||||
|
||||
pub fn reduce_octal_to_char(input: String) -> String {
|
||||
let result = many0(alt((parse_octal, anychar)))(input.as_str())
|
||||
pub fn reduce_octal_to_char(input: &str) -> String {
|
||||
let result = many0(alt((parse_octal, anychar)))(input)
|
||||
.map(|(_, r)| r)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
|
|
|
@ -64,7 +64,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
.values_of(options::SETS)
|
||||
.map(|v| {
|
||||
v.map(ToString::to_string)
|
||||
.map(convert::reduce_octal_to_char)
|
||||
.map(|input| convert::reduce_octal_to_char(&input))
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
|
|
@ -129,7 +129,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
let no_create = matches.is_present(options::NO_CREATE);
|
||||
let reference = matches.value_of(options::REFERENCE).map(String::from);
|
||||
let size = matches.value_of(options::SIZE).map(String::from);
|
||||
truncate(no_create, io_blocks, reference, size, files)
|
||||
truncate(no_create, io_blocks, reference, size, &files)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,7 +210,7 @@ fn file_truncate(filename: &str, create: bool, size: usize) -> std::io::Result<(
|
|||
fn truncate_reference_and_size(
|
||||
rfilename: &str,
|
||||
size_string: &str,
|
||||
filenames: Vec<String>,
|
||||
filenames: &[String],
|
||||
create: bool,
|
||||
) -> UResult<()> {
|
||||
let mode = match parse_mode_and_size(size_string) {
|
||||
|
@ -238,7 +238,7 @@ fn truncate_reference_and_size(
|
|||
})?;
|
||||
let fsize = metadata.len() as usize;
|
||||
let tsize = mode.to_size(fsize);
|
||||
for filename in &filenames {
|
||||
for filename in filenames {
|
||||
file_truncate(filename, create, tsize)
|
||||
.map_err_context(|| format!("cannot open {} for writing", filename.quote()))?;
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ fn truncate_reference_and_size(
|
|||
/// the size of at least one file.
|
||||
fn truncate_reference_file_only(
|
||||
rfilename: &str,
|
||||
filenames: Vec<String>,
|
||||
filenames: &[String],
|
||||
create: bool,
|
||||
) -> UResult<()> {
|
||||
let metadata = metadata(rfilename).map_err(|e| match e.kind() {
|
||||
|
@ -272,7 +272,7 @@ fn truncate_reference_file_only(
|
|||
_ => e.map_err_context(String::new),
|
||||
})?;
|
||||
let tsize = metadata.len() as usize;
|
||||
for filename in &filenames {
|
||||
for filename in filenames {
|
||||
file_truncate(filename, create, tsize)
|
||||
.map_err_context(|| format!("cannot open {} for writing", filename.quote()))?;
|
||||
}
|
||||
|
@ -294,13 +294,13 @@ fn truncate_reference_file_only(
|
|||
///
|
||||
/// If the any file could not be opened, or there was a problem setting
|
||||
/// the size of at least one file.
|
||||
fn truncate_size_only(size_string: &str, filenames: Vec<String>, create: bool) -> UResult<()> {
|
||||
fn truncate_size_only(size_string: &str, filenames: &[String], create: bool) -> UResult<()> {
|
||||
let mode = parse_mode_and_size(size_string)
|
||||
.map_err(|e| USimpleError::new(1, format!("Invalid number: {}", e)))?;
|
||||
if let TruncateMode::RoundDown(0) | TruncateMode::RoundUp(0) = mode {
|
||||
return Err(USimpleError::new(1, "division by zero"));
|
||||
}
|
||||
for filename in &filenames {
|
||||
for filename in filenames {
|
||||
let fsize = match metadata(filename) {
|
||||
Ok(m) => m.len(),
|
||||
Err(_) => 0,
|
||||
|
@ -324,7 +324,7 @@ fn truncate(
|
|||
_: bool,
|
||||
reference: Option<String>,
|
||||
size: Option<String>,
|
||||
filenames: Vec<String>,
|
||||
filenames: &[String],
|
||||
) -> UResult<()> {
|
||||
let create = !no_create;
|
||||
// There are four possibilities
|
||||
|
|
|
@ -27,7 +27,7 @@ static SUMMARY: &str = "Convert blanks in each FILE to tabs, writing to standard
|
|||
|
||||
const DEFAULT_TABSTOP: usize = 8;
|
||||
|
||||
fn tabstops_parse(s: String) -> Vec<usize> {
|
||||
fn tabstops_parse(s: &str) -> Vec<usize> {
|
||||
let words = s.split(',');
|
||||
|
||||
let nums = words
|
||||
|
@ -67,10 +67,10 @@ struct Options {
|
|||
}
|
||||
|
||||
impl Options {
|
||||
fn new(matches: clap::ArgMatches) -> Options {
|
||||
fn new(matches: &clap::ArgMatches) -> Options {
|
||||
let tabstops = match matches.value_of(options::TABS) {
|
||||
None => vec![DEFAULT_TABSTOP],
|
||||
Some(s) => tabstops_parse(s.to_string()),
|
||||
Some(s) => tabstops_parse(s),
|
||||
};
|
||||
|
||||
let aflag = (matches.is_present(options::ALL) || matches.is_present(options::TABS))
|
||||
|
@ -99,7 +99,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
unexpand(Options::new(matches)).map_err_context(String::new)
|
||||
unexpand(&Options::new(&matches)).map_err_context(String::new)
|
||||
}
|
||||
|
||||
pub fn uu_app<'a>() -> App<'a> {
|
||||
|
@ -138,7 +138,7 @@ pub fn uu_app<'a>() -> App<'a> {
|
|||
.help("interpret input file as 8-bit ASCII rather than UTF-8"))
|
||||
}
|
||||
|
||||
fn open(path: String) -> BufReader<Box<dyn Read + 'static>> {
|
||||
fn open(path: &str) -> BufReader<Box<dyn Read + 'static>> {
|
||||
let file_buf;
|
||||
if path == "-" {
|
||||
BufReader::new(Box::new(stdin()) as Box<dyn Read>)
|
||||
|
@ -243,13 +243,13 @@ fn next_char_info(uflag: bool, buf: &[u8], byte: usize) -> (CharType, usize, usi
|
|||
(ctype, cwidth, nbytes)
|
||||
}
|
||||
|
||||
fn unexpand(options: Options) -> std::io::Result<()> {
|
||||
fn unexpand(options: &Options) -> std::io::Result<()> {
|
||||
let mut output = BufWriter::new(stdout());
|
||||
let ts = &options.tabstops[..];
|
||||
let mut buf = Vec::new();
|
||||
let lastcol = if ts.len() > 1 { *ts.last().unwrap() } else { 0 };
|
||||
|
||||
for file in options.files.into_iter() {
|
||||
for file in options.files.iter() {
|
||||
let mut fh = open(file);
|
||||
|
||||
while match fh.read_until(b'\n', &mut buf) {
|
||||
|
|
|
@ -294,8 +294,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
zero_terminated: matches.is_present(options::ZERO_TERMINATED),
|
||||
};
|
||||
uniq.print_uniq(
|
||||
&mut open_input_file(in_file_name)?,
|
||||
&mut open_output_file(out_file_name)?,
|
||||
&mut open_input_file(&in_file_name)?,
|
||||
&mut open_output_file(&out_file_name)?,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -409,11 +409,11 @@ fn get_delimiter(matches: &ArgMatches) -> Delimiters {
|
|||
}
|
||||
}
|
||||
|
||||
fn open_input_file(in_file_name: String) -> UResult<BufReader<Box<dyn Read + 'static>>> {
|
||||
fn open_input_file(in_file_name: &str) -> UResult<BufReader<Box<dyn Read + 'static>>> {
|
||||
let in_file = if in_file_name == "-" {
|
||||
Box::new(stdin()) as Box<dyn Read>
|
||||
} else {
|
||||
let path = Path::new(&in_file_name[..]);
|
||||
let path = Path::new(in_file_name);
|
||||
let in_file = File::open(&path)
|
||||
.map_err_context(|| format!("Could not open {}", in_file_name.maybe_quote()))?;
|
||||
Box::new(in_file) as Box<dyn Read>
|
||||
|
@ -421,11 +421,11 @@ fn open_input_file(in_file_name: String) -> UResult<BufReader<Box<dyn Read + 'st
|
|||
Ok(BufReader::new(in_file))
|
||||
}
|
||||
|
||||
fn open_output_file(out_file_name: String) -> UResult<BufWriter<Box<dyn Write + 'static>>> {
|
||||
fn open_output_file(out_file_name: &str) -> UResult<BufWriter<Box<dyn Write + 'static>>> {
|
||||
let out_file = if out_file_name == "-" {
|
||||
Box::new(stdout()) as Box<dyn Write>
|
||||
} else {
|
||||
let path = Path::new(&out_file_name[..]);
|
||||
let path = Path::new(out_file_name);
|
||||
let out_file = File::create(&path)
|
||||
.map_err_context(|| format!("Could not create {}", out_file_name.maybe_quote()))?;
|
||||
Box::new(out_file) as Box<dyn Write>
|
||||
|
|
|
@ -159,7 +159,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
|
||||
let settings = Settings::new(&matches);
|
||||
|
||||
wc(inputs, &settings)
|
||||
wc(&inputs, &settings)
|
||||
}
|
||||
|
||||
pub fn uu_app<'a>() -> App<'a> {
|
||||
|
@ -409,7 +409,7 @@ fn max_width(inputs: &[Input]) -> usize {
|
|||
result
|
||||
}
|
||||
|
||||
fn wc(inputs: Vec<Input>, settings: &Settings) -> UResult<()> {
|
||||
fn wc(inputs: &[Input], settings: &Settings) -> UResult<()> {
|
||||
// Compute the width, in digits, to use when formatting counts.
|
||||
//
|
||||
// The width is the number of digits needed to print the number of
|
||||
|
@ -421,14 +421,14 @@ fn wc(inputs: Vec<Input>, settings: &Settings) -> UResult<()> {
|
|||
let max_width = if settings.number_enabled() <= 1 {
|
||||
0
|
||||
} else {
|
||||
max_width(&inputs)
|
||||
max_width(inputs)
|
||||
};
|
||||
|
||||
let mut total_word_count = WordCount::default();
|
||||
|
||||
let num_inputs = inputs.len();
|
||||
|
||||
for input in &inputs {
|
||||
for input in inputs {
|
||||
let word_count = match word_count_from_input(input, settings) {
|
||||
CountResult::Success(word_count) => word_count,
|
||||
CountResult::Interrupted(word_count, error) => {
|
||||
|
|
|
@ -156,12 +156,12 @@ impl<R: Read> Data<R> {
|
|||
}
|
||||
|
||||
// NOTE: this will likely be phased out at some point
|
||||
pub fn wrap_print<R: Read>(data: &Data<R>, res: String) {
|
||||
pub fn wrap_print<R: Read>(data: &Data<R>, res: &str) {
|
||||
let stdout = io::stdout();
|
||||
wrap_write(stdout.lock(), data.line_wrap, res).unwrap();
|
||||
}
|
||||
|
||||
pub fn wrap_write<W: Write>(mut writer: W, line_wrap: usize, res: String) -> io::Result<()> {
|
||||
pub fn wrap_write<W: Write>(mut writer: W, line_wrap: usize, res: &str) -> io::Result<()> {
|
||||
use std::cmp::min;
|
||||
|
||||
if line_wrap == 0 {
|
||||
|
|
|
@ -197,7 +197,7 @@ impl MountInfo {
|
|||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn new(file_name: &str, raw: Vec<&str>) -> Option<MountInfo> {
|
||||
fn new(file_name: &str, raw: &[&str]) -> Option<MountInfo> {
|
||||
match file_name {
|
||||
// spell-checker:ignore (word) noatime
|
||||
// Format: 36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue
|
||||
|
@ -410,7 +410,7 @@ pub fn read_fs_list() -> Vec<MountInfo> {
|
|||
.filter_map(|line| line.ok())
|
||||
.filter_map(|line| {
|
||||
let raw_data = line.split_whitespace().collect::<Vec<&str>>();
|
||||
MountInfo::new(file_name, raw_data)
|
||||
MountInfo::new(file_name, &raw_data)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
@ -902,9 +902,9 @@ mod tests {
|
|||
// spell-checker:ignore (word) relatime
|
||||
let info = MountInfo::new(
|
||||
LINUX_MOUNTINFO,
|
||||
"106 109 253:6 / /mnt rw,relatime - xfs /dev/fs0 rw"
|
||||
&"106 109 253:6 / /mnt rw,relatime - xfs /dev/fs0 rw"
|
||||
.split_ascii_whitespace()
|
||||
.collect(),
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
@ -917,9 +917,9 @@ mod tests {
|
|||
// Test parsing with different amounts of optional fields.
|
||||
let info = MountInfo::new(
|
||||
LINUX_MOUNTINFO,
|
||||
"106 109 253:6 / /mnt rw,relatime master:1 - xfs /dev/fs0 rw"
|
||||
&"106 109 253:6 / /mnt rw,relatime master:1 - xfs /dev/fs0 rw"
|
||||
.split_ascii_whitespace()
|
||||
.collect(),
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
@ -928,9 +928,9 @@ mod tests {
|
|||
|
||||
let info = MountInfo::new(
|
||||
LINUX_MOUNTINFO,
|
||||
"106 109 253:6 / /mnt rw,relatime master:1 shared:2 - xfs /dev/fs0 rw"
|
||||
&"106 109 253:6 / /mnt rw,relatime master:1 shared:2 - xfs /dev/fs0 rw"
|
||||
.split_ascii_whitespace()
|
||||
.collect(),
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -46,12 +46,12 @@ pub struct DivOut<'a> {
|
|||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn arrnum_int_div_step(
|
||||
rem_in: Remainder,
|
||||
pub fn arrnum_int_div_step<'a>(
|
||||
rem_in: &'a Remainder,
|
||||
radix_in: u8,
|
||||
base_ten_int_divisor: u8,
|
||||
after_decimal: bool,
|
||||
) -> DivOut {
|
||||
) -> DivOut<'a> {
|
||||
let mut rem_out = Remainder {
|
||||
position: rem_in.position,
|
||||
replace: Vec::new(),
|
||||
|
|
|
@ -49,7 +49,7 @@ fn test_arrnum_int_div_short_circuit() {
|
|||
let remainder_position_should_be: usize = 3;
|
||||
let remainder_replace_should_be = vec![1, 2];
|
||||
|
||||
let result = arrnum_int_div_step(remainder_passed_in, base_num, base_ten_int_divisor, false);
|
||||
let result = arrnum_int_div_step(&remainder_passed_in, base_num, base_ten_int_divisor, false);
|
||||
assert!(quotient_should_be == result.quotient);
|
||||
assert!(remainder_position_should_be == result.remainder.position);
|
||||
assert!(remainder_replace_should_be == result.remainder.replace);
|
||||
|
|
|
@ -25,7 +25,7 @@ pub fn warn_expected_numeric(pf_arg: &str) {
|
|||
|
||||
// when character constant arguments have excess characters
|
||||
// issue a warning when POSIXLY_CORRECT is not set
|
||||
fn warn_char_constant_ign(remaining_bytes: Vec<u8>) {
|
||||
fn warn_char_constant_ign(remaining_bytes: &[u8]) {
|
||||
match env::var("POSIXLY_CORRECT") {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
|
@ -59,7 +59,7 @@ fn get_provided(str_in_opt: Option<&String>) -> Option<u8> {
|
|||
ignored.push(cont);
|
||||
}
|
||||
if !ignored.is_empty() {
|
||||
warn_char_constant_ign(ignored);
|
||||
warn_char_constant_ign(&ignored);
|
||||
}
|
||||
second_byte as u8
|
||||
}
|
||||
|
|
|
@ -92,9 +92,9 @@ fn test_zero_param() {
|
|||
}
|
||||
}
|
||||
|
||||
fn expect_error(input: Vec<&str>) {
|
||||
fn expect_error(input: &[&str]) {
|
||||
assert!(!new_ucmd!()
|
||||
.args(&input)
|
||||
.args(input)
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_str()
|
||||
|
@ -104,12 +104,12 @@ fn expect_error(input: Vec<&str>) {
|
|||
#[test]
|
||||
fn test_invalid_option() {
|
||||
let path = "/foo/bar/baz";
|
||||
expect_error(vec!["-q", path]);
|
||||
expect_error(&["-q", path]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_args() {
|
||||
expect_error(vec![]);
|
||||
expect_error(&[]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -119,7 +119,7 @@ fn test_no_args_output() {
|
|||
|
||||
#[test]
|
||||
fn test_too_many_args() {
|
||||
expect_error(vec!["a", "b", "c"]);
|
||||
expect_error(&["a", "b", "c"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -33,7 +33,7 @@ fn make_file(file: &str, mode: u32) {
|
|||
set_permissions(file, perms).unwrap();
|
||||
}
|
||||
|
||||
fn run_single_test(test: &TestCase, at: AtPath, mut ucmd: UCommand) {
|
||||
fn run_single_test(test: &TestCase, at: &AtPath, mut ucmd: UCommand) {
|
||||
make_file(&at.plus_as_string(TEST_FILE), test.before);
|
||||
let perms = at.metadata(TEST_FILE).permissions().mode();
|
||||
if perms != test.before {
|
||||
|
@ -64,7 +64,7 @@ fn run_single_test(test: &TestCase, at: AtPath, mut ucmd: UCommand) {
|
|||
fn run_tests(tests: Vec<TestCase>) {
|
||||
for test in tests {
|
||||
let (at, ucmd) = at_and_ucmd!();
|
||||
run_single_test(&test, at, ucmd);
|
||||
run_single_test(&test, &at, ucmd);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -295,7 +295,7 @@ fn test_chmod_reference_file() {
|
|||
];
|
||||
let (at, ucmd) = at_and_ucmd!();
|
||||
make_file(&at.plus_as_string(REFERENCE_FILE), REFERENCE_PERMS);
|
||||
run_single_test(&tests[0], at, ucmd);
|
||||
run_single_test(&tests[0], &at, ucmd);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -553,7 +553,7 @@ fn test_mode_after_dash_dash() {
|
|||
before: 0o100777,
|
||||
after: 0o100333,
|
||||
},
|
||||
at,
|
||||
&at,
|
||||
ucmd,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -235,7 +235,7 @@ impl CmdResult {
|
|||
}
|
||||
|
||||
/// like `stdout_is`, but succeeds if any elements of `expected` matches stdout.
|
||||
pub fn stdout_is_any<T: AsRef<str> + std::fmt::Debug>(&self, expected: Vec<T>) -> &CmdResult {
|
||||
pub fn stdout_is_any<T: AsRef<str> + std::fmt::Debug>(&self, expected: &[T]) -> &CmdResult {
|
||||
if !expected.iter().any(|msg| self.stdout_str() == msg.as_ref()) {
|
||||
panic!(
|
||||
"stdout was {}\nExpected any of {:#?}",
|
||||
|
@ -294,7 +294,7 @@ impl CmdResult {
|
|||
}
|
||||
contents
|
||||
});
|
||||
self.stdout_is_any(possible_values.collect());
|
||||
self.stdout_is_any(&possible_values.collect::<Vec<_>>());
|
||||
}
|
||||
|
||||
/// asserts that the command resulted in stderr stream output that equals the
|
||||
|
@ -816,13 +816,13 @@ impl TestScenario {
|
|||
util_name: T,
|
||||
env_clear: bool,
|
||||
) -> UCommand {
|
||||
UCommand::new_from_tmp(bin, Some(util_name), self.tmpd.clone(), env_clear)
|
||||
UCommand::new_from_tmp(bin, &Some(util_name), self.tmpd.clone(), env_clear)
|
||||
}
|
||||
|
||||
/// Returns builder for invoking any system command. Paths given are treated
|
||||
/// relative to the environment's unique temporary test directory.
|
||||
pub fn cmd<S: AsRef<OsStr>>(&self, bin: S) -> UCommand {
|
||||
UCommand::new_from_tmp::<S, S>(bin, None, self.tmpd.clone(), true)
|
||||
UCommand::new_from_tmp::<S, S>(bin, &None, self.tmpd.clone(), true)
|
||||
}
|
||||
|
||||
/// Returns builder for invoking any uutils command. Paths given are treated
|
||||
|
@ -842,7 +842,7 @@ impl TestScenario {
|
|||
/// Differs from the builder returned by `cmd` in that `cmd_keepenv` does not call
|
||||
/// `Command::env_clear` (Clears the entire environment map for the child process.)
|
||||
pub fn cmd_keepenv<S: AsRef<OsStr>>(&self, bin: S) -> UCommand {
|
||||
UCommand::new_from_tmp::<S, S>(bin, None, self.tmpd.clone(), false)
|
||||
UCommand::new_from_tmp::<S, S>(bin, &None, self.tmpd.clone(), false)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -872,7 +872,7 @@ pub struct UCommand {
|
|||
impl UCommand {
|
||||
pub fn new<T: AsRef<OsStr>, S: AsRef<OsStr>, U: AsRef<OsStr>>(
|
||||
bin_path: T,
|
||||
util_name: Option<S>,
|
||||
util_name: &Option<S>,
|
||||
curdir: U,
|
||||
env_clear: bool,
|
||||
) -> UCommand {
|
||||
|
@ -924,7 +924,7 @@ impl UCommand {
|
|||
|
||||
pub fn new_from_tmp<T: AsRef<OsStr>, S: AsRef<OsStr>>(
|
||||
bin_path: T,
|
||||
util_name: Option<S>,
|
||||
util_name: &Option<S>,
|
||||
tmpd: Rc<TempDir>,
|
||||
env_clear: bool,
|
||||
) -> UCommand {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue