mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-04 15:07:47 +00:00
refactor/polish ~ fix cargo clippy
complaints (collapse else-if)
This commit is contained in:
parent
2db6fb20c9
commit
b8eb763e43
8 changed files with 26 additions and 42 deletions
|
@ -202,13 +202,11 @@ fn determine_backup_suffix(backup_mode: BackupMode, matches: &getopts::Matches)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if let (Ok(s), BackupMode::SimpleBackup) = (env::var("SIMPLE_BACKUP_SUFFIX"), backup_mode) {
|
||||||
if let (Ok(s), BackupMode::SimpleBackup) = (env::var("SIMPLE_BACKUP_SUFFIX"), backup_mode) {
|
|
||||||
s
|
s
|
||||||
} else {
|
} else {
|
||||||
"~".to_owned()
|
"~".to_owned()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn help(usage: &str) {
|
fn help(usage: &str) {
|
||||||
|
|
|
@ -115,13 +115,11 @@ fn num_cpus_all() -> usize {
|
||||||
// In some situation, /proc and /sys are not mounted, and sysconf returns 1.
|
// In some situation, /proc and /sys are not mounted, and sysconf returns 1.
|
||||||
// However, we want to guarantee that `nproc --all` >= `nproc`.
|
// However, we want to guarantee that `nproc --all` >= `nproc`.
|
||||||
num_cpus::get()
|
num_cpus::get()
|
||||||
} else {
|
} else if nprocs > 0 {
|
||||||
if nprocs > 0 {
|
|
||||||
nprocs as usize
|
nprocs as usize
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Other platform(e.g., windows), num_cpus::get() directly.
|
// Other platform(e.g., windows), num_cpus::get() directly.
|
||||||
|
|
|
@ -290,13 +290,11 @@ impl Pinky {
|
||||||
if ut.is_user_process() {
|
if ut.is_user_process() {
|
||||||
if self.names.is_empty() {
|
if self.names.is_empty() {
|
||||||
self.print_entry(&ut)
|
self.print_entry(&ut)
|
||||||
} else {
|
} else if self.names.iter().any(|n| n.as_str() == ut.user()) {
|
||||||
if self.names.iter().any(|n| n.as_str() == ut.user()) {
|
|
||||||
self.print_entry(&ut);
|
self.print_entry(&ut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,11 @@ fn has_enough_digits(
|
||||||
} else {
|
} else {
|
||||||
false //undecidable without converting
|
false //undecidable without converting
|
||||||
}
|
}
|
||||||
} else {
|
} else if hex_input {
|
||||||
if hex_input {
|
|
||||||
((((string_position - 1) - starting_position) * 9) / 8 >= limit)
|
((((string_position - 1) - starting_position) * 9) / 8 >= limit)
|
||||||
} else {
|
} else {
|
||||||
((string_position - 1) - starting_position >= limit)
|
((string_position - 1) - starting_position >= limit)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FloatAnalysis {
|
impl FloatAnalysis {
|
||||||
|
|
|
@ -189,15 +189,13 @@ fn read_input(input_files: &[String], config: &Config) -> HashMap<String, (Vec<S
|
||||||
let mut files = Vec::new();
|
let mut files = Vec::new();
|
||||||
if input_files.is_empty() {
|
if input_files.is_empty() {
|
||||||
files.push("-");
|
files.push("-");
|
||||||
} else {
|
} else if config.gnu_ext {
|
||||||
if config.gnu_ext {
|
|
||||||
for file in input_files {
|
for file in input_files {
|
||||||
files.push(&file);
|
files.push(&file);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
files.push(&input_files[0]);
|
files.push(&input_files[0]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
let mut lines_so_far: usize = 0;
|
let mut lines_so_far: usize = 0;
|
||||||
for filename in files {
|
for filename in files {
|
||||||
let reader: BufReader<Box<dyn Read>> = BufReader::new(if filename == "-" {
|
let reader: BufReader<Box<dyn Read>> = BufReader::new(if filename == "-" {
|
||||||
|
|
|
@ -225,8 +225,7 @@ fn handle_dir(path: &Path, options: &Options) -> bool {
|
||||||
}
|
}
|
||||||
} else if options.dir && (!is_root || !options.preserve_root) {
|
} else if options.dir && (!is_root || !options.preserve_root) {
|
||||||
had_err = remove_dir(path, options).bitor(had_err);
|
had_err = remove_dir(path, options).bitor(had_err);
|
||||||
} else {
|
} else if options.recursive {
|
||||||
if options.recursive {
|
|
||||||
show_error!("could not remove directory '{}'", path.display());
|
show_error!("could not remove directory '{}'", path.display());
|
||||||
had_err = true;
|
had_err = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -236,7 +235,6 @@ fn handle_dir(path: &Path, options: &Options) -> bool {
|
||||||
);
|
);
|
||||||
had_err = true;
|
had_err = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
had_err
|
had_err
|
||||||
}
|
}
|
||||||
|
|
|
@ -302,13 +302,11 @@ fn exec(files: Vec<String>, settings: &Settings) -> i32 {
|
||||||
} else {
|
} else {
|
||||||
print_sorted(file_merger, &settings.outfile)
|
print_sorted(file_merger, &settings.outfile)
|
||||||
}
|
}
|
||||||
} else {
|
} else if settings.unique {
|
||||||
if settings.unique {
|
|
||||||
print_sorted(lines.iter().dedup(), &settings.outfile)
|
print_sorted(lines.iter().dedup(), &settings.outfile)
|
||||||
} else {
|
} else {
|
||||||
print_sorted(lines.iter(), &settings.outfile)
|
print_sorted(lines.iter(), &settings.outfile)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,12 +182,10 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
if let Err(e) = set_symlink_file_times(path, atime, mtime) {
|
if let Err(e) = set_symlink_file_times(path, atime, mtime) {
|
||||||
show_warning!("cannot touch '{}': {}", path, e);
|
show_warning!("cannot touch '{}': {}", path, e);
|
||||||
}
|
}
|
||||||
} else {
|
} else if let Err(e) = filetime::set_file_times(path, atime, mtime) {
|
||||||
if let Err(e) = filetime::set_file_times(path, atime, mtime) {
|
|
||||||
show_warning!("cannot touch '{}': {}", path, e);
|
show_warning!("cannot touch '{}': {}", path, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue