replace nix getgroups by rustix (#12269)

This commit is contained in:
oech3
2026-05-13 14:41:32 +09:00
committed by GitHub
parent b1c267fd73
commit eca185b22b
3 changed files with 12 additions and 11 deletions
+10 -9
View File
@@ -4,6 +4,8 @@
// file that was distributed with this source code.
// spell-checker:ignore (words) nosuchgroup groupname
#[cfg(not(target_vendor = "apple"))]
use rustix::process::getgroups;
#[cfg(target_os = "linux")]
use std::os::unix::ffi::OsStringExt;
use uucore::process::getegid;
@@ -299,9 +301,8 @@ fn test_big_h() {
#[cfg(not(target_vendor = "apple"))]
fn basic_succeeds() {
let (at, mut ucmd) = at_and_ucmd!();
let one_group = nix::unistd::getgroups().unwrap();
// if there are no groups we can't run this test.
if let Some(group) = one_group.first() {
if let Some(group) = getgroups().unwrap().first() {
at.touch("f1");
ucmd.arg(group.as_raw().to_string())
.arg("f1")
@@ -322,7 +323,7 @@ fn test_no_change() {
fn test_permission_denied() {
use std::os::unix::prelude::PermissionsExt;
if let Some(group) = nix::unistd::getgroups().unwrap().first() {
if let Some(group) = getgroups().unwrap().first() {
let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("dir");
at.touch("dir/file");
@@ -340,7 +341,7 @@ fn test_permission_denied() {
fn test_subdir_permission_denied() {
use std::os::unix::prelude::PermissionsExt;
if let Some(group) = nix::unistd::getgroups().unwrap().first() {
if let Some(group) = getgroups().unwrap().first() {
let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("dir");
at.mkdir("dir/subdir");
@@ -358,7 +359,7 @@ fn test_subdir_permission_denied() {
#[cfg(not(target_vendor = "apple"))]
fn test_traverse_symlinks() {
use std::os::unix::prelude::MetadataExt;
let groups = nix::unistd::getgroups().unwrap();
let groups = getgroups().unwrap();
if groups.len() < 2 {
return;
}
@@ -431,7 +432,7 @@ fn test_from_option() {
use std::os::unix::fs::MetadataExt;
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let groups = nix::unistd::getgroups().unwrap();
let groups = getgroups().unwrap();
// Skip test if we don't have at least two different groups to work with
if groups.len() < 2 {
return;
@@ -495,7 +496,7 @@ fn test_from_with_invalid_group() {
fn test_verbosity_messages() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let groups = nix::unistd::getgroups().unwrap();
let groups = getgroups().unwrap();
// Skip test if we don't have at least one group to work with
if groups.is_empty() {
return;
@@ -519,7 +520,7 @@ fn test_from_with_reference() {
use std::os::unix::fs::MetadataExt;
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let groups = nix::unistd::getgroups().unwrap();
let groups = getgroups().unwrap();
if groups.len() < 2 {
return;
}
@@ -562,7 +563,7 @@ fn test_numeric_group_formats() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let groups = nix::unistd::getgroups().unwrap();
let groups = getgroups().unwrap();
if groups.len() < 2 {
return;
}
+1 -1
View File
@@ -3336,7 +3336,7 @@ fn test_cp_socket() {
#[cfg(all(unix, not(target_vendor = "apple")))]
fn find_other_group(current: u32) -> Option<u32> {
// Get the first group that doesn't match current
nix::unistd::getgroups().ok()?.iter().find_map(|group| {
rustix::process::getgroups().ok()?.iter().find_map(|group| {
let gid = group.as_raw();
(gid != current).then_some(gid)
})
+1 -1
View File
@@ -2988,7 +2988,7 @@ fn test_mv_cross_device_file_symlink_preserved() {
/// Non-root users can chgrp to any group they belong to.
#[cfg(target_os = "linux")]
fn find_other_group(current: u32) -> Option<u32> {
nix::unistd::getgroups().ok()?.iter().find_map(|group| {
rustix::process::getgroups().ok()?.iter().find_map(|group| {
let gid = group.as_raw();
(gid != current).then_some(gid)
})