Skip to content

Commit eca185b

Browse files
authored
replace nix getgroups by rustix (#12269)
1 parent b1c267f commit eca185b

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

tests/by-util/test_chgrp.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// file that was distributed with this source code.
55
// spell-checker:ignore (words) nosuchgroup groupname
66

7+
#[cfg(not(target_vendor = "apple"))]
8+
use rustix::process::getgroups;
79
#[cfg(target_os = "linux")]
810
use std::os::unix::ffi::OsStringExt;
911
use uucore::process::getegid;
@@ -299,9 +301,8 @@ fn test_big_h() {
299301
#[cfg(not(target_vendor = "apple"))]
300302
fn basic_succeeds() {
301303
let (at, mut ucmd) = at_and_ucmd!();
302-
let one_group = nix::unistd::getgroups().unwrap();
303304
// if there are no groups we can't run this test.
304-
if let Some(group) = one_group.first() {
305+
if let Some(group) = getgroups().unwrap().first() {
305306
at.touch("f1");
306307
ucmd.arg(group.as_raw().to_string())
307308
.arg("f1")
@@ -322,7 +323,7 @@ fn test_no_change() {
322323
fn test_permission_denied() {
323324
use std::os::unix::prelude::PermissionsExt;
324325

325-
if let Some(group) = nix::unistd::getgroups().unwrap().first() {
326+
if let Some(group) = getgroups().unwrap().first() {
326327
let (at, mut ucmd) = at_and_ucmd!();
327328
at.mkdir("dir");
328329
at.touch("dir/file");
@@ -340,7 +341,7 @@ fn test_permission_denied() {
340341
fn test_subdir_permission_denied() {
341342
use std::os::unix::prelude::PermissionsExt;
342343

343-
if let Some(group) = nix::unistd::getgroups().unwrap().first() {
344+
if let Some(group) = getgroups().unwrap().first() {
344345
let (at, mut ucmd) = at_and_ucmd!();
345346
at.mkdir("dir");
346347
at.mkdir("dir/subdir");
@@ -358,7 +359,7 @@ fn test_subdir_permission_denied() {
358359
#[cfg(not(target_vendor = "apple"))]
359360
fn test_traverse_symlinks() {
360361
use std::os::unix::prelude::MetadataExt;
361-
let groups = nix::unistd::getgroups().unwrap();
362+
let groups = getgroups().unwrap();
362363
if groups.len() < 2 {
363364
return;
364365
}
@@ -431,7 +432,7 @@ fn test_from_option() {
431432
use std::os::unix::fs::MetadataExt;
432433
let scene = TestScenario::new(util_name!());
433434
let at = &scene.fixtures;
434-
let groups = nix::unistd::getgroups().unwrap();
435+
let groups = getgroups().unwrap();
435436
// Skip test if we don't have at least two different groups to work with
436437
if groups.len() < 2 {
437438
return;
@@ -495,7 +496,7 @@ fn test_from_with_invalid_group() {
495496
fn test_verbosity_messages() {
496497
let scene = TestScenario::new(util_name!());
497498
let at = &scene.fixtures;
498-
let groups = nix::unistd::getgroups().unwrap();
499+
let groups = getgroups().unwrap();
499500
// Skip test if we don't have at least one group to work with
500501
if groups.is_empty() {
501502
return;
@@ -519,7 +520,7 @@ fn test_from_with_reference() {
519520
use std::os::unix::fs::MetadataExt;
520521
let scene = TestScenario::new(util_name!());
521522
let at = &scene.fixtures;
522-
let groups = nix::unistd::getgroups().unwrap();
523+
let groups = getgroups().unwrap();
523524
if groups.len() < 2 {
524525
return;
525526
}
@@ -562,7 +563,7 @@ fn test_numeric_group_formats() {
562563
let scene = TestScenario::new(util_name!());
563564
let at = &scene.fixtures;
564565

565-
let groups = nix::unistd::getgroups().unwrap();
566+
let groups = getgroups().unwrap();
566567
if groups.len() < 2 {
567568
return;
568569
}

tests/by-util/test_cp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3336,7 +3336,7 @@ fn test_cp_socket() {
33363336
#[cfg(all(unix, not(target_vendor = "apple")))]
33373337
fn find_other_group(current: u32) -> Option<u32> {
33383338
// Get the first group that doesn't match current
3339-
nix::unistd::getgroups().ok()?.iter().find_map(|group| {
3339+
rustix::process::getgroups().ok()?.iter().find_map(|group| {
33403340
let gid = group.as_raw();
33413341
(gid != current).then_some(gid)
33423342
})

tests/by-util/test_mv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2988,7 +2988,7 @@ fn test_mv_cross_device_file_symlink_preserved() {
29882988
/// Non-root users can chgrp to any group they belong to.
29892989
#[cfg(target_os = "linux")]
29902990
fn find_other_group(current: u32) -> Option<u32> {
2991-
nix::unistd::getgroups().ok()?.iter().find_map(|group| {
2991+
rustix::process::getgroups().ok()?.iter().find_map(|group| {
29922992
let gid = group.as_raw();
29932993
(gid != current).then_some(gid)
29942994
})

0 commit comments

Comments
 (0)