Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,9 +1150,8 @@
CpError::Error("SELinux was not enabled during the compile time!".to_owned());
if required {
return Err(selinux_disabled_error);
} else {
show_error_if_needed(&selinux_disabled_error);
}
show_error_if_needed(&selinux_disabled_error);
}

// Extract the SELinux related flags and options
Expand Down Expand Up @@ -1925,10 +1924,9 @@
source.quote()
)
.into());
} else {
is_dest_removed = dest.is_symlink();
backup_dest(dest, &backup_path, is_dest_removed)?;
}
is_dest_removed = dest.is_symlink();
backup_dest(dest, &backup_path, is_dest_removed)?;
}
if !is_dest_removed {
delete_dest_if_needed_and_allowed(
Expand Down Expand Up @@ -2195,21 +2193,21 @@
let dest_time = dest_metadata.modified()?;
if src_time <= dest_time {
return Ok(PerformedAction::Skipped);
} else {
options.overwrite.verify(dest, options.debug)?;

copy_helper(
source,
dest,
options,
context,
source_is_symlink,
source_is_fifo,
symlinked_files,
#[cfg(unix)]
source_is_stream,
)?;
}

Check warning on line 2197 in src/uu/cp/src/cp.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/cp/src/cp.rs#L2197

Added line #L2197 was not covered by tests
options.overwrite.verify(dest, options.debug)?;

copy_helper(
source,
dest,
options,
context,
source_is_symlink,
source_is_fifo,
symlinked_files,
#[cfg(unix)]

Check warning on line 2208 in src/uu/cp/src/cp.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/cp/src/cp.rs#L2201-L2208

Added lines #L2201 - L2208 were not covered by tests
source_is_stream,
)?;

Check warning on line 2210 in src/uu/cp/src/cp.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/cp/src/cp.rs#L2210

Added line #L2210 was not covered by tests
}
}
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/uu/cut/src/cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,8 @@ fn get_delimiters(matches: &ArgMatches) -> UResult<(Delimiter, Option<&[u8]>)> {
1,
get_message("cut-error-delimiter-must-be-single-character"),
));
} else {
Delimiter::from(os_string)
}
Delimiter::from(os_string)
}
}
None => {
Expand Down
3 changes: 1 addition & 2 deletions src/uu/cut/src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
|| haystack[match_idx + 1..].starts_with(&self.needle[1..])
{
return Some((match_idx, match_idx + self.needle.len()));
} else {
pos = match_idx + 1;
}
pos = match_idx + 1;

Check warning on line 38 in src/uu/cut/src/matcher.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/cut/src/matcher.rs#L38

Added line #L38 was not covered by tests
}
None => {
return None;
Expand Down
132 changes: 66 additions & 66 deletions src/uu/date/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,81 +204,81 @@
};

return set_system_datetime(date);
}

// Get the current time, either in the local time zone or UTC.
let now = if settings.utc {
Timestamp::now().to_zoned(TimeZone::UTC)
} else {
// Get the current time, either in the local time zone or UTC.
let now = if settings.utc {
Timestamp::now().to_zoned(TimeZone::UTC)
} else {
Zoned::now()
};
Zoned::now()
};

// Iterate over all dates - whether it's a single date or a file.
let dates: Box<dyn Iterator<Item = _>> = match settings.date_source {
DateSource::Custom(ref input) => {
let date = parse_date(input);
let iter = std::iter::once(date);
Box::new(iter)
}
DateSource::Human(relative_time) => {
// Double check the result is overflow or not of the current_time + relative_time
// it may cause a panic of chrono::datetime::DateTime add
match now.checked_add(relative_time) {
Ok(date) => {
let iter = std::iter::once(Ok(date));
Box::new(iter)
}
Err(_) => {
return Err(USimpleError::new(
1,
format!("invalid date {relative_time}"),
));
}
// Iterate over all dates - whether it's a single date or a file.
let dates: Box<dyn Iterator<Item = _>> = match settings.date_source {
DateSource::Custom(ref input) => {
let date = parse_date(input);
let iter = std::iter::once(date);
Box::new(iter)
}
DateSource::Human(relative_time) => {
// Double check the result is overflow or not of the current_time + relative_time
// it may cause a panic of chrono::datetime::DateTime add
match now.checked_add(relative_time) {
Ok(date) => {
let iter = std::iter::once(Ok(date));
Box::new(iter)
}
}
DateSource::Stdin => {
let lines = BufReader::new(std::io::stdin()).lines();
let iter = lines.map_while(Result::ok).map(parse_date);
Box::new(iter)
}
DateSource::File(ref path) => {
if path.is_dir() {
Err(_) => {
return Err(USimpleError::new(
2,
format!("expected file, got directory {}", path.quote()),
1,
format!("invalid date {relative_time}"),

Check warning on line 234 in src/uu/date/src/date.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/date/src/date.rs#L233-L234

Added lines #L233 - L234 were not covered by tests
));
}
let file = File::open(path)
.map_err_context(|| path.as_os_str().to_string_lossy().to_string())?;
let lines = BufReader::new(file).lines();
let iter = lines.map_while(Result::ok).map(parse_date);
Box::new(iter)
}
DateSource::Now => {
let iter = std::iter::once(Ok(now));
Box::new(iter)
}
DateSource::Stdin => {
let lines = BufReader::new(std::io::stdin()).lines();
let iter = lines.map_while(Result::ok).map(parse_date);
Box::new(iter)
}
DateSource::File(ref path) => {
if path.is_dir() {
return Err(USimpleError::new(
2,
format!("expected file, got directory {}", path.quote()),
));
}
};
let file = File::open(path)
.map_err_context(|| path.as_os_str().to_string_lossy().to_string())?;
let lines = BufReader::new(file).lines();
let iter = lines.map_while(Result::ok).map(parse_date);
Box::new(iter)
}
DateSource::Now => {
let iter = std::iter::once(Ok(now));
Box::new(iter)
}
};

let format_string = make_format_string(&settings);

// Format all the dates
for date in dates {
match date {
// TODO: Switch to lenient formatting.
Ok(date) => match strtime::format(format_string, &date) {
Ok(s) => println!("{s}"),
Err(e) => {
return Err(USimpleError::new(
1,
format!("invalid format {} ({e})", format_string),
));
}
},
Err((input, _err)) => show!(USimpleError::new(
1,
format!("invalid date {}", input.quote())
)),
}
let format_string = make_format_string(&settings);

// Format all the dates
for date in dates {
match date {
// TODO: Switch to lenient formatting.
Ok(date) => match strtime::format(format_string, &date) {
Ok(s) => println!("{s}"),
Err(e) => {
return Err(USimpleError::new(
1,
format!("invalid format {format_string} ({e})"),
));
}
},
Err((input, _err)) => show!(USimpleError::new(
1,
format!("invalid date {}", input.quote())
)),
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/uu/dd/src/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@
}
}
Ok(len) => return Ok(len),
Err(e) if e.kind() == io::ErrorKind::Interrupted => continue,
Err(e) if e.kind() == io::ErrorKind::Interrupted => (),

Check warning on line 440 in src/uu/dd/src/dd.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/dd/src/dd.rs#L440

Added line #L440 was not covered by tests
Err(_) if self.settings.iconv.noerror => return Ok(base_idx),
Err(e) => return Err(e),
}
Expand Down Expand Up @@ -861,7 +861,7 @@
return Ok(base_idx);
}
}
Err(e) if e.kind() == io::ErrorKind::Interrupted => continue,
Err(e) if e.kind() == io::ErrorKind::Interrupted => (),

Check warning on line 864 in src/uu/dd/src/dd.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/dd/src/dd.rs#L864

Added line #L864 was not covered by tests
Err(e) => return Err(e),
}
}
Expand Down
34 changes: 17 additions & 17 deletions src/uu/dirname/src/dirname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,27 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

if dirnames.is_empty() {
return Err(UUsageError::new(1, get_message("dirname-missing-operand")));
} else {
for path in &dirnames {
let p = Path::new(path);
match p.parent() {
Some(d) => {
if d.components().next().is_none() {
print!(".");
} else {
print_verbatim(d).unwrap();
}
}

for path in &dirnames {
let p = Path::new(path);
match p.parent() {
Some(d) => {
if d.components().next().is_none() {
print!(".");
} else {
print_verbatim(d).unwrap();
}
None => {
if p.is_absolute() || path == "/" {
print!("/");
} else {
print!(".");
}
}
None => {
if p.is_absolute() || path == "/" {
print!("/");
} else {
print!(".");
}
}
print!("{line_ending}");
}
print!("{line_ending}");
}

Ok(())
Expand Down
8 changes: 5 additions & 3 deletions src/uu/env/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,11 @@
match cmd.status() {
Ok(exit) if !exit.success() => {
#[cfg(unix)]
if let Some(exit_code) = exit.code() {
return Err(exit_code.into());
} else {
{
if let Some(exit_code) = exit.code() {
return Err(exit_code.into());
}

Check warning on line 600 in src/uu/env/src/env.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/env/src/env.rs#L598-L600

Added lines #L598 - L600 were not covered by tests

// `exit.code()` returns `None` on Unix when the process is terminated by a signal.
// See std::os::unix::process::ExitStatusExt for more information. This prints out
// the interrupted process and the signal it received.
Expand Down
1 change: 0 additions & 1 deletion src/uu/expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ fn expand(options: &Options) -> UResult<()> {
Err(e) => {
show_error!("{e}");
set_exit_code(1);
continue;
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/uu/fmt/src/linebreak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ fn break_knuth_plass<'a, T: Clone + Iterator<Item = &'a WordInfo<'a>>>(
fresh = true;
}
break;
} else {
write_with_spaces(word, slen, args.ostream)?;
}
write_with_spaces(word, slen, args.ostream)?;
}
Ok((prev_punct, fresh))
},
Expand Down
1 change: 0 additions & 1 deletion src/uu/head/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub fn parse_obsolete(src: &str) -> Option<Result<Vec<OsString>, ParseError>> {
} else if c == '+' && plus_possible {
plus_possible = false;
num_start += 1;
continue;
} else {
num_end = n;
last_char = c;
Expand Down
2 changes: 1 addition & 1 deletion src/uu/head/src/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
self.buffer.truncate(n);
return Ok(n);
}
Err(e) if e.kind() == ErrorKind::Interrupted => continue,
Err(e) if e.kind() == ErrorKind::Interrupted => (),

Check warning on line 34 in src/uu/head/src/take.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/head/src/take.rs#L34

Added line #L34 was not covered by tests
Err(e) => return Err(e),
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,13 +1091,13 @@ impl Config {
Dereference::DirArgs
};

let tab_size = if !needs_color {
let tab_size = if needs_color {
Some(0)
} else {
options
.get_one::<String>(options::format::TAB_SIZE)
.and_then(|size| size.parse::<usize>().ok())
.or_else(|| std::env::var("TABSIZE").ok().and_then(|s| s.parse().ok()))
} else {
Some(0)
}
.unwrap_or(SPACES_IN_TAB);

Expand Down Expand Up @@ -2366,7 +2366,6 @@ fn enter_directory(
err,
e.command_line
));
continue;
}
Ok(rd) => {
if listed_ancestors
Expand Down
4 changes: 2 additions & 2 deletions src/uu/more/src/more.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@
&format!("{}{pattern}{}", Attribute::Reverse, Attribute::Reset),
);
};
self.stdout.write_all(format!("\r{}\n", line).as_bytes())?;
self.stdout.write_all(format!("\r{line}\n").as_bytes())?;

Check warning on line 748 in src/uu/more/src/more.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/more/src/more.rs#L748

Added line #L748 was not covered by tests
lines_printed += 1;
index += 1;
}
Expand Down Expand Up @@ -792,7 +792,7 @@
if percentage >= 100 {
" (END)".to_string()
} else {
format!(" ({}%)", percentage)
format!(" ({percentage}%)")

Check warning on line 795 in src/uu/more/src/more.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/more/src/more.rs#L795

Added line #L795 was not covered by tests
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/uu/numfmt/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ fn format_and_print_whitespace(s: &str, options: &NumfmtOptions) -> Result<()> {
}

let eol = if options.zero_terminated { '\0' } else { '\n' };
print!("{}", eol);
print!("{eol}");

Ok(())
}
Expand Down
Loading
Loading