Skip to content

Commit 5aade31

Browse files
oech3cakebaker
authored andcommitted
test_test.rs: remove unsafe
1 parent 34e1d93 commit 5aade31

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

tests/by-util/test_test.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -731,22 +731,18 @@ fn test_file_owned_by_egid() {
731731
// /tmp directory will have a different gid than the current egid (due to
732732
// the sticky bit set on the /tmp directory). Fix this before running the
733733
// test command.
734-
use std::ffi::CString;
735-
use std::os::unix::ffi::OsStrExt;
736734
use std::os::unix::fs::MetadataExt;
737-
use uucore::process::getegid;
738735
let scene = TestScenario::new(util_name!());
739736
let at = &scene.fixtures;
740737

741738
let metadata = at.metadata("regular_file");
742-
let file_gid = metadata.gid();
743-
let user_gid = getegid();
739+
let file_gid = rustix::fs::Gid::from_raw(metadata.gid());
740+
let user_gid = rustix::process::getegid();
744741

745742
if user_gid != file_gid {
746-
let file_metadata_uid = metadata.uid();
747-
let path = CString::new(at.plus("regular_file").as_os_str().as_bytes()).expect("bad path");
748-
let r = unsafe { libc::chown(path.as_ptr(), file_metadata_uid, user_gid) };
749-
assert_ne!(r, -1);
743+
let file_uid = rustix::fs::Uid::from_raw(metadata.uid());
744+
let path = at.plus("regular_file");
745+
rustix::fs::chown(&path, Some(file_uid), Some(user_gid)).expect("chown failed");
750746
}
751747

752748
scene.ucmd().args(&["-G", "regular_file"]).succeeds();

0 commit comments

Comments
 (0)