mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
fix clippy for unix
This commit is contained in:
parent
b465c34eef
commit
d67560c37a
12 changed files with 36 additions and 43 deletions
|
@ -286,7 +286,7 @@ impl Chgrper {
|
||||||
|
|
||||||
ret = match wrap_chgrp(path, &meta, self.dest_gid, follow, self.verbosity.clone()) {
|
ret = match wrap_chgrp(path, &meta, self.dest_gid, follow, self.verbosity.clone()) {
|
||||||
Ok(n) => {
|
Ok(n) => {
|
||||||
if n != "" {
|
if !n.is_empty() {
|
||||||
show_info!("{}", n);
|
show_info!("{}", n);
|
||||||
}
|
}
|
||||||
0
|
0
|
||||||
|
|
|
@ -171,13 +171,13 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
// of a prefix '-' if it's associated with MODE
|
// of a prefix '-' if it's associated with MODE
|
||||||
// e.g. "chmod -v -xw -R FILE" -> "chmod -v xw -R FILE"
|
// e.g. "chmod -v -xw -R FILE" -> "chmod -v xw -R FILE"
|
||||||
pub fn strip_minus_from_mode(args: &mut Vec<String>) -> bool {
|
pub fn strip_minus_from_mode(args: &mut Vec<String>) -> bool {
|
||||||
for i in 0..args.len() {
|
for arg in args {
|
||||||
if args[i].starts_with("-") {
|
if arg.starts_with('-') {
|
||||||
if let Some(second) = args[i].chars().nth(1) {
|
if let Some(second) = arg.chars().nth(1) {
|
||||||
match second {
|
match second {
|
||||||
'r' | 'w' | 'x' | 'X' | 's' | 't' | 'u' | 'g' | 'o' | '0'..='7' => {
|
'r' | 'w' | 'x' | 'X' | 's' | 't' | 'u' | 'g' | 'o' | '0'..='7' => {
|
||||||
// TODO: use strip_prefix() once minimum rust version reaches 1.45.0
|
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
@ -391,7 +391,7 @@ impl Chowner {
|
||||||
self.verbosity.clone(),
|
self.verbosity.clone(),
|
||||||
) {
|
) {
|
||||||
Ok(n) => {
|
Ok(n) => {
|
||||||
if n != "" {
|
if !n.is_empty() {
|
||||||
show_info!("{}", n);
|
show_info!("{}", n);
|
||||||
}
|
}
|
||||||
0
|
0
|
||||||
|
@ -446,7 +446,7 @@ impl Chowner {
|
||||||
self.verbosity.clone(),
|
self.verbosity.clone(),
|
||||||
) {
|
) {
|
||||||
Ok(n) => {
|
Ok(n) => {
|
||||||
if n != "" {
|
if !n.is_empty() {
|
||||||
show_info!("{}", n);
|
show_info!("{}", n);
|
||||||
}
|
}
|
||||||
0
|
0
|
||||||
|
|
|
@ -104,7 +104,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
_ => {
|
_ => {
|
||||||
let mut vector: Vec<&str> = Vec::new();
|
let mut vector: Vec<&str> = Vec::new();
|
||||||
for (&k, v) in matches.args.iter() {
|
for (&k, v) in matches.args.iter() {
|
||||||
vector.push(k.clone());
|
vector.push(k);
|
||||||
vector.push(&v.vals[0].to_str().unwrap());
|
vector.push(&v.vals[0].to_str().unwrap());
|
||||||
}
|
}
|
||||||
vector
|
vector
|
||||||
|
@ -133,7 +133,7 @@ fn set_context(root: &Path, options: &clap::ArgMatches) {
|
||||||
let userspec = match userspec_str {
|
let userspec = match userspec_str {
|
||||||
Some(ref u) => {
|
Some(ref u) => {
|
||||||
let s: Vec<&str> = u.split(':').collect();
|
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)
|
crash!(1, "invalid userspec: `{}`", u)
|
||||||
};
|
};
|
||||||
s
|
s
|
||||||
|
@ -142,16 +142,16 @@ fn set_context(root: &Path, options: &clap::ArgMatches) {
|
||||||
};
|
};
|
||||||
|
|
||||||
let (user, group) = if userspec.is_empty() {
|
let (user, group) = if userspec.is_empty() {
|
||||||
(&user_str[..], &group_str[..])
|
(user_str, group_str)
|
||||||
} else {
|
} else {
|
||||||
(&userspec[0][..], &userspec[1][..])
|
(userspec[0], userspec[1])
|
||||||
};
|
};
|
||||||
|
|
||||||
enter_chroot(root);
|
enter_chroot(root);
|
||||||
|
|
||||||
set_groups_from_str(&groups_str[..]);
|
set_groups_from_str(groups_str);
|
||||||
set_main_group(&group[..]);
|
set_main_group(group);
|
||||||
set_user(&user[..]);
|
set_user(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enter_chroot(root: &Path) {
|
fn enter_chroot(root: &Path) {
|
||||||
|
|
|
@ -302,7 +302,7 @@ fn behavior(matches: &ArgMatches) -> Result<Behavior, i32> {
|
||||||
|
|
||||||
let specified_mode: Option<u32> = if matches.is_present(OPT_MODE) {
|
let specified_mode: Option<u32> = if matches.is_present(OPT_MODE) {
|
||||||
match matches.value_of(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),
|
Ok(y) => Some(y),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
show_error!("Invalid mode string: {}", 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.
|
/// _files_ must all exist as non-directories.
|
||||||
/// _target_dir_ must be a directory.
|
/// _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() {
|
if !target_dir.is_dir() {
|
||||||
show_error!("target '{}' is not a directory", target_dir.display());
|
show_error!("target '{}' is not a directory", target_dir.display());
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -453,7 +453,7 @@ fn copy_files_into_dir(files: &[PathBuf], target_dir: &PathBuf, b: &Behavior) ->
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut targetpath = target_dir.clone().to_path_buf();
|
let mut targetpath = target_dir.to_path_buf();
|
||||||
let filename = sourcepath.components().last().unwrap();
|
let filename = sourcepath.components().last().unwrap();
|
||||||
targetpath.push(filename);
|
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.
|
/// _file_ must exist as a non-directory.
|
||||||
/// _target_ must be 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() {
|
if copy(file, &target, b).is_err() {
|
||||||
1
|
1
|
||||||
} else {
|
} 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.
|
/// 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) {
|
if b.compare && !need_copy(from, to, b) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -556,7 +556,7 @@ fn copy(from: &PathBuf, to: &PathBuf, b: &Behavior) -> Result<(), ()> {
|
||||||
};
|
};
|
||||||
let gid = meta.gid();
|
let gid = meta.gid();
|
||||||
match wrap_chown(
|
match wrap_chown(
|
||||||
to.as_path(),
|
to,
|
||||||
&meta,
|
&meta,
|
||||||
Some(owner_id),
|
Some(owner_id),
|
||||||
Some(gid),
|
Some(gid),
|
||||||
|
@ -582,7 +582,7 @@ fn copy(from: &PathBuf, to: &PathBuf, b: &Behavior) -> Result<(), ()> {
|
||||||
Ok(g) => g,
|
Ok(g) => g,
|
||||||
_ => crash!(1, "no such group: {}", b.group),
|
_ => 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) => {
|
Ok(n) => {
|
||||||
if !n.is_empty() {
|
if !n.is_empty() {
|
||||||
show_info!("{}", n);
|
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 modified_time = FileTime::from_last_modification_time(&meta);
|
||||||
let accessed_time = FileTime::from_last_access_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(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => show_info!("{}", e),
|
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_.
|
/// 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) {
|
let from_meta = match fs::metadata(from) {
|
||||||
Ok(meta) => meta,
|
Ok(meta) => meta,
|
||||||
Err(_) => return true,
|
Err(_) => return true,
|
||||||
|
|
|
@ -370,6 +370,7 @@ impl Config {
|
||||||
})
|
})
|
||||||
.or_else(|| termsize::get().map(|s| s.cols));
|
.or_else(|| termsize::get().map(|s| s.cols));
|
||||||
|
|
||||||
|
#[allow(clippy::needless_bool)]
|
||||||
let show_control = if options.is_present(options::HIDE_CONTROL_CHARS) {
|
let show_control = if options.is_present(options::HIDE_CONTROL_CHARS) {
|
||||||
false
|
false
|
||||||
} else if options.is_present(options::SHOW_CONTROL_CHARS) {
|
} else if options.is_present(options::SHOW_CONTROL_CHARS) {
|
||||||
|
|
|
@ -15,7 +15,6 @@ use uucore::utmpx::{self, time, Utmpx};
|
||||||
|
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::io::Result as IOResult;
|
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
|
@ -136,12 +135,8 @@ The utmp file will be {}",
|
||||||
};
|
};
|
||||||
|
|
||||||
if do_short_format {
|
if do_short_format {
|
||||||
if let Err(e) = pk.short_pinky() {
|
pk.short_pinky();
|
||||||
show_usage_error!("{}", e);
|
|
||||||
1
|
|
||||||
} else {
|
|
||||||
0
|
0
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
pk.long_pinky()
|
pk.long_pinky()
|
||||||
}
|
}
|
||||||
|
@ -282,7 +277,7 @@ impl Pinky {
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn short_pinky(&self) -> IOResult<()> {
|
fn short_pinky(&self) {
|
||||||
if self.include_heading {
|
if self.include_heading {
|
||||||
self.print_heading();
|
self.print_heading();
|
||||||
}
|
}
|
||||||
|
@ -295,7 +290,6 @@ impl Pinky {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn long_pinky(&self) -> i32 {
|
fn long_pinky(&self) -> i32 {
|
||||||
|
|
|
@ -35,8 +35,8 @@ extern "C" {
|
||||||
|
|
||||||
fn set_buffer(stream: *mut FILE, value: &str) {
|
fn set_buffer(stream: *mut FILE, value: &str) {
|
||||||
let (mode, size): (c_int, size_t) = match value {
|
let (mode, size): (c_int, size_t) = match value {
|
||||||
"0" => (_IONBF, 0 as size_t),
|
"0" => (_IONBF, 0_usize),
|
||||||
"L" => (_IOLBF, 0 as size_t),
|
"L" => (_IOLBF, 0_usize),
|
||||||
input => {
|
input => {
|
||||||
let buff_size: usize = match input.parse() {
|
let buff_size: usize = match input.parse() {
|
||||||
Ok(num) => num,
|
Ok(num) => num,
|
||||||
|
|
|
@ -141,12 +141,10 @@ fn parse_size(size: &str) -> Option<u64> {
|
||||||
|
|
||||||
fn check_option(matches: &ArgMatches, name: &str) -> Result<BufferType, ProgramOptionsError> {
|
fn check_option(matches: &ArgMatches, name: &str) -> Result<BufferType, ProgramOptionsError> {
|
||||||
match matches.value_of(name) {
|
match matches.value_of(name) {
|
||||||
Some(value) => match &value[..] {
|
Some(value) => match value {
|
||||||
"L" => {
|
"L" => {
|
||||||
if name == options::INPUT {
|
if name == options::INPUT {
|
||||||
Err(ProgramOptionsError(format!(
|
Err(ProgramOptionsError("line buffering stdin is meaningless".to_string()))
|
||||||
"line buffering stdin is meaningless"
|
|
||||||
)))
|
|
||||||
} else {
|
} else {
|
||||||
Ok(BufferType::Line)
|
Ok(BufferType::Line)
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
|
|
||||||
let (mut atime, mut mtime) = if matches.is_present(options::sources::REFERENCE) {
|
let (mut atime, mut mtime) = if matches.is_present(options::sources::REFERENCE) {
|
||||||
stat(
|
stat(
|
||||||
&matches.value_of(options::sources::REFERENCE).unwrap()[..],
|
matches.value_of(options::sources::REFERENCE).unwrap(),
|
||||||
!matches.is_present(options::NO_DEREF),
|
!matches.is_present(options::NO_DEREF),
|
||||||
)
|
)
|
||||||
} else if matches.is_present(options::sources::DATE)
|
} else if matches.is_present(options::sources::DATE)
|
||||||
|
|
|
@ -65,9 +65,9 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return if is_stdin_interactive() {
|
if is_stdin_interactive() {
|
||||||
libc::EXIT_SUCCESS
|
libc::EXIT_SUCCESS
|
||||||
} else {
|
} else {
|
||||||
libc::EXIT_FAILURE
|
libc::EXIT_FAILURE
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 s = CString::new(path.as_os_str().as_bytes()).unwrap();
|
||||||
let ret = unsafe {
|
let ret = unsafe {
|
||||||
if follow {
|
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 {
|
} 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 {
|
if ret == 0 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue