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