mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
Merge pull request #7724 from nyurik/ref-option
chore: fix `ref_option` lint
This commit is contained in:
commit
e4c7bd0641
11 changed files with 45 additions and 44 deletions
|
@ -600,3 +600,4 @@ unused_qualifications = "warn"
|
||||||
[workspace.lints.clippy]
|
[workspace.lints.clippy]
|
||||||
all = { level = "deny", priority = -1 }
|
all = { level = "deny", priority = -1 }
|
||||||
#cargo = { level = "warn", priority = -1 }
|
#cargo = { level = "warn", priority = -1 }
|
||||||
|
ref_option = "warn"
|
||||||
|
|
|
@ -390,7 +390,7 @@ fn handle_missing_groups(strategy: Strategy) -> Result<(), ChrootError> {
|
||||||
/// Set supplemental groups for this process.
|
/// Set supplemental groups for this process.
|
||||||
fn set_supplemental_gids_with_strategy(
|
fn set_supplemental_gids_with_strategy(
|
||||||
strategy: Strategy,
|
strategy: Strategy,
|
||||||
groups: &Option<Vec<String>>,
|
groups: Option<&Vec<String>>,
|
||||||
) -> Result<(), ChrootError> {
|
) -> Result<(), ChrootError> {
|
||||||
match groups {
|
match groups {
|
||||||
None => handle_missing_groups(strategy),
|
None => handle_missing_groups(strategy),
|
||||||
|
@ -410,27 +410,27 @@ fn set_context(options: &Options) -> UResult<()> {
|
||||||
match &options.userspec {
|
match &options.userspec {
|
||||||
None | Some(UserSpec::NeitherGroupNorUser) => {
|
None | Some(UserSpec::NeitherGroupNorUser) => {
|
||||||
let strategy = Strategy::Nothing;
|
let strategy = Strategy::Nothing;
|
||||||
set_supplemental_gids_with_strategy(strategy, &options.groups)?;
|
set_supplemental_gids_with_strategy(strategy, options.groups.as_ref())?;
|
||||||
}
|
}
|
||||||
Some(UserSpec::UserOnly(user)) => {
|
Some(UserSpec::UserOnly(user)) => {
|
||||||
let uid = name_to_uid(user)?;
|
let uid = name_to_uid(user)?;
|
||||||
let gid = uid as libc::gid_t;
|
let gid = uid as libc::gid_t;
|
||||||
let strategy = Strategy::FromUID(uid, false);
|
let strategy = Strategy::FromUID(uid, false);
|
||||||
set_supplemental_gids_with_strategy(strategy, &options.groups)?;
|
set_supplemental_gids_with_strategy(strategy, options.groups.as_ref())?;
|
||||||
set_gid(gid).map_err(|e| ChrootError::SetGidFailed(user.to_string(), e))?;
|
set_gid(gid).map_err(|e| ChrootError::SetGidFailed(user.to_string(), e))?;
|
||||||
set_uid(uid).map_err(|e| ChrootError::SetUserFailed(user.to_string(), e))?;
|
set_uid(uid).map_err(|e| ChrootError::SetUserFailed(user.to_string(), e))?;
|
||||||
}
|
}
|
||||||
Some(UserSpec::GroupOnly(group)) => {
|
Some(UserSpec::GroupOnly(group)) => {
|
||||||
let gid = name_to_gid(group)?;
|
let gid = name_to_gid(group)?;
|
||||||
let strategy = Strategy::Nothing;
|
let strategy = Strategy::Nothing;
|
||||||
set_supplemental_gids_with_strategy(strategy, &options.groups)?;
|
set_supplemental_gids_with_strategy(strategy, options.groups.as_ref())?;
|
||||||
set_gid(gid).map_err(|e| ChrootError::SetGidFailed(group.to_string(), e))?;
|
set_gid(gid).map_err(|e| ChrootError::SetGidFailed(group.to_string(), e))?;
|
||||||
}
|
}
|
||||||
Some(UserSpec::UserAndGroup(user, group)) => {
|
Some(UserSpec::UserAndGroup(user, group)) => {
|
||||||
let uid = name_to_uid(user)?;
|
let uid = name_to_uid(user)?;
|
||||||
let gid = name_to_gid(group)?;
|
let gid = name_to_gid(group)?;
|
||||||
let strategy = Strategy::FromUID(uid, true);
|
let strategy = Strategy::FromUID(uid, true);
|
||||||
set_supplemental_gids_with_strategy(strategy, &options.groups)?;
|
set_supplemental_gids_with_strategy(strategy, options.groups.as_ref())?;
|
||||||
set_gid(gid).map_err(|e| ChrootError::SetGidFailed(group.to_string(), e))?;
|
set_gid(gid).map_err(|e| ChrootError::SetGidFailed(group.to_string(), e))?;
|
||||||
set_uid(uid).map_err(|e| ChrootError::SetUserFailed(user.to_string(), e))?;
|
set_uid(uid).map_err(|e| ChrootError::SetUserFailed(user.to_string(), e))?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,7 +224,7 @@ where
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
/// Copy a single entry during a directory traversal.
|
/// Copy a single entry during a directory traversal.
|
||||||
fn copy_direntry(
|
fn copy_direntry(
|
||||||
progress_bar: &Option<ProgressBar>,
|
progress_bar: Option<&ProgressBar>,
|
||||||
entry: Entry,
|
entry: Entry,
|
||||||
options: &Options,
|
options: &Options,
|
||||||
symlinked_files: &mut HashSet<FileInformation>,
|
symlinked_files: &mut HashSet<FileInformation>,
|
||||||
|
@ -314,7 +314,7 @@ fn copy_direntry(
|
||||||
/// will not cause a short-circuit.
|
/// will not cause a short-circuit.
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub(crate) fn copy_directory(
|
pub(crate) fn copy_directory(
|
||||||
progress_bar: &Option<ProgressBar>,
|
progress_bar: Option<&ProgressBar>,
|
||||||
root: &Path,
|
root: &Path,
|
||||||
target: &Path,
|
target: &Path,
|
||||||
options: &Options,
|
options: &Options,
|
||||||
|
|
|
@ -1366,7 +1366,7 @@ pub fn copy(sources: &[PathBuf], target: &Path, options: &Options) -> CopyResult
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(error) = copy_source(
|
if let Err(error) = copy_source(
|
||||||
&progress_bar,
|
progress_bar.as_ref(),
|
||||||
source,
|
source,
|
||||||
target,
|
target,
|
||||||
target_type,
|
target_type,
|
||||||
|
@ -1433,7 +1433,7 @@ fn construct_dest_path(
|
||||||
}
|
}
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn copy_source(
|
fn copy_source(
|
||||||
progress_bar: &Option<ProgressBar>,
|
progress_bar: Option<&ProgressBar>,
|
||||||
source: &Path,
|
source: &Path,
|
||||||
target: &Path,
|
target: &Path,
|
||||||
target_type: TargetType,
|
target_type: TargetType,
|
||||||
|
@ -1979,7 +1979,7 @@ fn aligned_ancestors<'a>(source: &'a Path, dest: &'a Path) -> Vec<(&'a Path, &'a
|
||||||
|
|
||||||
fn print_verbose_output(
|
fn print_verbose_output(
|
||||||
parents: bool,
|
parents: bool,
|
||||||
progress_bar: &Option<ProgressBar>,
|
progress_bar: Option<&ProgressBar>,
|
||||||
source: &Path,
|
source: &Path,
|
||||||
dest: &Path,
|
dest: &Path,
|
||||||
) {
|
) {
|
||||||
|
@ -2207,7 +2207,7 @@ fn calculate_dest_permissions(
|
||||||
/// after a successful copy.
|
/// after a successful copy.
|
||||||
#[allow(clippy::cognitive_complexity, clippy::too_many_arguments)]
|
#[allow(clippy::cognitive_complexity, clippy::too_many_arguments)]
|
||||||
fn copy_file(
|
fn copy_file(
|
||||||
progress_bar: &Option<ProgressBar>,
|
progress_bar: Option<&ProgressBar>,
|
||||||
source: &Path,
|
source: &Path,
|
||||||
dest: &Path,
|
dest: &Path,
|
||||||
options: &Options,
|
options: &Options,
|
||||||
|
|
|
@ -1106,13 +1106,13 @@ fn dd_copy(mut i: Input, o: Output) -> io::Result<()> {
|
||||||
// blocks to this output. Read/write statistics are updated on
|
// blocks to this output. Read/write statistics are updated on
|
||||||
// each iteration and cumulative statistics are reported to
|
// each iteration and cumulative statistics are reported to
|
||||||
// the progress reporting thread.
|
// the progress reporting thread.
|
||||||
while below_count_limit(&i.settings.count, &rstat) {
|
while below_count_limit(i.settings.count, &rstat) {
|
||||||
// Read a block from the input then write the block to the output.
|
// Read a block from the input then write the block to the output.
|
||||||
//
|
//
|
||||||
// As an optimization, make an educated guess about the
|
// As an optimization, make an educated guess about the
|
||||||
// best buffer size for reading based on the number of
|
// best buffer size for reading based on the number of
|
||||||
// blocks already read and the number of blocks remaining.
|
// blocks already read and the number of blocks remaining.
|
||||||
let loop_bsize = calc_loop_bsize(&i.settings.count, &rstat, &wstat, i.settings.ibs, bsize);
|
let loop_bsize = calc_loop_bsize(i.settings.count, &rstat, &wstat, i.settings.ibs, bsize);
|
||||||
let rstat_update = read_helper(&mut i, &mut buf, loop_bsize)?;
|
let rstat_update = read_helper(&mut i, &mut buf, loop_bsize)?;
|
||||||
if rstat_update.is_empty() {
|
if rstat_update.is_empty() {
|
||||||
break;
|
break;
|
||||||
|
@ -1295,7 +1295,7 @@ fn calc_bsize(ibs: usize, obs: usize) -> usize {
|
||||||
// Calculate the buffer size appropriate for this loop iteration, respecting
|
// Calculate the buffer size appropriate for this loop iteration, respecting
|
||||||
// a count=N if present.
|
// a count=N if present.
|
||||||
fn calc_loop_bsize(
|
fn calc_loop_bsize(
|
||||||
count: &Option<Num>,
|
count: Option<Num>,
|
||||||
rstat: &ReadStat,
|
rstat: &ReadStat,
|
||||||
wstat: &WriteStat,
|
wstat: &WriteStat,
|
||||||
ibs: usize,
|
ibs: usize,
|
||||||
|
@ -1308,7 +1308,7 @@ fn calc_loop_bsize(
|
||||||
cmp::min(ideal_bsize as u64, rremain * ibs as u64) as usize
|
cmp::min(ideal_bsize as u64, rremain * ibs as u64) as usize
|
||||||
}
|
}
|
||||||
Some(Num::Bytes(bmax)) => {
|
Some(Num::Bytes(bmax)) => {
|
||||||
let bmax: u128 = (*bmax).into();
|
let bmax: u128 = bmax.into();
|
||||||
let bremain: u128 = bmax - wstat.bytes_total;
|
let bremain: u128 = bmax - wstat.bytes_total;
|
||||||
cmp::min(ideal_bsize as u128, bremain) as usize
|
cmp::min(ideal_bsize as u128, bremain) as usize
|
||||||
}
|
}
|
||||||
|
@ -1318,10 +1318,10 @@ fn calc_loop_bsize(
|
||||||
|
|
||||||
// Decide if the current progress is below a count=N limit or return
|
// Decide if the current progress is below a count=N limit or return
|
||||||
// true if no such limit is set.
|
// true if no such limit is set.
|
||||||
fn below_count_limit(count: &Option<Num>, rstat: &ReadStat) -> bool {
|
fn below_count_limit(count: Option<Num>, rstat: &ReadStat) -> bool {
|
||||||
match count {
|
match count {
|
||||||
Some(Num::Blocks(n)) => rstat.reads_complete + rstat.reads_partial < *n,
|
Some(Num::Blocks(n)) => rstat.reads_complete + rstat.reads_partial < n,
|
||||||
Some(Num::Bytes(n)) => rstat.bytes_total < *n,
|
Some(Num::Bytes(n)) => rstat.bytes_total < n,
|
||||||
None => true,
|
None => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1085,7 +1085,7 @@ fn write_columns(
|
||||||
for (i, cell) in row.iter().enumerate() {
|
for (i, cell) in row.iter().enumerate() {
|
||||||
if cell.is_none() && options.merge_files_print.is_some() {
|
if cell.is_none() && options.merge_files_print.is_some() {
|
||||||
out.write_all(
|
out.write_all(
|
||||||
get_line_for_printing(options, &blank_line, columns, i, &line_width, indexes)
|
get_line_for_printing(options, &blank_line, columns, i, line_width, indexes)
|
||||||
.as_bytes(),
|
.as_bytes(),
|
||||||
)?;
|
)?;
|
||||||
} else if cell.is_none() {
|
} else if cell.is_none() {
|
||||||
|
@ -1095,7 +1095,7 @@ fn write_columns(
|
||||||
let file_line = cell.unwrap();
|
let file_line = cell.unwrap();
|
||||||
|
|
||||||
out.write_all(
|
out.write_all(
|
||||||
get_line_for_printing(options, file_line, columns, i, &line_width, indexes)
|
get_line_for_printing(options, file_line, columns, i, line_width, indexes)
|
||||||
.as_bytes(),
|
.as_bytes(),
|
||||||
)?;
|
)?;
|
||||||
lines_printed += 1;
|
lines_printed += 1;
|
||||||
|
@ -1116,7 +1116,7 @@ fn get_line_for_printing(
|
||||||
file_line: &FileLine,
|
file_line: &FileLine,
|
||||||
columns: usize,
|
columns: usize,
|
||||||
index: usize,
|
index: usize,
|
||||||
line_width: &Option<usize>,
|
line_width: Option<usize>,
|
||||||
indexes: usize,
|
indexes: usize,
|
||||||
) -> String {
|
) -> String {
|
||||||
let blank_line = String::new();
|
let blank_line = String::new();
|
||||||
|
|
|
@ -121,7 +121,7 @@ impl Drop for FilterWriter {
|
||||||
|
|
||||||
/// Instantiate either a file writer or a "write to shell process's stdin" writer
|
/// Instantiate either a file writer or a "write to shell process's stdin" writer
|
||||||
pub fn instantiate_current_writer(
|
pub fn instantiate_current_writer(
|
||||||
filter: &Option<String>,
|
filter: Option<&str>,
|
||||||
filename: &str,
|
filename: &str,
|
||||||
is_new: bool,
|
is_new: bool,
|
||||||
) -> Result<BufWriter<Box<dyn Write>>> {
|
) -> Result<BufWriter<Box<dyn Write>>> {
|
||||||
|
|
|
@ -12,7 +12,7 @@ use uucore::fs;
|
||||||
/// Unlike the unix version of this function, this _always_ returns
|
/// Unlike the unix version of this function, this _always_ returns
|
||||||
/// a file writer
|
/// a file writer
|
||||||
pub fn instantiate_current_writer(
|
pub fn instantiate_current_writer(
|
||||||
_filter: &Option<String>,
|
_filter: Option<&str>,
|
||||||
filename: &str,
|
filename: &str,
|
||||||
is_new: bool,
|
is_new: bool,
|
||||||
) -> Result<BufWriter<Box<dyn Write>>> {
|
) -> Result<BufWriter<Box<dyn Write>>> {
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let (args, obs_lines) = handle_obsolete(args);
|
let (args, obs_lines) = handle_obsolete(args);
|
||||||
let matches = uu_app().try_get_matches_from(args)?;
|
let matches = uu_app().try_get_matches_from(args)?;
|
||||||
|
|
||||||
match Settings::from(&matches, &obs_lines) {
|
match Settings::from(&matches, obs_lines.as_deref()) {
|
||||||
Ok(settings) => split(&settings),
|
Ok(settings) => split(&settings),
|
||||||
Err(e) if e.requires_usage() => Err(UUsageError::new(1, format!("{e}"))),
|
Err(e) if e.requires_usage() => Err(UUsageError::new(1, format!("{e}"))),
|
||||||
Err(e) => Err(USimpleError::new(1, format!("{e}"))),
|
Err(e) => Err(USimpleError::new(1, format!("{e}"))),
|
||||||
|
@ -460,7 +460,7 @@ impl SettingsError {
|
||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
/// Parse a strategy from the command-line arguments.
|
/// Parse a strategy from the command-line arguments.
|
||||||
fn from(matches: &ArgMatches, obs_lines: &Option<String>) -> Result<Self, SettingsError> {
|
fn from(matches: &ArgMatches, obs_lines: Option<&str>) -> Result<Self, SettingsError> {
|
||||||
let strategy = Strategy::from(matches, obs_lines).map_err(SettingsError::Strategy)?;
|
let strategy = Strategy::from(matches, obs_lines).map_err(SettingsError::Strategy)?;
|
||||||
let suffix = Suffix::from(matches, &strategy).map_err(SettingsError::Suffix)?;
|
let suffix = Suffix::from(matches, &strategy).map_err(SettingsError::Suffix)?;
|
||||||
|
|
||||||
|
@ -541,7 +541,7 @@ impl Settings {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
platform::instantiate_current_writer(&self.filter, filename, is_new)
|
platform::instantiate_current_writer(self.filter.as_deref(), filename, is_new)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -607,14 +607,14 @@ fn get_input_size<R>(
|
||||||
input: &String,
|
input: &String,
|
||||||
reader: &mut R,
|
reader: &mut R,
|
||||||
buf: &mut Vec<u8>,
|
buf: &mut Vec<u8>,
|
||||||
io_blksize: &Option<u64>,
|
io_blksize: Option<u64>,
|
||||||
) -> io::Result<u64>
|
) -> io::Result<u64>
|
||||||
where
|
where
|
||||||
R: BufRead,
|
R: BufRead,
|
||||||
{
|
{
|
||||||
// Set read limit to io_blksize if specified
|
// Set read limit to io_blksize if specified
|
||||||
let read_limit: u64 = if let Some(custom_blksize) = io_blksize {
|
let read_limit: u64 = if let Some(custom_blksize) = io_blksize {
|
||||||
*custom_blksize
|
custom_blksize
|
||||||
} else {
|
} else {
|
||||||
// otherwise try to get it from filesystem, or use default
|
// otherwise try to get it from filesystem, or use default
|
||||||
uucore::fs::sane_blksize::sane_blksize_from_path(Path::new(input))
|
uucore::fs::sane_blksize::sane_blksize_from_path(Path::new(input))
|
||||||
|
@ -1084,7 +1084,7 @@ where
|
||||||
{
|
{
|
||||||
// Get the size of the input in bytes
|
// Get the size of the input in bytes
|
||||||
let initial_buf = &mut Vec::new();
|
let initial_buf = &mut Vec::new();
|
||||||
let mut num_bytes = get_input_size(&settings.input, reader, initial_buf, &settings.io_blksize)?;
|
let mut num_bytes = get_input_size(&settings.input, reader, initial_buf, settings.io_blksize)?;
|
||||||
let mut reader = initial_buf.chain(reader);
|
let mut reader = initial_buf.chain(reader);
|
||||||
|
|
||||||
// If input file is empty and we would not have determined the Kth chunk
|
// If input file is empty and we would not have determined the Kth chunk
|
||||||
|
@ -1230,7 +1230,7 @@ where
|
||||||
// Get the size of the input in bytes and compute the number
|
// Get the size of the input in bytes and compute the number
|
||||||
// of bytes per chunk.
|
// of bytes per chunk.
|
||||||
let initial_buf = &mut Vec::new();
|
let initial_buf = &mut Vec::new();
|
||||||
let num_bytes = get_input_size(&settings.input, reader, initial_buf, &settings.io_blksize)?;
|
let num_bytes = get_input_size(&settings.input, reader, initial_buf, settings.io_blksize)?;
|
||||||
let reader = initial_buf.chain(reader);
|
let reader = initial_buf.chain(reader);
|
||||||
|
|
||||||
// If input file is empty and we would not have determined the Kth chunk
|
// If input file is empty and we would not have determined the Kth chunk
|
||||||
|
|
|
@ -214,7 +214,7 @@ pub enum StrategyError {
|
||||||
|
|
||||||
impl Strategy {
|
impl Strategy {
|
||||||
/// Parse a strategy from the command-line arguments.
|
/// Parse a strategy from the command-line arguments.
|
||||||
pub fn from(matches: &ArgMatches, obs_lines: &Option<String>) -> Result<Self, StrategyError> {
|
pub fn from(matches: &ArgMatches, obs_lines: Option<&str>) -> Result<Self, StrategyError> {
|
||||||
fn get_and_parse(
|
fn get_and_parse(
|
||||||
matches: &ArgMatches,
|
matches: &ArgMatches,
|
||||||
option: &str,
|
option: &str,
|
||||||
|
|
|
@ -156,20 +156,20 @@ fn get_year(s: &str) -> u8 {
|
||||||
fn is_first_filename_timestamp(
|
fn is_first_filename_timestamp(
|
||||||
reference: Option<&OsString>,
|
reference: Option<&OsString>,
|
||||||
date: Option<&str>,
|
date: Option<&str>,
|
||||||
timestamp: &Option<String>,
|
timestamp: Option<&str>,
|
||||||
files: &[&String],
|
files: &[&String],
|
||||||
) -> bool {
|
) -> bool {
|
||||||
match std::env::var("_POSIX2_VERSION") {
|
if timestamp.is_none()
|
||||||
Ok(s) if s == "199209" => {
|
&& reference.is_none()
|
||||||
if timestamp.is_none() && reference.is_none() && date.is_none() && files.len() >= 2 {
|
&& date.is_none()
|
||||||
let s = files[0];
|
&& files.len() >= 2
|
||||||
all_digits(s)
|
// env check is last as the slowest op
|
||||||
&& (s.len() == 8 || (s.len() == 10 && (69..=99).contains(&get_year(s))))
|
&& matches!(std::env::var("_POSIX2_VERSION").as_deref(), Ok("199209"))
|
||||||
} else {
|
{
|
||||||
false
|
let s = files[0];
|
||||||
}
|
all_digits(s) && (s.len() == 8 || (s.len() == 10 && (69..=99).contains(&get_year(s))))
|
||||||
}
|
} else {
|
||||||
_ => false,
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
.get_one::<String>(options::sources::TIMESTAMP)
|
.get_one::<String>(options::sources::TIMESTAMP)
|
||||||
.map(|t| t.to_owned());
|
.map(|t| t.to_owned());
|
||||||
|
|
||||||
if is_first_filename_timestamp(reference, date.as_deref(), ×tamp, &filenames) {
|
if is_first_filename_timestamp(reference, date.as_deref(), timestamp.as_deref(), &filenames) {
|
||||||
timestamp = if filenames[0].len() == 10 {
|
timestamp = if filenames[0].len() == 10 {
|
||||||
Some(shr2(filenames[0]))
|
Some(shr2(filenames[0]))
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue