Skip to content

Commit

Permalink
repair sequoia: sort group members by the numbers in their name (#1448)
Browse files Browse the repository at this point in the history
It's possbile that the output of the dscl command has the group members
out-of-order.
  • Loading branch information
cole-h authored Feb 21, 2025
1 parent 2f1c358 commit f61de70
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/cli/subcommand/repair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,33 @@ impl CommandExecute for Repair {
group_plist
};

let expected_users = group_plist
.group_membership
let mut group_members = group_plist.group_membership;
group_members.sort_by(|a, b| {
let a = a
.trim_start_matches(|c: char| !c.is_numeric())
.parse::<u32>()
.unwrap_or_else(|_| {
tracing::warn!(
member = a,
"Group member had no numbers in their name?"
);
0
});
let b = b
.trim_start_matches(|c: char| !c.is_numeric())
.parse::<u32>()
.unwrap_or_else(|_| {
tracing::warn!(
member = b,
"Group member had no numbers in their name?"
);
0
});

a.cmp(&b)
});

let expected_users = group_members
.into_iter()
.enumerate()
.map(|(idx, name)| ((idx + 1) as u32, name))
Expand Down

0 comments on commit f61de70

Please sign in to comment.