1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

fix clippy for unix

This commit is contained in:
Reto Hablützel 2021-04-11 16:34:19 +02:00
parent b465c34eef
commit d67560c37a
12 changed files with 36 additions and 43 deletions

View file

@ -286,7 +286,7 @@ impl Chgrper {
ret = match wrap_chgrp(path, &meta, self.dest_gid, follow, self.verbosity.clone()) {
Ok(n) => {
if n != "" {
if !n.is_empty() {
show_info!("{}", n);
}
0

View file

@ -171,13 +171,13 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
// of a prefix '-' if it's associated with MODE
// e.g. "chmod -v -xw -R FILE" -> "chmod -v xw -R FILE"
pub fn strip_minus_from_mode(args: &mut Vec<String>) -> bool {
for i in 0..args.len() {
if args[i].starts_with("-") {
if let Some(second) = args[i].chars().nth(1) {
for arg in args {
if arg.starts_with('-') {
if let Some(second) = arg.chars().nth(1) {
match second {
'r' | 'w' | 'x' | 'X' | 's' | 't' | 'u' | 'g' | 'o' | '0'..='7' => {
// TODO: use strip_prefix() once minimum rust version reaches 1.45.0
args[i] = args[i][1..args[i].len()].to_string();
*arg = arg[1..arg.len()].to_string();
return true;
}
_ => {}

View file

@ -391,7 +391,7 @@ impl Chowner {
self.verbosity.clone(),
) {
Ok(n) => {
if n != "" {
if !n.is_empty() {
show_info!("{}", n);
}
0
@ -446,7 +446,7 @@ impl Chowner {
self.verbosity.clone(),
) {
Ok(n) => {
if n != "" {
if !n.is_empty() {
show_info!("{}", n);
}
0

View file

@ -104,7 +104,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
_ => {
let mut vector: Vec<&str> = Vec::new();
for (&k, v) in matches.args.iter() {
vector.push(k.clone());
vector.push(k);
vector.push(&v.vals[0].to_str().unwrap());
}
vector
@ -133,7 +133,7 @@ fn set_context(root: &Path, options: &clap::ArgMatches) {
let userspec = match userspec_str {
Some(ref u) => {
let s: Vec<&str> = u.split(':').collect();
if s.len() != 2 || s.iter().any(|&spec| spec == "") {
if s.len() != 2 || s.iter().any(|&spec| spec.is_empty()) {
crash!(1, "invalid userspec: `{}`", u)
};
s
@ -142,16 +142,16 @@ fn set_context(root: &Path, options: &clap::ArgMatches) {
};
let (user, group) = if userspec.is_empty() {
(&user_str[..], &group_str[..])
(user_str, group_str)
} else {
(&userspec[0][..], &userspec[1][..])
(userspec[0], userspec[1])
};
enter_chroot(root);
set_groups_from_str(&groups_str[..]);
set_main_group(&group[..]);
set_user(&user[..]);
set_groups_from_str(groups_str);
set_main_group(group);
set_user(user);
}
fn enter_chroot(root: &Path) {

View file

@ -302,7 +302,7 @@ fn behavior(matches: &ArgMatches) -> Result<Behavior, i32> {
let specified_mode: Option<u32> = if matches.is_present(OPT_MODE) {
match matches.value_of(OPT_MODE) {
Some(x) => match mode::parse(&x[..], considering_dir) {
Some(x) => match mode::parse(x, considering_dir) {
Ok(y) => Some(y),
Err(err) => {
show_error!("Invalid mode string: {}", err);
@ -429,7 +429,7 @@ fn standard(paths: Vec<String>, b: Behavior) -> i32 {
/// _files_ must all exist as non-directories.
/// _target_dir_ must be a directory.
///
fn copy_files_into_dir(files: &[PathBuf], target_dir: &PathBuf, b: &Behavior) -> i32 {
fn copy_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> i32 {
if !target_dir.is_dir() {
show_error!("target '{}' is not a directory", target_dir.display());
return 1;
@ -453,7 +453,7 @@ fn copy_files_into_dir(files: &[PathBuf], target_dir: &PathBuf, b: &Behavior) ->
continue;
}
let mut targetpath = target_dir.clone().to_path_buf();
let mut targetpath = target_dir.to_path_buf();
let filename = sourcepath.components().last().unwrap();
targetpath.push(filename);
@ -478,7 +478,7 @@ fn copy_files_into_dir(files: &[PathBuf], target_dir: &PathBuf, b: &Behavior) ->
/// _file_ must exist as a non-directory.
/// _target_ must be a non-directory
///
fn copy_file_to_file(file: &PathBuf, target: &PathBuf, b: &Behavior) -> i32 {
fn copy_file_to_file(file: &Path, target: &Path, b: &Behavior) -> i32 {
if copy(file, &target, b).is_err() {
1
} else {
@ -497,7 +497,7 @@ fn copy_file_to_file(file: &PathBuf, target: &PathBuf, b: &Behavior) -> i32 {
///
/// If the copy system call fails, we print a verbose error and return an empty error value.
///
fn copy(from: &PathBuf, to: &PathBuf, b: &Behavior) -> Result<(), ()> {
fn copy(from: &Path, to: &Path, b: &Behavior) -> Result<(), ()> {
if b.compare && !need_copy(from, to, b) {
return Ok(());
}
@ -556,7 +556,7 @@ fn copy(from: &PathBuf, to: &PathBuf, b: &Behavior) -> Result<(), ()> {
};
let gid = meta.gid();
match wrap_chown(
to.as_path(),
to,
&meta,
Some(owner_id),
Some(gid),
@ -582,7 +582,7 @@ fn copy(from: &PathBuf, to: &PathBuf, b: &Behavior) -> Result<(), ()> {
Ok(g) => g,
_ => crash!(1, "no such group: {}", b.group),
};
match wrap_chgrp(to.as_path(), &meta, group_id, false, Verbosity::Normal) {
match wrap_chgrp(to, &meta, group_id, false, Verbosity::Normal) {
Ok(n) => {
if !n.is_empty() {
show_info!("{}", n);
@ -601,7 +601,7 @@ fn copy(from: &PathBuf, to: &PathBuf, b: &Behavior) -> Result<(), ()> {
let modified_time = FileTime::from_last_modification_time(&meta);
let accessed_time = FileTime::from_last_access_time(&meta);
match set_file_times(to.as_path(), accessed_time, modified_time) {
match set_file_times(to, accessed_time, modified_time) {
Ok(_) => {}
Err(e) => show_info!("{}", e),
}
@ -630,7 +630,7 @@ fn copy(from: &PathBuf, to: &PathBuf, b: &Behavior) -> Result<(), ()> {
///
/// Crashes the program if a nonexistent owner or group is specified in _b_.
///
fn need_copy(from: &PathBuf, to: &PathBuf, b: &Behavior) -> bool {
fn need_copy(from: &Path, to: &Path, b: &Behavior) -> bool {
let from_meta = match fs::metadata(from) {
Ok(meta) => meta,
Err(_) => return true,

View file

@ -370,6 +370,7 @@ impl Config {
})
.or_else(|| termsize::get().map(|s| s.cols));
#[allow(clippy::needless_bool)]
let show_control = if options.is_present(options::HIDE_CONTROL_CHARS) {
false
} else if options.is_present(options::SHOW_CONTROL_CHARS) {

View file

@ -15,7 +15,6 @@ use uucore::utmpx::{self, time, Utmpx};
use std::io::prelude::*;
use std::io::BufReader;
use std::io::Result as IOResult;
use std::fs::File;
use std::os::unix::fs::MetadataExt;
@ -136,12 +135,8 @@ The utmp file will be {}",
};
if do_short_format {
if let Err(e) = pk.short_pinky() {
show_usage_error!("{}", e);
1
} else {
0
}
pk.short_pinky();
0
} else {
pk.long_pinky()
}
@ -282,7 +277,7 @@ impl Pinky {
println!();
}
fn short_pinky(&self) -> IOResult<()> {
fn short_pinky(&self) {
if self.include_heading {
self.print_heading();
}
@ -295,7 +290,6 @@ impl Pinky {
}
}
}
Ok(())
}
fn long_pinky(&self) -> i32 {

View file

@ -35,8 +35,8 @@ extern "C" {
fn set_buffer(stream: *mut FILE, value: &str) {
let (mode, size): (c_int, size_t) = match value {
"0" => (_IONBF, 0 as size_t),
"L" => (_IOLBF, 0 as size_t),
"0" => (_IONBF, 0_usize),
"L" => (_IOLBF, 0_usize),
input => {
let buff_size: usize = match input.parse() {
Ok(num) => num,

View file

@ -141,12 +141,10 @@ fn parse_size(size: &str) -> Option<u64> {
fn check_option(matches: &ArgMatches, name: &str) -> Result<BufferType, ProgramOptionsError> {
match matches.value_of(name) {
Some(value) => match &value[..] {
Some(value) => match value {
"L" => {
if name == options::INPUT {
Err(ProgramOptionsError(format!(
"line buffering stdin is meaningless"
)))
Err(ProgramOptionsError("line buffering stdin is meaningless".to_string()))
} else {
Ok(BufferType::Line)
}

View file

@ -137,7 +137,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
let (mut atime, mut mtime) = if matches.is_present(options::sources::REFERENCE) {
stat(
&matches.value_of(options::sources::REFERENCE).unwrap()[..],
matches.value_of(options::sources::REFERENCE).unwrap(),
!matches.is_present(options::NO_DEREF),
)
} else if matches.is_present(options::sources::DATE)

View file

@ -65,9 +65,9 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
}
}
return if is_stdin_interactive() {
if is_stdin_interactive() {
libc::EXIT_SUCCESS
} else {
libc::EXIT_FAILURE
};
}
}

View file

@ -31,9 +31,9 @@ fn chgrp<P: AsRef<Path>>(path: P, dgid: gid_t, follow: bool) -> IOResult<()> {
let s = CString::new(path.as_os_str().as_bytes()).unwrap();
let ret = unsafe {
if follow {
libc::chown(s.as_ptr(), (0 as gid_t).wrapping_sub(1), dgid)
libc::chown(s.as_ptr(), 0_u32.wrapping_sub(1), dgid)
} else {
lchown(s.as_ptr(), (0 as gid_t).wrapping_sub(1), dgid)
lchown(s.as_ptr(), 0_u32.wrapping_sub(1), dgid)
}
};
if ret == 0 {