Skip to content

Commit 5120da0

Browse files
xtqqczzecakebaker
authored andcommitted
1 parent 56cf4f9 commit 5120da0

6 files changed

Lines changed: 67 additions & 80 deletions

File tree

src/uu/chcon/src/chcon.rs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -537,33 +537,29 @@ fn process_file(
537537
let mut result = Ok(());
538538

539539
match entry.flags() {
540-
fts_sys::FTS_D => {
541-
if options.recursive_mode.is_recursive() {
542-
if root_dev_ino_check(root_dev_ino, file_dev_ino) {
543-
// This happens e.g., with "chcon -R --preserve-root ... /"
544-
// and with "chcon -RH --preserve-root ... symlink-to-root".
545-
root_dev_ino_warn(&file_full_name);
546-
547-
// Tell fts not to traverse into this hierarchy.
548-
let _ignored = fts.set(fts_sys::FTS_SKIP);
549-
550-
// Ensure that we do not process "/" on the second visit.
551-
let _ignored = fts.read_next_entry();
552-
553-
return Err(err(
554-
translate!("chcon-op-modifying-root-path"),
555-
io::ErrorKind::PermissionDenied,
556-
));
557-
}
540+
fts_sys::FTS_D if options.recursive_mode.is_recursive() => {
541+
if root_dev_ino_check(root_dev_ino, file_dev_ino) {
542+
// This happens e.g., with "chcon -R --preserve-root ... /"
543+
// and with "chcon -RH --preserve-root ... symlink-to-root".
544+
root_dev_ino_warn(&file_full_name);
558545

559-
return Ok(());
546+
// Tell fts not to traverse into this hierarchy.
547+
let _ignored = fts.set(fts_sys::FTS_SKIP);
548+
549+
// Ensure that we do not process "/" on the second visit.
550+
let _ignored = fts.read_next_entry();
551+
552+
return Err(err(
553+
translate!("chcon-op-modifying-root-path"),
554+
io::ErrorKind::PermissionDenied,
555+
));
560556
}
557+
558+
return Ok(());
561559
}
562560

563-
fts_sys::FTS_DP => {
564-
if !options.recursive_mode.is_recursive() {
565-
return Ok(());
566-
}
561+
fts_sys::FTS_DP if !options.recursive_mode.is_recursive() => {
562+
return Ok(());
567563
}
568564

569565
fts_sys::FTS_NS => {
@@ -585,14 +581,14 @@ fn process_file(
585581

586582
fts_sys::FTS_DNR => result = fts_err(translate!("chcon-op-reading-directory")),
587583

588-
fts_sys::FTS_DC => {
589-
if cycle_warning_required(options.recursive_mode.fts_open_options(), &entry) {
590-
emit_cycle_warning(&file_full_name);
591-
return Err(err(
592-
translate!("chcon-op-reading-cyclic-directory"),
593-
io::ErrorKind::InvalidData,
594-
));
595-
}
584+
fts_sys::FTS_DC
585+
if cycle_warning_required(options.recursive_mode.fts_open_options(), &entry) =>
586+
{
587+
emit_cycle_warning(&file_full_name);
588+
return Err(err(
589+
translate!("chcon-op-reading-cyclic-directory"),
590+
io::ErrorKind::InvalidData,
591+
));
596592
}
597593

598594
_ => {}

src/uu/cp/src/cp.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,10 +1134,8 @@ impl Options {
11341134
options::PRESERVE => {
11351135
attributes = attributes.union(&Attributes::parse_iter(val.into_iter())?);
11361136
}
1137-
options::NO_PRESERVE => {
1138-
if !val.is_empty() {
1139-
attributes = attributes.diff(&Attributes::parse_iter(val.into_iter())?);
1140-
}
1137+
options::NO_PRESERVE if !val.is_empty() => {
1138+
attributes = attributes.diff(&Attributes::parse_iter(val.into_iter())?);
11411139
}
11421140
_ => (),
11431141
}

src/uu/date/src/format_modifiers.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,9 @@ fn apply_modifiers(value: &str, parsed: &ParsedSpec<'_>) -> Result<String, Forma
379379
uppercase = true;
380380
swap_case = false; // ^ overrides #
381381
}
382-
'#' => {
383-
if !uppercase {
384-
// Only apply # if ^ hasn't been set
385-
swap_case = true;
386-
}
382+
'#' if !uppercase => {
383+
// Only apply # if ^ hasn't been set
384+
swap_case = true;
387385
}
388386
'+' => {
389387
force_sign = true;

src/uu/od/src/od.rs

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -132,38 +132,35 @@ impl OdOptions {
132132

133133
let formats = parse_format_flags(args).map_err(|e| USimpleError::new(1, e))?;
134134

135-
let mut line_bytes = match matches.get_one::<String>(options::WIDTH) {
136-
None => 16,
137-
Some(s) => {
138-
if matches.value_source(options::WIDTH) == Some(ValueSource::CommandLine) {
139-
let width_display = option_display_name(args, options::WIDTH, Some('w'));
140-
let parsed = parse_number_of_bytes(s).map_err(|e| {
141-
USimpleError::new(1, format_error_message(&e, s, &width_display))
142-
})?;
143-
if parsed == 0 {
144-
return Err(USimpleError::new(
145-
1,
146-
translate!(
147-
"od-error-invalid-argument",
148-
"option" => width_display.clone(),
149-
"value" => s.quote()
150-
),
151-
));
152-
}
153-
usize::try_from(parsed).map_err(|_| {
154-
USimpleError::new(
155-
1,
156-
translate!(
157-
"od-error-argument-too-large",
158-
"option" => width_display.clone(),
159-
"value" => s.quote()
160-
),
161-
)
162-
})?
163-
} else {
164-
16
165-
}
135+
let mut line_bytes = if let (Some(s), Some(ValueSource::CommandLine)) = (
136+
matches.get_one::<String>(options::WIDTH),
137+
matches.value_source(options::WIDTH),
138+
) {
139+
let width_display = option_display_name(args, options::WIDTH, Some('w'));
140+
let parsed = parse_number_of_bytes(s)
141+
.map_err(|e| USimpleError::new(1, format_error_message(&e, s, &width_display)))?;
142+
if parsed == 0 {
143+
return Err(USimpleError::new(
144+
1,
145+
translate!(
146+
"od-error-invalid-argument",
147+
"option" => width_display.clone(),
148+
"value" => s.quote()
149+
),
150+
));
166151
}
152+
usize::try_from(parsed).map_err(|_| {
153+
USimpleError::new(
154+
1,
155+
translate!(
156+
"od-error-argument-too-large",
157+
"option" => width_display.clone(),
158+
"value" => s.quote()
159+
),
160+
)
161+
})?
162+
} else {
163+
16
167164
};
168165

169166
let min_bytes = formats.iter().fold(1, |max, next| {

src/uu/tail/src/follow/watch.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ impl Observer {
439439
*/
440440
}
441441
}
442-
EventKind::Modify(ModifyKind::Name(RenameMode::Both)) => {
442+
EventKind::Modify(ModifyKind::Name(RenameMode::Both))
443443
/*
444444
NOTE: For `tail -f a`, keep tracking additions to b after `mv a b`
445445
(gnu/tests/tail-2/descriptor-vs-rename.sh)
@@ -457,7 +457,7 @@ impl Observer {
457457
TODO: [2022-05; jhscheer] add test for this bug
458458
*/
459459

460-
if self.follow_descriptor() {
460+
if self.follow_descriptor() => {
461461
let new_path = event.paths.last().unwrap();
462462
paths.push(new_path.clone());
463463

@@ -472,7 +472,6 @@ impl Observer {
472472
let _ = self.watcher_rx.as_mut().unwrap().unwatch(event_path);
473473
self.watcher_rx.as_mut().unwrap().watch_with_parent(new_path)?;
474474
}
475-
}
476475
_ => {}
477476
}
478477
Ok(paths)

src/uucore/src/lib/features/fs.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,11 @@ pub fn canonicalize<P: AsRef<Path>>(
435435
}
436436
result.pop();
437437
}
438-
Err(e) => {
439-
if miss_mode == MissingHandling::Existing
440-
|| (miss_mode == MissingHandling::Normal && !parts.is_empty())
441-
{
442-
return Err(e);
443-
}
438+
Err(e)
439+
if (miss_mode == MissingHandling::Existing
440+
|| (miss_mode == MissingHandling::Normal && !parts.is_empty())) =>
441+
{
442+
return Err(e);
444443
}
445444
_ => {}
446445
}

0 commit comments

Comments
 (0)