Skip to content

Commit 4cdcfb7

Browse files
xtqqczzecakebaker
authored andcommitted
install: refactor conditional expression
1 parent 8c2d995 commit 4cdcfb7

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/uu/install/src/install.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,27 +1259,26 @@ fn need_copy(from: &Path, to: &Path, b: &Behavior) -> bool {
12591259
return true;
12601260
}
12611261

1262-
#[cfg(all(feature = "selinux", target_os = "linux"))]
1263-
if !b.unprivileged && b.preserve_context && contexts_differ(from, to) {
1264-
return true;
1265-
}
1262+
if !b.unprivileged {
1263+
#[cfg(all(feature = "selinux", target_os = "linux"))]
1264+
if b.preserve_context && contexts_differ(from, to) {
1265+
return true;
1266+
}
12661267

1267-
// TODO: if -P (#1809) and from/to contexts mismatch, return true.
1268+
// TODO: if -P (#1809) and from/to contexts mismatch, return true.
12681269

1269-
// Check if the owner ID is specified and differs from the destination file's owner.
1270-
if let Some(owner_id) = b.owner_id {
1271-
if !b.unprivileged && owner_id != to_meta.uid() {
1272-
return true;
1270+
// Check if the owner ID is specified and differs from the destination file's owner.
1271+
match b.owner_id {
1272+
Some(uid) if uid != to_meta.uid() => return true,
1273+
_ => {}
12731274
}
1274-
}
12751275

1276-
// Check if the group ID is specified and differs from the destination file's group.
1277-
if let Some(group_id) = b.group_id {
1278-
if !b.unprivileged && group_id != to_meta.gid() {
1279-
return true;
1276+
// Check if the group ID is specified and differs from the destination file's group.
1277+
match b.group_id {
1278+
Some(gid) if gid != to_meta.gid() => return true,
1279+
None if needs_copy_for_ownership(to, &to_meta) => return true,
1280+
_ => {}
12801281
}
1281-
} else if !b.unprivileged && needs_copy_for_ownership(to, &to_meta) {
1282-
return true;
12831282
}
12841283

12851284
// Check if the contents of the source and destination files differ.

0 commit comments

Comments
 (0)